‪TYPO3CMS  ‪main
EnableFieldsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\HasRecordConstraint;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪EnableFieldsTest extends FunctionalTestCase
29 {
31 
32  protected array ‪$testExtensionsToLoad = [
33  'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example',
34  ];
35 
36  private const ‪TABLE_Blog = 'tx_blogexample_domain_model_blog';
37  private const ‪LANGUAGE_PRESETS = [
38  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
39  ];
40 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->importCSVDataSet(__DIR__ . '/Fixtures/EnableFieldsTestImport.csv');
46  'test',
47  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
48  [
49  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
50  ],
51  $this->‪buildErrorHandlingConfiguration('Fluid', [404]),
52  );
53  $this->setUpFrontendRootPage(1, ['EXT:extbase/Tests/Functional/Persistence/Fixtures/Frontend/JsonRenderer.typoscript']);
54  }
55 
56  #[Test]
57  public function ‪protectedRecordsNotFoundIfNoUserLoggedIn(): void
58  {
59  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
60  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
61  self::assertThat($responseSections, (new HasRecordConstraint())
62  ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1'));
63  }
64 
65  #[Test]
67  {
68  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(1));
69  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
70  self::assertThat($responseSections, (new HasRecordConstraint())
71  ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
72  }
73 
74  #[Test]
76  {
77  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(2));
78  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
79  self::assertThat($responseSections, (new HasRecordConstraint())
80  ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
81  }
82 
83  #[Test]
85  {
86  // first request to fill the query cache
87  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(1));
88  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
89  self::assertThat($responseSections, (new HasRecordConstraint())
90  ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
91 
92  // second request with other frontenduser
93  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(2));
94  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
95  self::assertThat($responseSections, (new HasRecordConstraint())
96  ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
97  }
98 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\TABLE_Blog
‪const TABLE_Blog
Definition: EnableFieldsTest.php:35
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\onlyReturnProtectedRecordsForTheSecondUserGroup
‪onlyReturnProtectedRecordsForTheSecondUserGroup()
Definition: EnableFieldsTest.php:74
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: EnableFieldsTest.php:36
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\onlyReturnProtectedRecordsForTheFirstUserGroup
‪onlyReturnProtectedRecordsForTheFirstUserGroup()
Definition: EnableFieldsTest.php:65
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\setUp
‪setUp()
Definition: EnableFieldsTest.php:40
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildErrorHandlingConfiguration
‪buildErrorHandlingConfiguration(string $handler, array $codes)
Definition: SiteBasedTestTrait.php:142
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\protectedRecordsNotFoundIfNoUserLoggedIn
‪protectedRecordsNotFoundIfNoUserLoggedIn()
Definition: EnableFieldsTest.php:56
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest
Definition: EnableFieldsTest.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: EnableFieldsTest.php:31
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\EnableFieldsTest\onlyOwnProtectedRecordsWithQueryCacheInvolvedAreReturned
‪onlyOwnProtectedRecordsWithQueryCacheInvolvedAreReturned()
Definition: EnableFieldsTest.php:83