d72ee363f4ccdc962708f1e48d2a728ee44ac408
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Updates / RowUpdater / L10nModeUpdaterTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\Updates\RowUpdater;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Prophecy\Argument;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
20 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
21 use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
22 use TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Install\Updates\RowUpdater\L10nModeUpdater;
25
26 /**
27 * Test Class for ContentTypesToTextMediaUpdate
28 */
29 class L10nModeUpdaterTest extends BaseTestCase
30 {
31 /**
32 * Subject is not notice free, disable E_NOTICES
33 */
34 protected static $suppressNotices = true;
35
36 /**
37 * @test
38 */
39 public function hasPotentialUpdateForTableThrowsExceptionIfGlobalsTcaIsNoArray()
40 {
41 $this->expectException(\RuntimeException::class);
42 $this->expectExceptionCode(1484176136);
43 (new L10nModeUpdater())->hasPotentialUpdateForTable('someTable');
44 }
45
46 /**
47 * @test
48 */
49 public function hasPotentialUpdateForTableReturnFalseForTableWithoutL10nMode()
50 {
51 $GLOBALS['TCA'] = [
52 'testTable' => [
53 'ctrl' => [
54 'languageField' => 'sys_language_uid',
55 'transOrigPointerField' => 'l10n_parent',
56 ],
57 'columns' => [
58 'testField' => [
59 'label' => 'someLabel',
60 'config' => [
61 'type' => 'input',
62 ],
63 ],
64 ],
65 ],
66 ];
67 $subject = new L10nModeUpdater();
68 $this->assertFalse($subject->hasPotentialUpdateForTable('testTable'));
69 }
70
71 /**
72 * @test
73 */
74 public function hasPotentialUpdateForTableReturnTrueForTableWithL10nModeExclude()
75 {
76 $GLOBALS['TCA'] = [
77 'testTable' => [
78 'ctrl' => [
79 'languageField' => 'sys_language_uid',
80 'transOrigPointerField' => 'l10n_parent',
81 ],
82 'columns' => [
83 'testField' => [
84 'label' => 'someLabel',
85 'l10n_mode' => 'exclude',
86 'config' => [
87 'type' => 'input',
88 ],
89 ],
90 ],
91 ],
92 ];
93
94 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
95 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
96 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
97 $connectionPoolProphecy->getQueryBuilderForTable('testTable')->willReturn($queryBuilderProphecy->reveal());
98 $restrictionBuilderProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
99 $queryBuilderProphecy->getRestrictions()->willReturn($restrictionBuilderProphecy->reveal());
100 $queryBuilderProphecy->from('testTable');
101 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
102 $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
103 $queryBuilderProphecy->createNamedParameter(Argument::cetera())->willReturnArgument(0);
104 $expressionBuilderProphecy->gt('sys_language_uid', 0);
105 $expressionBuilderProphecy->gt('l10n_parent', 0);
106 $queryBuilderProphecy->select('uid', 'l10n_parent')->willReturn($queryBuilderProphecy->reveal());
107 $queryBuilderProphecy->andWhere(Argument::cetera())->willReturn($queryBuilderProphecy->reveal());
108 $queryBuilderProphecy->execute()->willReturn([
109 [
110 'uid' => 23,
111 'l10n_parent' => 42,
112 ]
113 ]);
114
115 $subject = new L10nModeUpdater();
116 $this->assertTrue($subject->hasPotentialUpdateForTable('testTable'));
117 }
118
119 /**
120 * @test
121 */
122 public function hasPotentialUpdateForTableReturnTrueForTableWithBehaviourAllowLanguageSynchronization()
123 {
124 $GLOBALS['TCA'] = [
125 'testTable' => [
126 'ctrl' => [
127 'languageField' => 'sys_language_uid',
128 'transOrigPointerField' => 'l10n_parent',
129 ],
130 'columns' => [
131 'testField' => [
132 'label' => 'someLabel',
133 'config' => [
134 'type' => 'input',
135 'behaviour' => [
136 'allowLanguageSynchronization' => true,
137 ]
138 ],
139 ],
140 ],
141 ],
142 ];
143
144 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
145 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
146 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
147 $connectionPoolProphecy->getQueryBuilderForTable('testTable')->willReturn($queryBuilderProphecy->reveal());
148 $restrictionBuilderProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
149 $queryBuilderProphecy->getRestrictions()->willReturn($restrictionBuilderProphecy->reveal());
150 $queryBuilderProphecy->from('testTable');
151 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
152 $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
153 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
154 $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
155 $queryBuilderProphecy->createNamedParameter(Argument::cetera())->willReturnArgument(0);
156 $expressionBuilderProphecy->gt('sys_language_uid', 0);
157 $expressionBuilderProphecy->gt('l10n_parent', 0);
158 $queryBuilderProphecy->select('uid', 'l10n_parent')->willReturn($queryBuilderProphecy->reveal());
159 $queryBuilderProphecy->andWhere(Argument::cetera())->willReturn($queryBuilderProphecy->reveal());
160 $queryBuilderProphecy->execute()->willReturn([
161 [
162 'uid' => 23,
163 'l10n_parent' => 42,
164 ]
165 ]);
166
167 $subject = new L10nModeUpdater();
168 $this->assertTrue($subject->hasPotentialUpdateForTable('testTable'));
169 }
170 }