‪TYPO3CMS  9.5
QueryLocalizedDataLegacyTest.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 
18 use PHPUnit\Framework\MockObject\MockObject;
28 
33 class ‪QueryLocalizedDataLegacyTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
34 {
38  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
39 
43  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
44 
48  protected ‪$objectManager;
49 
53  protected ‪$postRepository;
54 
59 
63  protected function ‪setUp()
64  {
65  parent::setUp();
66 
67  $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translatedBlogExampleData.csv');
69 
70  $this->objectManager = GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
71  $configuration = [
72  'features' => ['consistentTranslationOverlayHandling' => 0],
73  'persistence' => [
74  'storagePid' => 20,
75  'classes' => [
76  'TYPO3\CMS\Extbase\Domain\Model\Category' => [
77  'mapping' => ['tableName' => 'sys_category']
78  ]
79  ]
80  ]
81  ];
82  $configurationManager = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Configuration\ConfigurationManagerInterface::class);
83  $configurationManager->setConfiguration($configuration);
84  $this->postRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
85  $this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
86  }
87 
91  protected function ‪setUpBasicFrontendEnvironment()
92  {
94  $environmentServiceMock = $this->createMock(EnvironmentService::class);
95  $environmentServiceMock
96  ->expects($this->atLeast(1))
97  ->method('isEnvironmentInFrontendMode')
98  ->willReturn(true);
99  GeneralUtility::setSingletonInstance(EnvironmentService::class, $environmentServiceMock);
100 
101  $context = GeneralUtility::makeInstance(Context::class);
102  $context->setAspect('language', new ‪LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_ON, []));
103 
104  $pageRepositoryFixture = new ‪PageRepository();
105  $frontendControllerMock = $this->createMock(\‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
106  $frontendControllerMock->sys_page = $pageRepositoryFixture;
107  ‪$GLOBALS['TSFE'] = $frontendControllerMock;
108  }
109 
119  {
120  $context = GeneralUtility::makeInstance(Context::class);
121  $context->setAspect('language', new LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_ON));
122 
123  $post2 = $this->postRepository->findByUid(2);
124 
125  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
126  $post2->getTitle(),
127  $post2->getUid(),
128  $post2->_getProperty('_localizedUid'),
129  $post2->getBlog()->getTitle(),
130  $post2->getBlog()->getUid(),
131  $post2->getBlog()->_getProperty('_localizedUid'),
132  $post2->getAuthor()->getFirstname(),
133  $post2->getAuthor()->getUid(),
134  $post2->getAuthor()->_getProperty('_localizedUid')
135  ]);
136 
137  //this is needed because of https://forge.typo3.org/issues/59992
138  $this->persistenceManager->clearState();
139 
140  $post2translated = $this->postRepository->findByUid(11);
141  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
142  $post2translated->getTitle(),
143  $post2translated->getUid(),
144  $post2translated->_getProperty('_localizedUid'),
145  $post2translated->getBlog()->getTitle(),
146  $post2translated->getBlog()->getUid(),
147  $post2translated->getBlog()->_getProperty('_localizedUid'),
148  $post2translated->getAuthor()->getFirstname(),
149  $post2translated->getAuthor()->getUid(),
150  $post2translated->getAuthor()->_getProperty('_localizedUid')
151  ]);
152  }
153 
159  public function ‪findByUidNoOverlaysDefaultLanguage()
160  {
161  $context = GeneralUtility::makeInstance(Context::class);
162  $context->setAspect('language', new LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_OFF));
163 
164  $post2 = $this->postRepository->findByUid(2);
165  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
166  $post2->getTitle(),
167  $post2->getUid(),
168  $post2->_getProperty('_localizedUid'),
169  $post2->getBlog()->getTitle(),
170  $post2->getBlog()->getUid(),
171  $post2->getBlog()->_getProperty('_localizedUid'),
172  $post2->getAuthor()->getFirstname(),
173  $post2->getAuthor()->getUid(),
174  $post2->getAuthor()->_getProperty('_localizedUid')
175  ]);
176 
177  //this is needed because of https://forge.typo3.org/issues/59992
178  $this->persistenceManager->clearState();
179 
180  $post2translated = $this->postRepository->findByUid(11);
181  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
182  $post2translated->getTitle(),
183  $post2translated->getUid(),
184  $post2translated->_getProperty('_localizedUid'),
185  $post2translated->getBlog()->getTitle(),
186  $post2translated->getBlog()->getUid(),
187  $post2translated->getBlog()->_getProperty('_localizedUid'),
188  $post2translated->getAuthor()->getFirstname(),
189  $post2translated->getAuthor()->getUid(),
190  $post2translated->getAuthor()->_getProperty('_localizedUid')
191  ]);
192  }
193 
199  public function ‪findByUidOverlayModeOnLanguage()
200  {
201  $context = GeneralUtility::makeInstance(Context::class);
202  $context->setAspect('language', new LanguageAspect(1, 1, ‪LanguageAspect::OVERLAYS_ON));
203 
204  $post2 = $this->postRepository->findByUid(2);
205  //this is needed because of https://forge.typo3.org/issues/59992
206  $this->persistenceManager->clearState();
207  $post2translated = $this->postRepository->findByUid(11);
208 
209  foreach ([$post2, $post2translated] as $post) {
210  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
211  $post->getTitle(),
212  $post->getUid(),
213  $post->_getProperty('_localizedUid'),
214  $post->getBlog()->getTitle(),
215  $post->getBlog()->getUid(),
216  $post->getBlog()->_getProperty('_localizedUid'),
217  $post->getAuthor()->getFirstname(),
218  $post->getAuthor()->getUid(),
219  $post->getAuthor()->_getProperty('_localizedUid')
220  ]);
221  }
222  }
223 
229  public function ‪findByUidNoOverlaysLanguage()
230  {
231  $context = GeneralUtility::makeInstance(Context::class);
232  $context->setAspect('language', new LanguageAspect(1, 1, ‪LanguageAspect::OVERLAYS_OFF));
233 
234  $post2 = $this->postRepository->findByUid(2);
235  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
236  $post2->getTitle(),
237  $post2->getUid(),
238  $post2->_getProperty('_localizedUid'),
239  $post2->getBlog()->getTitle(),
240  $post2->getBlog()->getUid(),
241  $post2->getBlog()->_getProperty('_localizedUid'),
242  $post2->getAuthor()->getFirstname(),
243  $post2->getAuthor()->getUid(),
244  $post2->getAuthor()->_getProperty('_localizedUid')
245  ]);
246 
247  //this is needed because of https://forge.typo3.org/issues/59992
248  $this->persistenceManager->clearState();
249 
250  $post2translated = $this->postRepository->findByUid(11);
251  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
252  $post2translated->getTitle(),
253  $post2translated->getUid(),
254  $post2translated->_getProperty('_localizedUid'),
255  $post2translated->getBlog()->getTitle(),
256  $post2translated->getBlog()->getUid(),
257  $post2translated->getBlog()->_getProperty('_localizedUid'),
258  $post2translated->getAuthor()->getFirstname(),
259  $post2translated->getAuthor()->getUid(),
260  $post2translated->getAuthor()->_getProperty('_localizedUid')
261  ]);
262  }
263 
273  public function ‪customFindByUidOverlayEnabled()
274  {
275  // we're in default lang and fetching by uid of the record in default language
276  $query = $this->postRepository->createQuery();
277  $querySettings = $query->getQuerySettings();
278  $querySettings->setLanguageUid(0);
279  $querySettings->setLanguageOverlayMode(true);
280  $query->matching($query->equals('uid', 2));
281  $post2 = $query->execute()->getFirst();
282 
283  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
284  $post2->getTitle(),
285  $post2->getUid(),
286  $post2->_getProperty('_localizedUid'),
287  $post2->getBlog()->getTitle(),
288  $post2->getBlog()->getUid(),
289  $post2->getBlog()->_getProperty('_localizedUid'),
290  $post2->getAuthor()->getFirstname(),
291  $post2->getAuthor()->getUid(),
292  $post2->getAuthor()->_getProperty('_localizedUid')
293  ]);
294 
295  //this is needed because of https://forge.typo3.org/issues/59992
296  $this->persistenceManager->clearState();
297 
298  $query = $this->postRepository->createQuery();
299  $querySettings = $query->getQuerySettings();
300  $querySettings->setLanguageUid(0);
301  $querySettings->setLanguageOverlayMode(true);
302  $query->matching($query->equals('uid', 11));
303  $post2 = $query->execute()->getFirst();
304 
305  $this->assertNull($post2);
306 
307  //this is needed because of https://forge.typo3.org/issues/59992
308  $this->persistenceManager->clearState();
309 
310  $query = $this->postRepository->createQuery();
311  $querySettings = $query->getQuerySettings();
312  $querySettings->setLanguageUid(1);
313  $querySettings->setLanguageOverlayMode(true);
314  $query->matching($query->equals('uid', 2));
315  $post2 = $query->execute()->getFirst();
316 
317  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1', 1, 1, 'John', 1, 1], [
318  $post2->getTitle(),
319  $post2->getUid(),
320  $post2->_getProperty('_localizedUid'),
321  $post2->getBlog()->getTitle(),
322  $post2->getBlog()->getUid(),
323  $post2->getBlog()->_getProperty('_localizedUid'),
324  $post2->getAuthor()->getFirstname(),
325  $post2->getAuthor()->getUid(),
326  $post2->getAuthor()->_getProperty('_localizedUid')
327  ]);
328 
329  //this is needed because of https://forge.typo3.org/issues/59992
330  $this->persistenceManager->clearState();
331 
332  $query = $this->postRepository->createQuery();
333  $querySettings = $query->getQuerySettings();
334  $querySettings->setLanguageUid(1);
335  $querySettings->setLanguageOverlayMode(true);
336  $query->matching($query->equals('uid', 11));
337  $post2 = $query->execute()->getFirst();
338 
339  $this->assertNull($post2);
340  }
341 
351  public function ‪customFindByUidOverlayDisabled()
352  {
353  $query = $this->postRepository->createQuery();
354  $querySettings = $query->getQuerySettings();
355  $querySettings->setLanguageUid(0);
356  $querySettings->setLanguageOverlayMode(false);
357  $query->matching($query->equals('uid', 2));
358  $post2 = $query->execute()->getFirst();
359 
360  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
361  $post2->getTitle(),
362  $post2->getUid(),
363  $post2->_getProperty('_localizedUid'),
364  $post2->getBlog()->getTitle(),
365  $post2->getBlog()->getUid(),
366  $post2->getBlog()->_getProperty('_localizedUid'),
367  $post2->getAuthor()->getFirstname(),
368  $post2->getAuthor()->getUid(),
369  $post2->getAuthor()->_getProperty('_localizedUid')
370  ]);
371 
372  //this is needed because of https://forge.typo3.org/issues/59992
373  $this->persistenceManager->clearState();
374 
375  $query = $this->postRepository->createQuery();
376  $querySettings = $query->getQuerySettings();
377  $querySettings->setLanguageUid(0);
378  $querySettings->setLanguageOverlayMode(false);
379  $query->matching($query->equals('uid', 11));
380  $post2 = $query->execute()->getFirst();
381 
382  $this->assertNull($post2);
383 
384  //this is needed because of https://forge.typo3.org/issues/59992
385  $this->persistenceManager->clearState();
386 
387  $query = $this->postRepository->createQuery();
388  $querySettings = $query->getQuerySettings();
389  $querySettings->setLanguageUid(1);
390  $querySettings->setLanguageOverlayMode(false);
391  $query->matching($query->equals('uid', 2));
392  $post2 = $query->execute()->getFirst();
393 
394  //the john is not translated but it should, see next query in this test
395  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1', 1, 1, 'John', 1, 1], [
396  $post2->getTitle(),
397  $post2->getUid(),
398  $post2->_getProperty('_localizedUid'),
399  $post2->getBlog()->getTitle(),
400  $post2->getBlog()->getUid(),
401  $post2->getBlog()->_getProperty('_localizedUid'),
402  $post2->getAuthor()->getFirstname(),
403  $post2->getAuthor()->getUid(),
404  $post2->getAuthor()->_getProperty('_localizedUid')
405  ]);
406 
407  //this is needed because of https://forge.typo3.org/issues/59992
408  $this->persistenceManager->clearState();
409 
410  $query = $this->postRepository->createQuery();
411  $querySettings = $query->getQuerySettings();
412  $querySettings->setLanguageUid(1);
413  $querySettings->setLanguageOverlayMode(false);
414  $query->matching($query->equals('uid', 11));
415  $post2 = $query->execute()->getFirst();
416 
417  $this->assertNull($post2);
418 
419  //We're setting global context here to show that the result is different then one above.
420  //this means that language which is set in global context influences overlays of relations
421  $context = GeneralUtility::makeInstance(Context::class);
422  $context->setAspect('language', new LanguageAspect(1, 1, ‪LanguageAspect::OVERLAYS_ON));
423 
424  //this is needed because of https://forge.typo3.org/issues/59992
425  $this->persistenceManager->clearState();
426 
427  $query = $this->postRepository->createQuery();
428  $querySettings = $query->getQuerySettings();
429  $querySettings->setLanguageUid(1);
430  $querySettings->setLanguageOverlayMode(false);
431  $query->matching($query->equals('uid', 11));
432  $post2 = $query->execute()->getFirst();
433 
434  $this->assertNull($post2);
435  }
436 
437  public function ‪queryFirst5PostsDataProvider()
438  {
439  //put it to variable to make cases with the same expected values explicit
440  $lang0Expected = [
441  [
442  'title' => 'Post 4',
443  'uid' => 4,
444  '_localizedUid' => 4,
445  'content' => 'A - content',
446  'blog.title' => 'Blog 1',
447  'blog.uid' => 1,
448  'blog._localizedUid' => 1,
449  'author.firstname' => 'John',
450  'author.uid' => 1,
451  'author._localizedUid' => 1,
452  'secondAuthor.firstname' => 'John',
453  'secondAuthor.uid' => 1,
454  'secondAuthor._localizedUid' => 1,
455  'tags' => [],
456  ],
457  [
458  'title' => 'Post 2',
459  'uid' => 2,
460  '_localizedUid' => 2,
461  'content' => 'B - content',
462  'blog.title' => 'Blog 1',
463  'blog.uid' => 1,
464  'blog._localizedUid' => 1,
465  'author.firstname' => 'John',
466  'author.uid' => 1,
467  'author._localizedUid' => 1,
468  'secondAuthor.firstname' => 'John',
469  'secondAuthor.uid' => 1,
470  'secondAuthor._localizedUid' => 1,
471  'tags.0.name' => 'Tag2',
472  'tags.0.uid' => 2,
473  'tags.0._localizedUid' => 2,
474  'tags.1.name' => 'Tag3',
475  'tags.1.uid' => 3,
476  'tags.1._localizedUid' => 3,
477  'tags.2.name' => 'Tag4',
478  'tags.2.uid' => 4,
479  'tags.2._localizedUid' => 4,
480  ],
481  [
482  'title' => 'Post 7',
483  'uid' => 7,
484  '_localizedUid' => 7,
485  'content' => 'C - content',
486  'blog.title' => 'Blog 1',
487  'blog.uid' => 1,
488  'blog._localizedUid' => 1,
489  'author.firstname' => 'John',
490  'author.uid' => 1,
491  'author._localizedUid' => 1,
492  'secondAuthor.firstname' => 'John',
493  'secondAuthor.uid' => 1,
494  'secondAuthor._localizedUid' => 1,
495  'tags' => [],
496  ],
497  [
498  'title' => 'Post 6',
499  'uid' => 6,
500  '_localizedUid' => 6,
501  'content' => 'F - content',
502  'blog.title' => 'Blog 1',
503  'blog.uid' => 1,
504  'blog._localizedUid' => 1,
505  'author.firstname' => 'John',
506  'author.uid' => 1,
507  'author._localizedUid' => 1,
508  'secondAuthor.firstname' => 'John',
509  'secondAuthor.uid' => 1,
510  'secondAuthor._localizedUid' => 1,
511  'tags' => [],
512  ],
513  [
514  'title' => 'Post 1 - not translated',
515  'uid' => 1,
516  '_localizedUid' => 1,
517  'content' => 'G - content',
518  'blog.title' => 'Blog 1',
519  'blog.uid' => 1,
520  'blog._localizedUid' => 1,
521  'author.firstname' => 'John',
522  'author.uid' => 1,
523  'author._localizedUid' => 1,
524  'secondAuthor.firstname' => 'Never translate me henry',
525  'secondAuthor.uid' => 3,
526  'secondAuthor._localizedUid' => 3,
527  'tags.0.name' => 'Tag1',
528  'tags.0.uid' => 1,
529  'tags.0._localizedUid' => 1,
530  'tags.1.name' => 'Tag2',
531  'tags.1.uid' => 2,
532  'tags.1._localizedUid' => 2,
533  'tags.2.name' => 'Tag3',
534  'tags.2.uid' => 3,
535  'tags.2._localizedUid' => 3,
536  ],
537  ];
538  return [
539  [
540  'language' => 0,
541  'overlay' => true,
542  'expected' => $lang0Expected
543  ],
544  [
545  'language' => 0,
546  'overlay' => false,
547  'expected' => $lang0Expected
548  ],
549  [
550  'language' => 1,
551  'overlay' => true,
552  'expected' => [
553  [
554  'title' => 'Post 4 - DK',
555  'uid' => 4,
556  '_localizedUid' => 12,
557  'content' => 'U - content',
558  'blog.title' => 'Blog 1',
559  'blog.uid' => 1,
560  'blog._localizedUid' => 1,
561  'author.firstname' => 'John',
562  'author.uid' => 1,
563  'author._localizedUid' => 1,
564  'secondAuthor.firstname' => 'John',
565  'secondAuthor.uid' => 1,
566  'secondAuthor._localizedUid' => 1,
567  'tags' => [],
568  ],
569  [
570  'title' => 'Post 2 - DK',
571  'uid' => 2,
572  '_localizedUid' => 11,
573  'content' => 'C - content',
574  'blog.title' => 'Blog 1',
575  'blog.uid' => 1,
576  'blog._localizedUid' => 1,
577  'author.firstname' => 'John',
578  'author.uid' => 1,
579  'author._localizedUid' => 1,
580  'secondAuthor.firstname' => 'John',
581  'secondAuthor.uid' => 1,
582  'secondAuthor._localizedUid' => 1,
583  'tags.0.name' => 'Tag2',
584  'tags.0.uid' => 2,
585  'tags.0._localizedUid' => 2,
586  'tags.1.name' => 'Tag3',
587  'tags.1.uid' => 3,
588  'tags.1._localizedUid' => 3,
589  'tags.2.name' => 'Tag4',
590  'tags.2.uid' => 4,
591  'tags.2._localizedUid' => 4,
592  ],
593  [
594  'title' => 'Post DK only',
595  'uid' => 15,
596  '_localizedUid' => 15,
597  'content' => 'B - content',
598  'blog.title' => 'Blog 1',
599  'blog.uid' => 1,
600  'blog._localizedUid' => 1,
601  'author.firstname' => 'John',
602  'author.uid' => 1,
603  'author._localizedUid' => 1,
604  'secondAuthor.firstname' => 'John',
605  'secondAuthor.uid' => 1,
606  'secondAuthor._localizedUid' => 1,
607  'tags' => [],
608  ],
609  [
610  'title' => 'Post 7 - DK',
611  'uid' => 7,
612  '_localizedUid' => 14,
613  'content' => 'S - content',
614  'blog.title' => 'Blog 1',
615  'blog.uid' => 1,
616  'blog._localizedUid' => 1,
617  'author.firstname' => 'John',
618  'author.uid' => 1,
619  'author._localizedUid' => 1,
620  'secondAuthor.firstname' => 'John',
621  'secondAuthor.uid' => 1,
622  'secondAuthor._localizedUid' => 1,
623  'tags' => [],
624  ],
625  [
626  'title' => 'Post 5 - DK',
627  'uid' => 5,
628  '_localizedUid' => 13,
629  'content' => 'A - content',
630  'blog.title' => 'Blog 1',
631  'blog.uid' => 1,
632  'blog._localizedUid' => 1,
633  'author.firstname' => 'John',
634  'author.uid' => 1,
635  'author._localizedUid' => 1,
636  'secondAuthor.firstname' => 'John',
637  'secondAuthor.uid' => 1,
638  'secondAuthor._localizedUid' => 1,
639  'tags' => [],
640  ],
641  ],
642  ],
643  [
644  'language' => 1,
645  'overlay' => 'hideNonTranslated',
646  'expected' => [
647  [
648  'title' => 'Post 4 - DK',
649  'uid' => 4,
650  '_localizedUid' => 12,
651  'content' => 'U - content',
652  'blog.title' => 'Blog 1',
653  'blog.uid' => 1,
654  'blog._localizedUid' => 1,
655  'author.firstname' => 'John',
656  'author.uid' => 1,
657  'author._localizedUid' => 1,
658  'secondAuthor.firstname' => 'John',
659  'secondAuthor.uid' => 1,
660  'secondAuthor._localizedUid' => 1,
661  'tags' => [],
662  ],
663  [
664  'title' => 'Post 2 - DK',
665  'uid' => 2,
666  '_localizedUid' => 11,
667  'content' => 'C - content',
668  'blog.title' => 'Blog 1',
669  'blog.uid' => 1,
670  'blog._localizedUid' => 1,
671  'author.firstname' => 'John',
672  'author.uid' => 1,
673  'author._localizedUid' => 1,
674  'secondAuthor.firstname' => 'John',
675  'secondAuthor.uid' => 1,
676  'secondAuthor._localizedUid' => 1,
677  'tags.0.name' => 'Tag2',
678  'tags.0.uid' => 2,
679  'tags.0._localizedUid' => 2,
680  'tags.1.name' => 'Tag3',
681  'tags.1.uid' => 3,
682  'tags.1._localizedUid' => 3,
683  'tags.2.name' => 'Tag4',
684  'tags.2.uid' => 4,
685  'tags.2._localizedUid' => 4,
686  ],
687  [
688  'title' => 'Post DK only',
689  'uid' => 15,
690  '_localizedUid' => 15,
691  'content' => 'B - content',
692  'blog.title' => 'Blog 1',
693  'blog.uid' => 1,
694  'blog._localizedUid' => 1,
695  'author.firstname' => 'John',
696  'author.uid' => 1,
697  'author._localizedUid' => 1,
698  'secondAuthor.firstname' => 'John',
699  'secondAuthor.uid' => 1,
700  'secondAuthor._localizedUid' => 1,
701  'tags' => [],
702  ],
703  [
704  'title' => 'Post 7 - DK',
705  'uid' => 7,
706  '_localizedUid' => 14,
707  'content' => 'S - content',
708  'blog.title' => 'Blog 1',
709  'blog.uid' => 1,
710  'blog._localizedUid' => 1,
711  'author.firstname' => 'John',
712  'author.uid' => 1,
713  'author._localizedUid' => 1,
714  'secondAuthor.firstname' => 'John',
715  'secondAuthor.uid' => 1,
716  'secondAuthor._localizedUid' => 1,
717  'tags' => [],
718 
719  ],
720  [
721  'title' => 'Post 5 - DK',
722  'uid' => 5,
723  '_localizedUid' => 13,
724  'content' => 'A - content',
725  'blog.title' => 'Blog 1',
726  'blog.uid' => 1,
727  'blog._localizedUid' => 1,
728  'author.firstname' => 'John',
729  'author.uid' => 1,
730  'author._localizedUid' => 1,
731  'secondAuthor.firstname' => 'John',
732  'secondAuthor.uid' => 1,
733  'secondAuthor._localizedUid' => 1,
734  'tags' => [],
735  ],
736  ],
737  ],
738  [
739  'language' => 1,
740  'overlay' => false,
741  'expected' => [
742  [
743  'title' => 'Post 4 - DK',
744  'uid' => 4,
745  '_localizedUid' => 12,
746  'content' => 'U - content',
747  'blog.title' => 'Blog 1',
748  'blog.uid' => 1,
749  'blog._localizedUid' => 1,
750  'author.firstname' => 'John',
751  'author.uid' => 1,
752  'author._localizedUid' => 1,
753  'secondAuthor.firstname' => 'John',
754  'secondAuthor.uid' => 1,
755  'secondAuthor._localizedUid' => 1,
756  'tags' => [],
757  ],
758  [
759  'title' => 'Post 2 - DK',
760  'uid' => 2,
761  '_localizedUid' => 11,
762  'content' => 'C - content',
763  'blog.title' => 'Blog 1',
764  'blog.uid' => 1,
765  'blog._localizedUid' => 1,
766  'author.firstname' => 'John',
767  'author.uid' => 1,
768  'author._localizedUid' => 1,
769  'secondAuthor.firstname' => 'John',
770  'secondAuthor.uid' => 1,
771  'secondAuthor._localizedUid' => 1,
772  'tags.0.name' => 'Tag2',
773  'tags.0.uid' => 2,
774  'tags.0._localizedUid' => 2,
775  'tags.1.name' => 'Tag3',
776  'tags.1.uid' => 3,
777  'tags.1._localizedUid' => 3,
778  'tags.2.name' => 'Tag4',
779  'tags.2.uid' => 4,
780  'tags.2._localizedUid' => 4,
781  ],
782  [
783  'title' => 'Post DK only',
784  'uid' => 15,
785  '_localizedUid' => 15,
786  'content' => 'B - content',
787  'blog.title' => 'Blog 1',
788  'blog.uid' => 1,
789  'blog._localizedUid' => 1,
790  'author.firstname' => 'John',
791  'author.uid' => 1,
792  'author._localizedUid' => 1,
793  'secondAuthor.firstname' => 'John',
794  'secondAuthor.uid' => 1,
795  'secondAuthor._localizedUid' => 1,
796  'tags' => [],
797  ],
798  [
799  'title' => 'Post 7 - DK',
800  'uid' => 7,
801  '_localizedUid' => 14,
802  'content' => 'S - content',
803  'blog.title' => 'Blog 1',
804  'blog.uid' => 1,
805  'blog._localizedUid' => 1,
806  'author.firstname' => 'John',
807  'author.uid' => 1,
808  'author._localizedUid' => 1,
809  'secondAuthor.firstname' => 'John',
810  'secondAuthor.uid' => 1,
811  'secondAuthor._localizedUid' => 1,
812  'tags' => [],
813  ],
814  [
815  'title' => 'Post 5 - DK',
816  'uid' => 5,
817  '_localizedUid' => 13,
818  'content' => 'A - content',
819  'blog.title' => 'Blog 1',
820  'blog.uid' => 1,
821  'blog._localizedUid' => 1,
822  'author.firstname' => 'John',
823  'author.uid' => 1,
824  'author._localizedUid' => 1,
825  'secondAuthor.firstname' => 'John',
826  'secondAuthor.uid' => 1,
827  'secondAuthor._localizedUid' => 1,
828  'tags' => [],
829  ],
830  ],
831  ],
832  ];
833  }
834 
847  public function ‪queryFirst5Posts($languageUid, $overlay, $expected)
848  {
849  $query = $this->postRepository->createQuery();
850  $querySettings = $query->getQuerySettings();
851  $querySettings->setLanguageUid($languageUid);
852  $querySettings->setLanguageOverlayMode($overlay);
853 
854  $query->setOrderings([
857  ]);
858  $query->setLimit(5);
859  $query->setOffset(0);
860  $posts = $query->execute()->toArray();
861 
862  $this->assertCount(5, $posts);
863  $this->‪assertObjectsProperties($posts, $expected);
864  }
865 
866  public function ‪queryPostsByPropertyDataProvider()
867  {
868  $lang0Expected = [
869  [
870  'title' => 'Post 5',
871  'uid' => 5,
872  '_localizedUid' => 5,
873  'content' => 'Z - content',
874  'blog.title' => 'Blog 1',
875  'blog.uid' => 1,
876  'blog._localizedUid' => 1,
877  'author.firstname' => 'John',
878  'author.uid' => 1,
879  'author._localizedUid' => 1,
880  'secondAuthor.firstname' => 'John',
881  'secondAuthor.uid' => 1,
882  'secondAuthor._localizedUid' => 1,
883  ],
884  [
885  'title' => 'Post 6',
886  'uid' => 6,
887  '_localizedUid' => 6,
888  'content' => 'F - content',
889  'blog.title' => 'Blog 1',
890  'blog.uid' => 1,
891  'blog._localizedUid' => 1,
892  'author.firstname' => 'John',
893  'author.uid' => 1,
894  'author._localizedUid' => 1,
895  'secondAuthor.firstname' => 'John',
896  'secondAuthor.uid' => 1,
897  'secondAuthor._localizedUid' => 1,
898  'tags' => [],
899  ]
900  ];
901  $lang1Expected = [
902  [
903  'title' => 'Post 5 - DK',
904  'uid' => 5,
905  '_localizedUid' => 13,
906  'content' => 'A - content',
907  'blog.title' => 'Blog 1',
908  'blog.uid' => 1,
909  'blog._localizedUid' => 1,
910  'author.firstname' => 'John',
911  'author.uid' => 1,
912  'author._localizedUid' => 1,
913  'secondAuthor.firstname' => 'John',
914  'secondAuthor.uid' => 1,
915  'secondAuthor._localizedUid' => 1,
916  ],
917  [
918  'title' => 'Post DK only',
919  'uid' => 15,
920  '_localizedUid' => 15,
921  'content' => 'B - content',
922  'blog.title' => 'Blog 1',
923  'blog.uid' => 1,
924  'blog._localizedUid' => 1,
925  'author.firstname' => 'John',
926  'author.uid' => 1,
927  'author._localizedUid' => 1,
928  'secondAuthor.firstname' => 'John',
929  'secondAuthor.uid' => 1,
930  'secondAuthor._localizedUid' => 1,
931  ],
932 
933  ];
934  return [
935  [
936  'language' => 0,
937  'overlay' => true,
938  'expected' => $lang0Expected
939  ],
940  [
941  'language' => 0,
942  'overlay' => 'hideNonTranslated',
943  'expected' => $lang0Expected
944  ],
945  [
946  'language' => 0,
947  'overlay' => false,
948  'expected' => $lang0Expected
949  ],
950  [
951  'language' => 1,
952  'overlay' => true,
953  'expected' => $lang1Expected
954  ],
955  [
956  'language' => 1,
957  'overlay' => 'hideNonTranslated',
958  'expected' => $lang1Expected,
959  ],
960  [
961  'language' => 1,
962  'overlay' => false,
963  'expected' => $lang1Expected,
964  ],
965  ];
966  }
967 
984  public function ‪queryPostsByProperty($languageUid, $overlay, $expected)
985  {
986  $query = $this->postRepository->createQuery();
987  $querySettings = $query->getQuerySettings();
988  $querySettings->setLanguageUid($languageUid);
989  $querySettings->setLanguageOverlayMode($overlay);
990 
991  $query->matching(
992  $query->logicalOr(
993  $query->like('title', 'Post 5%'),
994  $query->like('title', 'Post 6%'),
995  $query->like('title', 'Post DK only')
996  )
997  );
998  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
999  $posts = $query->execute()->toArray();
1001  $this->assertCount(count($expected), $posts);
1002  $this->‪assertObjectsProperties($posts, $expected);
1003  }
1004 
1006  {
1007  $lang0Expected = [
1008  [
1009  'title' => 'Blog 1',
1010  'uid' => 1,
1011  '_localizedUid' => 1,
1012  ],
1013  [
1014  'title' => 'Blog 1',
1015  'uid' => 1,
1016  '_localizedUid' => 1,
1017  ],
1018  ];
1019  $lang1Expected = [
1020  [
1021  'title' => 'Blog 1 DK',
1022  'uid' => 1,
1023  '_localizedUid' => 2,
1024  ],
1025  [
1026  'title' => 'Blog 1 DK',
1027  'uid' => 1,
1028  '_localizedUid' => 2,
1029  ],
1030  ];
1031  return [
1032  [
1033  'language' => 0,
1034  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1035  'mode' => null,
1036  'expected' => $lang0Expected
1037  ],
1038  [
1039  'language' => 0,
1040  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1041  'mode' => 'strict',
1042  'expected' => $lang0Expected
1043  ],
1044  [
1045  'language' => 0,
1046  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1047  'mode' => null,
1048  'expected' => $lang0Expected
1049  ],
1050  [
1051  'language' => 0,
1052  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1053  'mode' => 'strict',
1054  'expected' => $lang0Expected
1055  ],
1056  [
1057  'language' => 1,
1058  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1059  'mode' => null,
1060  'expected' => $lang1Expected
1061  ],
1062  [
1063  'language' => 1,
1064  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1065  'mode' => 'strict',
1066  'expected' => $lang1Expected
1067  ],
1068  [
1069  'language' => 1,
1070  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1071  'mode' => null,
1072  'expected' => $lang1Expected
1073  ],
1074  [
1075  'language' => 1,
1076  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1077  'mode' => 'strict',
1078  'expected' => $lang1Expected
1079  ],
1080  ];
1081  }
1082 
1098  public function ‪postsWithoutRespectingSysLanguage($languageUid, $overlay, $languageMode, $expected)
1099  {
1100  $context = GeneralUtility::makeInstance(Context::class);
1101  $context->setAspect('language', new LanguageAspect($languageUid, $languageUid, $overlay));
1102 
1103  $blogRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
1104  $query = $blogRepository->createQuery();
1105  $querySettings = $query->getQuerySettings();
1106  $querySettings->setLanguageMode($languageMode);
1107  $querySettings->setRespectSysLanguage(false);
1108 
1109  $posts = $query->execute()->toArray();
1110 
1111  $this->assertCount(count($expected), $posts);
1112  $this->‪assertObjectsProperties($posts, $expected);
1113  }
1114 
1121  protected function ‪assertObjectsProperties($objects, $expected)
1122  {
1123  $actual = [];
1124  foreach ($objects as $key => $post) {
1125  $actualPost = [];
1126  $propertiesToCheck = array_keys($expected[$key]);
1127  foreach ($propertiesToCheck as $propertyPath) {
1128  $actualPost[$propertyPath] = ‪self::getPropertyPath($post, $propertyPath);
1129  }
1130  $actual[] = $actualPost;
1131  $this->assertEquals($expected[$key], $actual[$key], 'Assertion of the $expected[' . $key . '] failed');
1132  }
1133  $this->assertEquals($expected, $actual);
1134  }
1135 
1145  protected static function ‪getPropertyPath($subject, $propertyPath)
1146  {
1147  $propertyPathSegments = explode('.', $propertyPath);
1148  try {
1149  foreach ($propertyPathSegments as $pathSegment) {
1150  $subject = ‪ObjectAccess::getPropertyInternal($subject, $pathSegment, true);
1151  if ($subject instanceof \SplObjectStorage || $subject instanceof ObjectStorage) {
1152  $subject = iterator_to_array(clone $subject, false);
1153  }
1154  }
1155  } catch (\‪TYPO3\CMS\‪Extbase\Reflection\Exception\PropertyNotAccessibleException $error) {
1156  return null;
1157  }
1158  return $subject;
1159  }
1160 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\customFindByUidOverlayDisabled
‪customFindByUidOverlayDisabled()
Definition: QueryLocalizedDataLegacyTest.php:346
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\customFindByUidOverlayEnabled
‪customFindByUidOverlayEnabled()
Definition: QueryLocalizedDataLegacyTest.php:268
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: QueryLocalizedDataLegacyTest.php:45
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\$postRepository
‪TYPO3 CMS Extbase Persistence Repository $postRepository
Definition: QueryLocalizedDataLegacyTest.php:49
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\$persistenceManager
‪$persistenceManager
Definition: QueryLocalizedDataLegacyTest.php:53
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: QueryLocalizedDataLegacyTest.php:37
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\setUp
‪setUp()
Definition: QueryLocalizedDataLegacyTest.php:58
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_ON
‪const OVERLAYS_ON
Definition: LanguageAspect.php:74
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\postsWithoutRespectingSysLanguage
‪postsWithoutRespectingSysLanguage($languageUid, $overlay, $languageMode, $expected)
Definition: QueryLocalizedDataLegacyTest.php:1093
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:29
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:26
‪TYPO3\CMS\Extbase\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\queryFirst5PostsDataProvider
‪queryFirst5PostsDataProvider()
Definition: QueryLocalizedDataLegacyTest.php:432
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest
Definition: QueryLocalizedDataLegacyTest.php:34
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:95
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: QueryLocalizedDataLegacyTest.php:41
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\findByUidNoOverlaysLanguage
‪findByUidNoOverlaysLanguage()
Definition: QueryLocalizedDataLegacyTest.php:224
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\queryPostsByPropertyDataProvider
‪queryPostsByPropertyDataProvider()
Definition: QueryLocalizedDataLegacyTest.php:861
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal
‪static mixed getPropertyInternal($subject, $propertyName, $forceDirectAccess=false)
Definition: ObjectAccess.php:80
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:2
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\setUpBasicFrontendEnvironment
‪setUpBasicFrontendEnvironment()
Definition: QueryLocalizedDataLegacyTest.php:86
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\findByUidNoOverlaysDefaultLanguage
‪findByUidNoOverlaysDefaultLanguage()
Definition: QueryLocalizedDataLegacyTest.php:154
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\assertObjectsProperties
‪assertObjectsProperties($objects, $expected)
Definition: QueryLocalizedDataLegacyTest.php:1116
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\findByUidOverlayModeOnLanguage
‪findByUidOverlayModeOnLanguage()
Definition: QueryLocalizedDataLegacyTest.php:194
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\postsWithoutRespectingSysLanguageDataProvider
‪postsWithoutRespectingSysLanguageDataProvider()
Definition: QueryLocalizedDataLegacyTest.php:1000
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\findByUidOverlayModeOnDefaultLanguage
‪findByUidOverlayModeOnDefaultLanguage()
Definition: QueryLocalizedDataLegacyTest.php:113
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:72
‪ExtbaseTeam
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\queryFirst5Posts
‪queryFirst5Posts($languageUid, $overlay, $expected)
Definition: QueryLocalizedDataLegacyTest.php:842
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\PersistenceManager
‪PersistenceManager
Definition: QueryLocalizedDataLegacyTest.php:53
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\getPropertyPath
‪static mixed getPropertyPath($subject, $propertyPath)
Definition: QueryLocalizedDataLegacyTest.php:1140
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataLegacyTest\queryPostsByProperty
‪queryPostsByProperty($languageUid, $overlay, $expected)
Definition: QueryLocalizedDataLegacyTest.php:979