[TASK] Make L10nModeUpdaterTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Updates / RowUpdater / L10nModeUpdaterTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Install\Tests\Unit\Updates\RowUpdater;
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 Prophecy\Argument;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
21 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
22 use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
23 use TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Install\Updates\RowUpdater\L10nModeUpdater;
26
27 /**
28 * Test Class for ContentTypesToTextMediaUpdate
29 */
30 class L10nModeUpdaterTest extends BaseTestCase
31 {
32 /**
33 * @test
34 */
35 public function hasPotentialUpdateForTableThrowsExceptionIfGlobalsTcaTableArrayIsNotSet()
36 {
37 $this->expectException(\RuntimeException::class);
38 $this->expectExceptionCode(1484176136);
39 $GLOBALS['TCA'] = [];
40 (new L10nModeUpdater())->hasPotentialUpdateForTable('someTable');
41 }
42
43 /**
44 * @test
45 */
46 public function hasPotentialUpdateForTableThrowsExceptionIfGlobalsTcaTableArrayIsNotAnArray()
47 {
48 $this->expectException(\RuntimeException::class);
49 $this->expectExceptionCode(1484176136);
50 $GLOBALS['TCA'] = ['someTable' => ''];
51 (new L10nModeUpdater())->hasPotentialUpdateForTable('someTable');
52 }
53
54 /**
55 * @test
56 */
57 public function hasPotentialUpdateForTableReturnFalseForTableWithoutL10nMode()
58 {
59 $GLOBALS['TCA'] = [
60 'testTable' => [
61 'ctrl' => [
62 'languageField' => 'sys_language_uid',
63 'transOrigPointerField' => 'l10n_parent',
64 ],
65 'columns' => [
66 'testField' => [
67 'label' => 'someLabel',
68 'config' => [
69 'type' => 'input',
70 ],
71 ],
72 ],
73 ],
74 ];
75 $subject = new L10nModeUpdater();
76 $this->assertFalse($subject->hasPotentialUpdateForTable('testTable'));
77 }
78
79 /**
80 * @test
81 */
82 public function hasPotentialUpdateForTableReturnTrueForTableWithL10nModeExclude()
83 {
84 $GLOBALS['TCA'] = [
85 'testTable' => [
86 'ctrl' => [
87 'languageField' => 'sys_language_uid',
88 'transOrigPointerField' => 'l10n_parent',
89 ],
90 'columns' => [
91 'testField' => [
92 'label' => 'someLabel',
93 'l10n_mode' => 'exclude',
94 'config' => [
95 'type' => 'input',
96 ],
97 ],
98 ],
99 ],
100 ];
101
102 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
103 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
104 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
105 $connectionPoolProphecy->getQueryBuilderForTable('testTable')->willReturn($queryBuilderProphecy->reveal());
106 $restrictionBuilderProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
107 $queryBuilderProphecy->getRestrictions()->willReturn($restrictionBuilderProphecy->reveal());
108 $queryBuilderProphecy->from('testTable');
109 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
110 $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
111 $queryBuilderProphecy->createNamedParameter(Argument::cetera())->willReturnArgument(0);
112 $expressionBuilderProphecy->gt('sys_language_uid', 0);
113 $expressionBuilderProphecy->gt('l10n_parent', 0);
114 $queryBuilderProphecy->select('uid', 'l10n_parent')->willReturn($queryBuilderProphecy->reveal());
115 $queryBuilderProphecy->andWhere(Argument::cetera())->willReturn($queryBuilderProphecy->reveal());
116 $queryBuilderProphecy->execute()->willReturn([
117 [
118 'uid' => 23,
119 'l10n_parent' => 42,
120 ]
121 ]);
122
123 $subject = new L10nModeUpdater();
124 $this->assertTrue($subject->hasPotentialUpdateForTable('testTable'));
125 }
126
127 /**
128 * @test
129 */
130 public function hasPotentialUpdateForTableReturnTrueForTableWithBehaviourAllowLanguageSynchronization()
131 {
132 $GLOBALS['TCA'] = [
133 'testTable' => [
134 'ctrl' => [
135 'languageField' => 'sys_language_uid',
136 'transOrigPointerField' => 'l10n_parent',
137 ],
138 'columns' => [
139 'testField' => [
140 'label' => 'someLabel',
141 'config' => [
142 'type' => 'input',
143 'behaviour' => [
144 'allowLanguageSynchronization' => true,
145 ]
146 ],
147 ],
148 ],
149 ],
150 ];
151
152 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
153 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
154 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
155 $connectionPoolProphecy->getQueryBuilderForTable('testTable')->willReturn($queryBuilderProphecy->reveal());
156 $restrictionBuilderProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
157 $queryBuilderProphecy->getRestrictions()->willReturn($restrictionBuilderProphecy->reveal());
158 $queryBuilderProphecy->from('testTable');
159 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
160 $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
161 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
162 $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
163 $queryBuilderProphecy->createNamedParameter(Argument::cetera())->willReturnArgument(0);
164 $expressionBuilderProphecy->gt('sys_language_uid', 0);
165 $expressionBuilderProphecy->gt('l10n_parent', 0);
166 $queryBuilderProphecy->select('uid', 'l10n_parent')->willReturn($queryBuilderProphecy->reveal());
167 $queryBuilderProphecy->andWhere(Argument::cetera())->willReturn($queryBuilderProphecy->reveal());
168 $queryBuilderProphecy->execute()->willReturn([
169 [
170 'uid' => 23,
171 'l10n_parent' => 42,
172 ]
173 ]);
174
175 $subject = new L10nModeUpdater();
176 $this->assertTrue($subject->hasPotentialUpdateForTable('testTable'));
177 }
178 }