EnableFieldsTest.php 4.75 KB
Newer Older
1
<?php
2

3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

16
17
namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;

18
use TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase;
19
20
21
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
22
23
24
25

/**
 * Enable fields test
 */
26
27
28
class EnableFieldsTest extends AbstractDataHandlerActionTestCase
{
    const TABLE_Blog = 'tx_blogexample_domain_model_blog';
29

30
31
32
    /**
     * @var array
     */
33
    protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
34

35
36
37
    /**
     * @var array
     */
38
    protected $coreExtensionsToLoad = ['core', 'extbase', 'fluid'];
39

40
41
42
43
44
    /**
     * @var bool Reference index testing not relevant here.
     */
    protected $assertCleanReferenceIndex = false;

45
46
47
    /**
     * Sets up this test suite.
     */
48
    protected function setUp(): void
49
50
    {
        parent::setUp();
51

52
        $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
53
54
55
        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/fe_groups.xml');
        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/fe_users.xml');
        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs-with-fe_groups.xml');
56

57
        $this->setUpFrontendSite(1);
58
        $this->setUpFrontendRootPage(1, ['typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/Frontend/JsonRenderer.typoscript']);
59
    }
60

61
62
63
64
65
    /**
     * @test
     */
    public function protectedRecordsNotFoundIfNoUserLoggedIn()
    {
66
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
67
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
68
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
69
70
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1'));
    }
71

72
73
74
75
76
    /**
     * @test
     */
    public function onlyReturnProtectedRecordsForTheFirstUserGroup()
    {
77
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(1));
78
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
79
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
80
81
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
    }
82

83
84
85
86
87
    /**
     * @test
     */
    public function onlyReturnProtectedRecordsForTheSecondUserGroup()
    {
88
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(2));
89
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
90
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
91
92
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
    }
93

94
95
96
97
98
99
    /**
     * @test
     */
    public function onlyOwnProtectedRecordsWithQueryCacheInvolvedAreReturned()
    {
        // first request to fill the query cache
100
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(1));
101
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
102
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
103
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
104

105
        // second request with other frontenduser
106
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(2));
107
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
108
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
109
110
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
    }
111
}