[TASK] Make FrontendWorkspaceRestrictionTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Query / Restriction / FrontendWorkspaceRestrictionTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction;
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
18 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction;
19 use TYPO3\CMS\Frontend\Page\PageRepository;
20
21 class FrontendWorkspaceRestrictionTest extends AbstractRestrictionTestCase
22 {
23 /**
24 * @test
25 */
26 public function buildExpressionAddsLiveWorkspaceWhereClause()
27 {
28 $GLOBALS['TCA'] = [
29 'aTable' => [
30 'ctrl' => [
31 'versioningWS' => 2,
32 ],
33 ]
34 ];
35
36 $pageRepository = $this->createMock(PageRepository::class);
37 $pageRepository->versioningPreview = false;
38
39 $GLOBALS['TSFE'] = new \stdClass();
40 $GLOBALS['TSFE']->sys_page = $pageRepository;
41
42 $subject = new FrontendWorkspaceRestriction(0);
43 $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
44 $this->assertSame('("aTable"."t3ver_state" <= 0) AND ("aTable"."pid" <> -1)', (string)$expression);
45 }
46
47 /**
48 * @test
49 */
50 public function buildExpressionAddsNonLiveWorkspaceWhereClause()
51 {
52 $GLOBALS['TCA'] = [
53 'aTable' => [
54 'ctrl' => [
55 'versioningWS' => 2,
56 ],
57 ]
58 ];
59
60 $pageRepository = $this->createMock(PageRepository::class);
61 $pageRepository->versioningPreview = true;
62 $pageRepository->versioningWorkspaceId = 42;
63
64 $subject = new FrontendWorkspaceRestriction(42, true);
65 $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
66 $this->assertSame('(("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 42)) AND ("aTable"."pid" <> -1)', (string)$expression);
67 }
68
69 /**
70 * @test
71 */
72 public function buildExpressionAddsNonLiveWorkspaceExclusiveWhereClause()
73 {
74 $GLOBALS['TCA'] = [
75 'aTable' => [
76 'ctrl' => [
77 'versioningWS' => 2,
78 ],
79 ]
80 ];
81
82 $pageRepository = $this->createMock(PageRepository::class);
83 $pageRepository->versioningPreview = true;
84 $pageRepository->versioningWorkspaceId = 42;
85
86 $subject = new FrontendWorkspaceRestriction(42, true, false);
87 $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
88 $this->assertSame('("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 42)', (string)$expression);
89 }
90 }