[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / EnableFieldsTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase;
18
19 /**
20 * Enable fields test
21 */
22 class EnableFieldsTest extends AbstractDataHandlerActionTestCase
23 {
24 const TABLE_Blog = 'tx_blogexample_domain_model_blog';
25
26 /**
27 * @var array
28 */
29 protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
30
31 /**
32 * @var array
33 */
34 protected $coreExtensionsToLoad = ['sv', 'extbase', 'fluid'];
35
36 /**
37 * Sets up this test suite.
38 */
39 protected function setUp()
40 {
41 parent::setUp();
42
43 $this->importDataSet(ORIGINAL_ROOT . 'components/testing_framework/core/Functional/Fixtures/pages.xml');
44 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/fe_groups.xml');
45 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/fe_users.xml');
46 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs-with-fe_groups.xml');
47
48 $this->setUpFrontendRootPage(1, ['typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/Frontend/JsonRenderer.ts']);
49 }
50
51 /**
52 * @test
53 */
54 public function protectedRecordsNotFoundIfNoUserLoggedIn()
55 {
56 $responseSections = $this->getFrontendResponse(1)->getResponseSections('Extbase:list()');
57 $this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
58 ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1'));
59 }
60
61 /**
62 * @test
63 */
64 public function onlyReturnProtectedRecordsForTheFirstUserGroup()
65 {
66 $responseSections = $this->getFrontendResponse(1, 0, 0, 0, true, 1)->getResponseSections('Extbase:list()');
67 $this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
68 ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
69 }
70
71 /**
72 * @test
73 */
74 public function onlyReturnProtectedRecordsForTheSecondUserGroup()
75 {
76 $responseSections = $this->getFrontendResponse(1, 0, 0, 0, true, 2)->getResponseSections('Extbase:list()');
77 $this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
78 ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
79 }
80
81 /**
82 * @test
83 */
84 public function onlyOwnProtectedRecordsWithQueryCacheInvolvedAreReturned()
85 {
86 // first request to fill the query cache
87 $responseSections = $this->getFrontendResponse(1, 0, 0, 0, true, 1)->getResponseSections('Extbase:list()');
88 $this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
89 ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
90
91 // second request with other frontenduser
92 $responseSections = $this->getFrontendResponse(1, 0, 0, 0, true, 2)->getResponseSections('Extbase:list()');
93 $this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
94 ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
95 }
96 }