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

3
4
declare(strict_types=1);

5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * 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!
 */

18
19
namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;

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

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

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

37
38
39
    /**
     * Sets up this test suite.
     */
40
    protected function setUp(): void
41
42
    {
        parent::setUp();
43

44
        $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
45
46
47
        $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');
48

49
        $this->setUpFrontendSite(1);
50
        $this->setUpFrontendRootPage(1, ['typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/Frontend/JsonRenderer.typoscript']);
51
    }
52

53
54
55
    /**
     * @test
     */
56
    public function protectedRecordsNotFoundIfNoUserLoggedIn(): void
57
    {
58
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
59
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
60
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
61
62
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1'));
    }
63

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

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

86
87
88
    /**
     * @test
     */
89
    public function onlyOwnProtectedRecordsWithQueryCacheInvolvedAreReturned(): void
90
91
    {
        // first request to fill the query cache
92
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(1));
93
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
94
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
95
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog2'));
96

97
        // second request with other frontenduser
98
        $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1), (new InternalRequestContext())->withFrontendUserId(2));
99
        $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections('Extbase:list()');
100
        self::assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
101
102
            ->setTable(self::TABLE_Blog)->setField('title')->setValues('Blog1', 'Blog3'));
    }
103
}