[BUGFIX] Make LocalizationRepository handle copied records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Functional / Domain / Repository / Localization / LocalizationRepositoryTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Functional\Domain\Repository\Localization;
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 TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository;
18 use TYPO3\CMS\Core\Core\Bootstrap;
19
20 /**
21 * Test case for TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository
22 */
23 class LocalizationRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
24 {
25 /**
26 * @var LocalizationRepository
27 */
28 protected $subject;
29
30 /**
31 * Sets up this test case.
32 *
33 * @return void
34 */
35 protected function setUp()
36 {
37 parent::setUp();
38
39 $this->setUpBackendUserFromFixture(1);
40 Bootstrap::getInstance()->initializeLanguageObject();
41
42 $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/Fixtures/DefaultPagesAndContent.csv');
43
44 $this->subject = new LocalizationRepository();
45 }
46
47 public function fetchOriginLanguageDataProvider()
48 {
49 return [
50 'default language returns false' => [
51 1,
52 0,
53 0,
54 false
55 ],
56 'connected mode translated from default language' => [
57 1,
58 0,
59 1,
60 false
61 ],
62 'connected mode translated from non default language' => [
63 1,
64 0,
65 2,
66 [
67 'sys_language_uid' => 1
68 ]
69 ],
70 'free mode translated from default language' => [
71 2,
72 0,
73 1,
74 false
75 ],
76 'free mode translated from non default language' => [
77 2,
78 0,
79 2,
80 [
81 'sys_language_uid' => 1
82 ]
83 ],
84 'free mode copied from another page translated from default language' => [
85 3,
86 0,
87 1,
88 false
89 ],
90 'free mode copied from another page translated from non default language' => [
91 3,
92 0,
93 2,
94 [
95 'sys_language_uid' => 1
96 ]
97 ]
98 ];
99 }
100
101 /**
102 * @dataProvider fetchOriginLanguageDataProvider
103 * @test
104 *
105 * @param $pageId
106 * @param $colPos
107 * @param $localizedLanguage
108 * @param $expectedResult
109 */
110 public function fetchOriginLanguage($pageId, $colPos, $localizedLanguage, $expectedResult)
111 {
112 $result = $this->subject->fetchOriginLanguage($pageId, $colPos, $localizedLanguage);
113 $this->assertEquals($expectedResult, $result);
114 }
115
116 public function getLocalizedRecordCountDataProvider()
117 {
118 return [
119 'default language returns 0 always' => [
120 1,
121 0,
122 0,
123 0
124 ],
125 'connected mode translated from default language' => [
126 1,
127 0,
128 1,
129 2
130 ],
131 'connected mode translated from non default language' => [
132 1,
133 0,
134 2,
135 1
136 ],
137 'free mode translated from default language' => [
138 2,
139 0,
140 1,
141 1
142 ],
143 'free mode translated from non default language' => [
144 2,
145 0,
146 2,
147 1
148 ],
149 'free mode copied from another page translated from default language' => [
150 3,
151 0,
152 1,
153 1
154 ],
155 'free mode copied from another page translated from non default language' => [
156 3,
157 0,
158 2,
159 1
160 ]
161 ];
162 }
163
164 /**
165 * @dataProvider getLocalizedRecordCountDataProvider
166 * @test
167 */
168 public function getLocalizedRecordCount($pageId, $colPos, $localizedLanguage, $expectedResult)
169 {
170 $result = $this->subject->getLocalizedRecordCount($pageId, $colPos, $localizedLanguage);
171 $this->assertEquals($expectedResult, $result);
172 }
173
174 public function getRecordsToCopyDatabaseResultDataProvider()
175 {
176 return [
177 'from language 0 to 1 connected mode' => [
178 1,
179 0,
180 1,
181 0,
182 [
183 ['uid' => 298]
184 ]
185 ],
186 'from language 1 to 2 connected mode' => [
187 1,
188 0,
189 2,
190 1,
191 [
192 ['uid' => 300]
193 ]
194 ],
195 'from language 0 to 1 free mode' => [
196 2,
197 0,
198 1,
199 0,
200 []
201 ],
202 'from language 1 to 2 free mode' => [
203 2,
204 0,
205 2,
206 1,
207 []
208 ],
209 'from language 0 to 1 free mode copied' => [
210 3,
211 0,
212 1,
213 0,
214 []
215 ],
216 'from language 1 to 2 free mode mode copied' => [
217 3,
218 0,
219 2,
220 1,
221 []
222 ],
223 ];
224 }
225
226 /**
227 * @dataProvider getRecordsToCopyDatabaseResultDataProvider
228 * @test
229 */
230 public function getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $expectedResult)
231 {
232 $result = $this->subject->getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, 'uid');
233 $result = $result->fetchAll();
234 $this->assertEquals($expectedResult, $result);
235 }
236 }