2844e79ce9d5971078bec9547fa93b4bbbf9b200
[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 * @return void
25 */
26 protected function setUp()
27 {
28 parent::setUp();
29 }
30
31 /**
32 * @test
33 */
34 public function buildExpressionAddsLiveWorkspaceWhereClause()
35 {
36 $GLOBALS['TCA'] = [
37 'aTable' => [
38 'ctrl' => [
39 'versioningWS' => 2,
40 ],
41 ]
42 ];
43
44 $pageRepository = $this->createMock(PageRepository::class);
45 $pageRepository->versioningPreview = false;
46
47 $subject = new FrontendWorkspaceRestriction(0);
48 $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
49 $this->assertSame('("aTable"."t3ver_state" <= 0) AND ("aTable"."pid" <> -1)', (string)$expression);
50 }
51
52 /**
53 * @test
54 */
55 public function buildExpressionAddsNonLiveWorkspaceWhereClause()
56 {
57 $GLOBALS['TCA'] = [
58 'aTable' => [
59 'ctrl' => [
60 'versioningWS' => 2,
61 ],
62 ]
63 ];
64
65 $pageRepository = $this->createMock(PageRepository::class);
66 $pageRepository->versioningPreview = true;
67 $pageRepository->versioningWorkspaceId = 42;
68
69 $subject = new FrontendWorkspaceRestriction(42, true);
70 $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
71 $this->assertSame('(("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 42)) AND ("aTable"."pid" <> -1)', (string)$expression);
72 }
73
74 /**
75 * @test
76 */
77 public function buildExpressionAddsNonLiveWorkspaceExclusiveWhereClause()
78 {
79 $GLOBALS['TCA'] = [
80 'aTable' => [
81 'ctrl' => [
82 'versioningWS' => 2,
83 ],
84 ]
85 ];
86
87 $pageRepository = $this->createMock(PageRepository::class);
88 $pageRepository->versioningPreview = true;
89 $pageRepository->versioningWorkspaceId = 42;
90
91 $subject = new FrontendWorkspaceRestriction(42, true, false);
92 $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
93 $this->assertSame('("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 42)', (string)$expression);
94 }
95 }