‪TYPO3CMS  9.5
TranslationLegacyTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 
19 use PHPUnit\Framework\MockObject\MockObject;
26 
27 class ‪TranslationLegacyTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
28 {
32  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
33 
37  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
38 
42  protected ‪$objectManager;
43 
47  protected ‪$postRepository;
48 
52  protected function ‪setUp()
53  {
54  parent::setUp();
55  /*
56  * Posts Dataset for the tests:
57  *
58  * Post1
59  * -> EN: Post1
60  * -> GR: Post1
61  * Post2
62  * -> EN: Post2
63  * Post3
64  * Post10 [hidden]
65  * -> GR: Post10 [hidden]
66  */
67  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
68  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
69  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translated-posts.xml');
70  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
71  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
72 
74 
75  $this->objectManager = GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
76  $configuration = [
77  'features' => ['consistentTranslationOverlayHandling' => 0]
78  ];
79  $configurationManager = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Configuration\ConfigurationManagerInterface::class);
80  $configurationManager->setConfiguration($configuration);
81 
82  $this->postRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
83  }
84 
88  protected function ‪setUpBasicFrontendEnvironment()
89  {
90  // in v9 overlay and language mode has different default values, so we need to set them here explicitely
91  // to match v8 behaviour
92  $context = GeneralUtility::makeInstance(Context::class);
93  $context->setAspect('language', new ‪LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_OFF, ['off']));
94 
96  $environmentServiceMock = $this->createMock(EnvironmentService::class);
97  $environmentServiceMock
98  ->expects($this->atLeast(1))
99  ->method('isEnvironmentInFrontendMode')
100  ->willReturn(true);
101  GeneralUtility::setSingletonInstance(EnvironmentService::class, $environmentServiceMock);
102 
103  $pageRepositoryFixture = new ‪PageRepository();
104  $frontendControllerMock = $this->createMock(\‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
105  $frontendControllerMock->sys_page = $pageRepositoryFixture;
106  ‪$GLOBALS['TSFE'] = $frontendControllerMock;
107  }
108 
114  public function ‪countReturnsCorrectNumberOfPosts()
115  {
116  $query = $this->postRepository->createQuery();
117 
118  $querySettings = $query->getQuerySettings();
119  $querySettings->setStoragePageIds([1]);
120  $querySettings->setRespectSysLanguage(true);
121  $querySettings->setLanguageUid(0);
122 
123  $this->assertFalse($querySettings->getLanguageOverlayMode());
124  $this->assertNull($querySettings->getLanguageMode());
125 
126  $postCount = $query->execute()->count();
127  $this->assertSame(3, $postCount);
128  }
129 
138  {
139  $query = $this->postRepository->createQuery();
140 
141  $querySettings = $query->getQuerySettings();
142  $querySettings->setStoragePageIds([1]);
143  $querySettings->setRespectSysLanguage(true);
144  $querySettings->setLanguageUid(1);
145  $querySettings->setLanguageMode('strict');
146  $this->assertFalse($querySettings->getLanguageOverlayMode());
147 
148  $postCount = $query->execute()->count();
149  $this->assertSame(2, $postCount);
150  }
151 
158  {
159  $query = $this->postRepository->createQuery();
160 
161  $querySettings = $query->getQuerySettings();
162  $querySettings->setStoragePageIds([1]);
163  $querySettings->setRespectSysLanguage(true);
164  $querySettings->setLanguageUid(1);
165  $this->assertFalse($querySettings->getLanguageOverlayMode());
166  $this->assertNull($querySettings->getLanguageMode());
167 
168  $postCount = $query->execute()->count();
169  $this->assertSame(3, $postCount);
170  }
171 
176  {
177  $query = $this->postRepository->createQuery();
178 
179  $querySettings = $query->getQuerySettings();
180  $querySettings->setStoragePageIds([1]);
181  $querySettings->setRespectSysLanguage(true);
182  $querySettings->setLanguageUid(2);
183  $this->assertFalse($querySettings->getLanguageOverlayMode());
184  $this->assertNull($querySettings->getLanguageMode());
185 
186  $postCount = $query->execute()->count();
187 
188  $this->assertSame(3, $postCount);
189  }
190 
195  {
196  $query = $this->postRepository->createQuery();
197 
198  $querySettings = $query->getQuerySettings();
199  $querySettings->setStoragePageIds([1]);
200  $querySettings->setRespectSysLanguage(true);
201  $querySettings->setLanguageUid(1);
202  $this->assertFalse($querySettings->getLanguageOverlayMode());
203  $this->assertNull($querySettings->getLanguageMode());
204 
205  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
206 
208  $posts = $query->execute()->toArray();
209 
210  $this->assertCount(3, $posts);
211  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
212  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
213  $this->assertSame('Post3', $posts[2]->getTitle());
214  }
215 
222  {
223  $query = $this->postRepository->createQuery();
224 
225  $querySettings = $query->getQuerySettings();
226  $querySettings->setStoragePageIds([1]);
227  $querySettings->setRespectSysLanguage(true);
228  $querySettings->setLanguageUid(2);
229  $this->assertFalse($querySettings->getLanguageOverlayMode());
230  $this->assertNull($querySettings->getLanguageMode());
231 
232  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
233 
235  $posts = $query->execute()->toArray();
236 
237  $this->assertCount(3, $posts);
238  $this->assertSame('GR:Post1', $posts[0]->getTitle());
239  $this->assertSame('Post2', $posts[1]->getTitle());
240  $this->assertSame('Post3', $posts[2]->getTitle());
241  }
242 
249  {
250  $query = $this->postRepository->createQuery();
251 
252  $querySettings = $query->getQuerySettings();
253  $querySettings->setStoragePageIds([1]);
254  $querySettings->setRespectSysLanguage(true);
255  $querySettings->setLanguageUid(2);
256  $querySettings->setLanguageOverlayMode('hideNonTranslated');
257  $this->assertNull($querySettings->getLanguageMode());
258 
259  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
260 
262  $posts = $query->execute()->toArray();
263 
264  $this->assertCount(3, $posts);
265  $this->assertSame('GR:Post1', $posts[0]->getTitle());
266  $this->assertSame('Post2', $posts[1]->getTitle());
267  $this->assertSame('Post3', $posts[2]->getTitle());
268  }
269 
274  {
275  $query = $this->postRepository->createQuery();
276 
277  $querySettings = $query->getQuerySettings();
278  $querySettings->setStoragePageIds([1]);
279  $querySettings->setRespectSysLanguage(true);
280  $querySettings->setLanguageUid(1);
281  $this->assertFalse($querySettings->getLanguageOverlayMode());
282  $this->assertNull($querySettings->getLanguageMode());
283 
284  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
285 
287  $posts = $query->execute()->toArray();
288 
289  $this->assertCount(3, $posts);
290  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
291  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
292  $this->assertSame('Post3', $posts[2]->getTitle());
293  }
294 
303  {
304  $query = $this->postRepository->createQuery();
305 
306  $querySettings = $query->getQuerySettings();
307  $querySettings->setStoragePageIds([1]);
308  $querySettings->setRespectSysLanguage(true);
309  $querySettings->setIgnoreEnableFields(true);
310  $querySettings->setLanguageUid(0);
311  //we need it to have stable results on pgsql
312  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
313 
315  $posts = $query->execute()->toArray();
316 
317  $this->assertCount(4, $posts);
318  $this->assertSame('Post10', $posts[3]->getTitle());
319  }
320 
331  {
332  $query = $this->postRepository->createQuery();
333 
334  $querySettings = $query->getQuerySettings();
335  $querySettings->setStoragePageIds([1]);
336  $querySettings->setRespectSysLanguage(true);
337  $querySettings->setIgnoreEnableFields(true);
338  $querySettings->setLanguageUid(2);
339  $this->assertFalse($querySettings->getLanguageOverlayMode());
340  //we need it to have stable results on pgsql
341  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
342 
344  $posts = $query->execute()->toArray();
345 
346  $this->assertCount(4, $posts);
347  //This assertion is wrong, once the issue https://forge.typo3.org/issues/68672
348  //is fixed, the following assertion should be used.
349  $this->assertSame('Post10', $posts[3]->getTitle());
350  //$this->assertSame('GR:Post10', $posts[3]->getTitle());
351  }
352 
358  public function ‪fetchingTranslatedPostByTitle()
359  {
360  $query = $this->postRepository->createQuery();
361  $querySettings = $query->getQuerySettings();
362  $querySettings->setStoragePageIds([1]);
363  $querySettings->setRespectSysLanguage(true);
364  $querySettings->setLanguageUid(2);
365  $this->assertFalse($querySettings->getLanguageOverlayMode());
366  $this->assertNull($querySettings->getLanguageMode());
367 
368  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
369  $query->matching($query->equals('title', 'GR:Post1'));
371  $posts = $query->execute()->toArray();
372  $this->assertCount(1, $posts);
373  $this->assertSame('GR:Post1', $posts[0]->getTitle());
374  }
375 
379  public function ‪fetchingPostByTagName()
380  {
381  $query = $this->postRepository->createQuery();
382  $querySettings = $query->getQuerySettings();
383  $querySettings->setRespectStoragePage(false);
384  $querySettings->setRespectSysLanguage(true);
385  $querySettings->setLanguageUid(0);
386  $this->assertFalse($querySettings->getLanguageOverlayMode());
387  $this->assertNull($querySettings->getLanguageMode());
388 
389  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
390  $query->matching($query->equals('tags.name', 'Tag1'));
392  $posts = $query->execute()->toArray();
393  $this->assertCount(3, $posts);
394  $this->assertSame('Post1', $posts[0]->getTitle());
395  }
396 
400  public function ‪fetchingTranslatedPostByTagName()
401  {
402  $query = $this->postRepository->createQuery();
403  $querySettings = $query->getQuerySettings();
404  $querySettings->setRespectStoragePage(false);
405  $querySettings->setRespectSysLanguage(true);
406  $querySettings->setLanguageUid(1);
407  $this->assertFalse($querySettings->getLanguageOverlayMode());
408  $this->assertNull($querySettings->getLanguageMode());
409 
410  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
411  $query->matching($query->equals('tags.name', 'Tag1'));
413  $posts = $query->execute()->toArray();
414  $this->assertCount(3, $posts);
415  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
416  $this->assertSame('Post3', $posts[2]->getTitle());
417  }
418 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingPostsReturnsGreekPostsWithFallback
‪fetchingPostsReturnsGreekPostsWithFallback()
Definition: TranslationLegacyTest.php:217
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingTranslatedPostByTitle
‪fetchingTranslatedPostByTitle()
Definition: TranslationLegacyTest.php:354
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\orderingByTitleRespectsEnglishTitles
‪orderingByTitleRespectsEnglishTitles()
Definition: TranslationLegacyTest.php:269
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingPostsReturnsGreekPostsWithHideNonTranslated
‪fetchingPostsReturnsGreekPostsWithHideNonTranslated()
Definition: TranslationLegacyTest.php:244
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingPostByTagName
‪fetchingPostByTagName()
Definition: TranslationLegacyTest.php:375
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingHiddenPostsWithIgnoreEnableField
‪fetchingHiddenPostsWithIgnoreEnableField()
Definition: TranslationLegacyTest.php:298
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\countReturnsCorrectNumberOfPostsInGreekLanguage
‪countReturnsCorrectNumberOfPostsInGreekLanguage()
Definition: TranslationLegacyTest.php:171
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:95
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingPostsReturnsEnglishPostsWithFallback
‪fetchingPostsReturnsEnglishPostsWithFallback()
Definition: TranslationLegacyTest.php:190
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪ExtbaseTeam\BlogExample\Domain\Model\Post
Definition: Post.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\setUp
‪setUp()
Definition: TranslationLegacyTest.php:48
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\setUpBasicFrontendEnvironment
‪setUpBasicFrontendEnvironment()
Definition: TranslationLegacyTest.php:84
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:2
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\countReturnsCorrectNumberOfPosts
‪countReturnsCorrectNumberOfPosts()
Definition: TranslationLegacyTest.php:110
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingHiddenPostsReturnsHiddenOverlay
‪fetchingHiddenPostsReturnsHiddenOverlay()
Definition: TranslationLegacyTest.php:326
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest
Definition: TranslationLegacyTest.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: TranslationLegacyTest.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: TranslationLegacyTest.php:35
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\countReturnsCorrectNumberOfPostsInEnglishLanguageForStrictMode
‪countReturnsCorrectNumberOfPostsInEnglishLanguageForStrictMode()
Definition: TranslationLegacyTest.php:133
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\countReturnsCorrectNumberOfPostsInEnglishLanguage
‪countReturnsCorrectNumberOfPostsInEnglishLanguage()
Definition: TranslationLegacyTest.php:153
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\fetchingTranslatedPostByTagName
‪fetchingTranslatedPostByTagName()
Definition: TranslationLegacyTest.php:396
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:72
‪ExtbaseTeam
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\$postRepository
‪TYPO3 CMS Extbase Persistence Repository $postRepository
Definition: TranslationLegacyTest.php:43
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationLegacyTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: TranslationLegacyTest.php:31