‪TYPO3CMS  9.5
TranslationTest.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 ‪TranslationTest 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' => 1]
78  ];
79  $configurationManager = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Configuration\ConfigurationManagerInterface::class);
80  $configurationManager->setConfiguration($configuration);
81  $this->postRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
82  }
83 
87  protected function ‪setUpBasicFrontendEnvironment()
88  {
89  // in v9 overlay and language mode has different default values, so we need to set them here explicitely
90  // to match v8 behaviour
91  $context = GeneralUtility::makeInstance(Context::class);
92  $context->setAspect('language', new ‪LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_OFF, ['off']));
93 
95  $environmentServiceMock = $this->createMock(EnvironmentService::class);
96  $environmentServiceMock
97  ->expects($this->atLeast(1))
98  ->method('isEnvironmentInFrontendMode')
99  ->willReturn(true);
100  GeneralUtility::setSingletonInstance(EnvironmentService::class, $environmentServiceMock);
101 
102  $pageRepositoryFixture = new ‪PageRepository();
103  $frontendControllerMock = $this->createMock(\‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
104  $frontendControllerMock->sys_page = $pageRepositoryFixture;
105  ‪$GLOBALS['TSFE'] = $frontendControllerMock;
106  }
107 
113  public function ‪countReturnsCorrectNumberOfPosts()
114  {
115  $query = $this->postRepository->createQuery();
116 
117  $querySettings = $query->getQuerySettings();
118  $querySettings->setStoragePageIds([1]);
119  $querySettings->setRespectSysLanguage(true);
120  $querySettings->setLanguageUid(0);
121 
122  $this->assertFalse($querySettings->getLanguageOverlayMode());
123  $this->assertNull($querySettings->getLanguageMode());
124 
125  $postCount = $query->execute()->count();
126  $this->assertSame(3, $postCount);
127  }
128 
137  {
138  $query = $this->postRepository->createQuery();
139 
140  $querySettings = $query->getQuerySettings();
141  $querySettings->setStoragePageIds([1]);
142  $querySettings->setRespectSysLanguage(true);
143  $querySettings->setLanguageUid(1);
144  $querySettings->setLanguageMode('strict');
145  $this->assertFalse($querySettings->getLanguageOverlayMode());
146 
147  $postCount = $query->execute()->count();
148  $this->assertSame(2, $postCount);
149  }
150 
157  {
158  $query = $this->postRepository->createQuery();
159 
160  $querySettings = $query->getQuerySettings();
161  $querySettings->setStoragePageIds([1]);
162  $querySettings->setRespectSysLanguage(true);
163  $querySettings->setLanguageUid(1);
164 
165  $this->assertFalse($querySettings->getLanguageOverlayMode());
166  $this->assertNull($querySettings->getLanguageMode());
167 
168  $postCount = $query->execute()->count();
169  $this->assertSame(2, $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(1, $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(2, $posts);
211  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
212  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
213  }
214 
221  {
222  $query = $this->postRepository->createQuery();
223 
224  $querySettings = $query->getQuerySettings();
225  $querySettings->setStoragePageIds([1]);
226  $querySettings->setRespectSysLanguage(true);
227  $querySettings->setLanguageUid(2);
228  $this->assertFalse($querySettings->getLanguageOverlayMode());
229  $this->assertNull($querySettings->getLanguageMode());
230 
231  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
232 
234  $posts = $query->execute()->toArray();
235 
236  $this->assertCount(1, $posts);
237  $this->assertSame('GR:Post1', $posts[0]->getTitle());
238  }
239 
246  {
247  $query = $this->postRepository->createQuery();
248 
249  $querySettings = $query->getQuerySettings();
250  $querySettings->setStoragePageIds([1]);
251  $querySettings->setRespectSysLanguage(true);
252  $querySettings->setLanguageUid(2);
253  $querySettings->setLanguageOverlayMode('hideNonTranslated');
254  $this->assertNull($querySettings->getLanguageMode());
255 
256  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
257 
259  $posts = $query->execute()->toArray();
260 
261  $this->assertCount(1, $posts);
262  $this->assertSame('GR:Post1', $posts[0]->getTitle());
263  }
264 
269  {
270  $query = $this->postRepository->createQuery();
271 
272  $querySettings = $query->getQuerySettings();
273  $querySettings->setStoragePageIds([1]);
274  $querySettings->setRespectSysLanguage(true);
275  $querySettings->setLanguageUid(1);
276  $this->assertFalse($querySettings->getLanguageOverlayMode());
277  $this->assertNull($querySettings->getLanguageMode());
278 
279  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
280 
282  $posts = $query->execute()->toArray();
283 
284  $this->assertCount(2, $posts);
285  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
286  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
287  }
288 
295  public function ‪orderingByBlogTitle()
296  {
297  $query = $this->postRepository->createQuery();
298 
299  $querySettings = $query->getQuerySettings();
300  $querySettings->setStoragePageIds([1]);
301  $querySettings->setRespectSysLanguage(true);
302  $querySettings->setLanguageUid(1);
303  $this->assertFalse($querySettings->getLanguageOverlayMode());
304  $this->assertNull($querySettings->getLanguageMode());
305 
306  $query->setOrderings([
307  'blog.title' => ‪QueryInterface::ORDER_ASCENDING,
309  ]);
310 
312  $posts = $query->execute()->toArray();
313 
314  $this->assertCount(2, $posts);
315  $this->assertSame('B EN:Post1', $posts[0]->getTitle());
316  $this->assertSame('A EN:Post2', $posts[1]->getTitle());
317  }
318 
327  {
328  $query = $this->postRepository->createQuery();
329 
330  $querySettings = $query->getQuerySettings();
331  $querySettings->setStoragePageIds([1]);
332  $querySettings->setRespectSysLanguage(true);
333  $querySettings->setIgnoreEnableFields(true);
334  $querySettings->setLanguageUid(0);
335  //we need it to have stable results on pgsql
336  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
337 
339  $posts = $query->execute()->toArray();
340 
341  $this->assertCount(4, $posts);
342  $this->assertSame('Post10', $posts[3]->getTitle());
343  }
344 
352  {
353  $query = $this->postRepository->createQuery();
354 
355  $querySettings = $query->getQuerySettings();
356  $querySettings->setStoragePageIds([1]);
357  $querySettings->setRespectSysLanguage(true);
358  $querySettings->setIgnoreEnableFields(true);
359  $querySettings->setLanguageUid(2);
360  $this->assertFalse($querySettings->getLanguageOverlayMode());
361  //we need it to have stable results on pgsql
362  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
363 
365  $posts = $query->execute()->toArray();
366 
367  $this->assertCount(2, $posts);
368 
369  $this->assertSame('GR:Post1', $posts[0]->getTitle());
370  $this->assertSame('GR:Post10', $posts[1]->getTitle());
371  }
372 
383  {
384  $query = $this->postRepository->createQuery();
385 
386  $querySettings = $query->getQuerySettings();
387  $querySettings->setStoragePageIds([1]);
388  $querySettings->setRespectSysLanguage(true);
389  $querySettings->setIgnoreEnableFields(true);
390  $querySettings->setLanguageUid(2);
391  $querySettings->setLanguageOverlayMode(true);
392  //we need it to have stable results on pgsql
393  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
394 
396  $posts = $query->execute()->toArray();
397 
398  $this->assertCount(4, $posts);
399 
400  $this->assertSame('GR:Post1', $posts[0]->getTitle());
401  $this->assertSame('Post2', $posts[1]->getTitle());
402  $this->assertSame('Post3', $posts[2]->getTitle());
403  // once the issue is fixed this assertion should be GR:Post10
404  $this->assertSame('Post10', $posts[3]->getTitle());
405  }
406 
412  public function ‪fetchingTranslatedPostByTitle()
413  {
414  $query = $this->postRepository->createQuery();
415  $querySettings = $query->getQuerySettings();
416  $querySettings->setStoragePageIds([1]);
417  $querySettings->setRespectSysLanguage(true);
418  $querySettings->setLanguageUid(2);
419  $this->assertFalse($querySettings->getLanguageOverlayMode());
420  $this->assertNull($querySettings->getLanguageMode());
421 
422  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
423  $query->matching($query->equals('title', 'GR:Post1'));
425  $posts = $query->execute()->toArray();
426  $this->assertCount(1, $posts);
427  $this->assertSame('GR:Post1', $posts[0]->getTitle());
428  }
429 
436  public function ‪fetchingTranslatedPostByBlogTitle()
437  {
438  $query = $this->postRepository->createQuery();
439  $querySettings = $query->getQuerySettings();
440  $querySettings->setStoragePageIds([1]);
441  $querySettings->setRespectSysLanguage(true);
442  $querySettings->setLanguageUid(2);
443  $this->assertFalse($querySettings->getLanguageOverlayMode());
444  $this->assertNull($querySettings->getLanguageMode());
445 
446  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
447  $query->matching($query->equals('blog.title', 'Blog1'));
449  $posts = $query->execute()->toArray();
450  $this->assertCount(1, $posts);
451  $this->assertSame('GR:Post1', $posts[0]->getTitle());
452  }
453 
457  public function ‪fetchingPostByTagName()
458  {
459  $query = $this->postRepository->createQuery();
460  $querySettings = $query->getQuerySettings();
461  $querySettings->setRespectStoragePage(false);
462  $querySettings->setRespectSysLanguage(true);
463  $querySettings->setLanguageUid(0);
464  $this->assertFalse($querySettings->getLanguageOverlayMode());
465  $this->assertNull($querySettings->getLanguageMode());
466 
467  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
468  $query->matching($query->equals('tags.name', 'Tag1'));
470  $posts = $query->execute()->toArray();
471  $this->assertCount(3, $posts);
472  $this->assertSame('Post1', $posts[0]->getTitle());
473  }
474 
478  public function ‪fetchingTranslatedPostByTagName()
479  {
480  $query = $this->postRepository->createQuery();
481  $querySettings = $query->getQuerySettings();
482  $querySettings->setRespectStoragePage(false);
483  $querySettings->setRespectSysLanguage(true);
484  $querySettings->setLanguageUid(1);
485  $this->assertFalse($querySettings->getLanguageOverlayMode());
486  $this->assertNull($querySettings->getLanguageMode());
487 
488  $query->setOrderings(['title' => ‪QueryInterface::ORDER_ASCENDING]);
489  $query->matching($query->equals('tags.name', 'Tag1'));
491  $posts = $query->execute()->toArray();
492  $this->assertCount(2, $posts);
493  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
494  $this->assertSame(1, count($posts[0]->getTags()));
495  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
496  $this->assertSame(2, count($posts[1]->getTags()));
497  }
498 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingPostByTagName
‪fetchingPostByTagName()
Definition: TranslationTest.php:453
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingPostsReturnsGreekPostsWithHideNonTranslated
‪fetchingPostsReturnsGreekPostsWithHideNonTranslated()
Definition: TranslationTest.php:241
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\countReturnsCorrectNumberOfPosts
‪countReturnsCorrectNumberOfPosts()
Definition: TranslationTest.php:109
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\countReturnsCorrectNumberOfPostsInEnglishLanguage
‪countReturnsCorrectNumberOfPostsInEnglishLanguage()
Definition: TranslationTest.php:152
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\countReturnsCorrectNumberOfPostsInEnglishLanguageForStrictMode
‪countReturnsCorrectNumberOfPostsInEnglishLanguageForStrictMode()
Definition: TranslationTest.php:132
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingPostsReturnsEnglishPostsWithFallback
‪fetchingPostsReturnsEnglishPostsWithFallback()
Definition: TranslationTest.php:190
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingHiddenPostsWithIgnoreEnableField
‪fetchingHiddenPostsWithIgnoreEnableField()
Definition: TranslationTest.php:322
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: TranslationTest.php:31
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingTranslatedPostByTitle
‪fetchingTranslatedPostByTitle()
Definition: TranslationTest.php:408
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingPostsReturnsGreekPostsWithFallback
‪fetchingPostsReturnsGreekPostsWithFallback()
Definition: TranslationTest.php:216
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingTranslatedPostByBlogTitle
‪fetchingTranslatedPostByBlogTitle()
Definition: TranslationTest.php:432
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: TranslationTest.php:35
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\orderingByTitleRespectsEnglishTitles
‪orderingByTitleRespectsEnglishTitles()
Definition: TranslationTest.php:264
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:95
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\countReturnsCorrectNumberOfPostsInGreekLanguage
‪countReturnsCorrectNumberOfPostsInGreekLanguage()
Definition: TranslationTest.php:171
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingTranslatedPostByTagName
‪fetchingTranslatedPostByTagName()
Definition: TranslationTest.php:474
‪ExtbaseTeam\BlogExample\Domain\Model\Post
Definition: Post.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:2
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest
Definition: TranslationTest.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: TranslationTest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingHiddenPostsReturnsHiddenOverlay
‪fetchingHiddenPostsReturnsHiddenOverlay()
Definition: TranslationTest.php:347
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\orderingByBlogTitle
‪orderingByBlogTitle()
Definition: TranslationTest.php:291
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:72
‪ExtbaseTeam
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\$postRepository
‪TYPO3 CMS Extbase Persistence Repository $postRepository
Definition: TranslationTest.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\setUpBasicFrontendEnvironment
‪setUpBasicFrontendEnvironment()
Definition: TranslationTest.php:83
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\setUp
‪setUp()
Definition: TranslationTest.php:48
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\TranslationTest\fetchingHiddenPostsReturnsHiddenOverlayOverlayEnabled
‪fetchingHiddenPostsReturnsHiddenOverlayOverlayEnabled()
Definition: TranslationTest.php:378