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