‪TYPO3CMS  9.5
QueryLocalizedDataTest.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 
29 class ‪QueryLocalizedDataTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
30 {
34  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
35 
39  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
40 
44  protected ‪$objectManager;
45 
49  protected ‪$postRepository;
50 
55 
59  protected function ‪setUp()
60  {
61  parent::setUp();
62 
63  $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translatedBlogExampleData.csv');
65 
66  $this->objectManager = GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
67  $configuration = [
68  'features' => ['consistentTranslationOverlayHandling' => 1],
69  'persistence' => [
70  'storagePid' => 20,
71  'classes' => [
72  'TYPO3\CMS\Extbase\Domain\Model\Category' => [
73  'mapping' => ['tableName' => 'sys_category']
74  ]
75  ]
76  ]
77  ];
78  $configurationManager = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Configuration\ConfigurationManagerInterface::class);
79  $configurationManager->setConfiguration($configuration);
80  $this->postRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
81  $this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
82  }
83 
87  protected function ‪setUpBasicFrontendEnvironment()
88  {
90  $environmentServiceMock = $this->createMock(EnvironmentService::class);
91  $environmentServiceMock
92  ->expects($this->atLeast(1))
93  ->method('isEnvironmentInFrontendMode')
94  ->willReturn(true);
95  GeneralUtility::setSingletonInstance(EnvironmentService::class, $environmentServiceMock);
96 
97  $context = GeneralUtility::makeInstance(Context::class);
98  $context->setAspect('language', new ‪LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_ON, []));
99 
100  $pageRepositoryFixture = new ‪PageRepository();
101  $frontendControllerMock = $this->createMock(\‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
102  $frontendControllerMock->sys_page = $pageRepositoryFixture;
103  ‪$GLOBALS['TSFE'] = $frontendControllerMock;
104  }
105 
118  {
119  $context = GeneralUtility::makeInstance(Context::class);
120  $context->setAspect('language', new LanguageAspect(0, 0, ‪LanguageAspect::OVERLAYS_ON));
121 
122  $post2 = $this->postRepository->findByUid(2);
123 
124  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
125  $post2->getTitle(),
126  $post2->getUid(),
127  $post2->_getProperty('_localizedUid'),
128  $post2->getBlog()->getTitle(),
129  $post2->getBlog()->getUid(),
130  $post2->getBlog()->_getProperty('_localizedUid'),
131  $post2->getAuthor()->getFirstname(),
132  $post2->getAuthor()->getUid(),
133  $post2->getAuthor()->_getProperty('_localizedUid')
134  ]);
135 
136  //this is needed because of https://forge.typo3.org/issues/59992
137  $this->persistenceManager->clearState();
138 
139  // with feature flag disable, you'll get default language object here too (Post 2).
140  $post2translated = $this->postRepository->findByUid(11);
141  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
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 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
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->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
206  $post2->getTitle(),
207  $post2->getUid(),
208  $post2->_getProperty('_localizedUid'),
209  $post2->getBlog()->getTitle(),
210  $post2->getBlog()->getUid(),
211  $post2->getBlog()->_getProperty('_localizedUid'),
212  $post2->getAuthor()->getFirstname(),
213  $post2->getAuthor()->getUid(),
214  $post2->getAuthor()->_getProperty('_localizedUid')
215  ]);
216 
217  //this is needed because of https://forge.typo3.org/issues/59992
218  $this->persistenceManager->clearState();
219  $post2translated = $this->postRepository->findByUid(11);
220  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
221  $post2translated->getTitle(),
222  $post2translated->getUid(),
223  $post2translated->_getProperty('_localizedUid'),
224  $post2translated->getBlog()->getTitle(),
225  $post2translated->getBlog()->getUid(),
226  $post2translated->getBlog()->_getProperty('_localizedUid'),
227  $post2translated->getAuthor()->getFirstname(),
228  $post2translated->getAuthor()->getUid(),
229  $post2translated->getAuthor()->_getProperty('_localizedUid')
230  ]);
231  }
232 
238  public function ‪findByUidNoOverlaysLanguage()
239  {
240  $context = GeneralUtility::makeInstance(Context::class);
241  $context->setAspect('language', new LanguageAspect(1, 1, ‪LanguageAspect::OVERLAYS_OFF));
242 
243  $post2 = $this->postRepository->findByUid(2);
244  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
245  $post2->getTitle(),
246  $post2->getUid(),
247  $post2->_getProperty('_localizedUid'),
248  $post2->getBlog()->getTitle(),
249  $post2->getBlog()->getUid(),
250  $post2->getBlog()->_getProperty('_localizedUid'),
251  $post2->getAuthor()->getFirstname(),
252  $post2->getAuthor()->getUid(),
253  $post2->getAuthor()->_getProperty('_localizedUid')
254  ]);
255 
256  //this is needed because of https://forge.typo3.org/issues/59992
257  $this->persistenceManager->clearState();
258 
259  $post2translated = $this->postRepository->findByUid(11);
260  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
261  $post2translated->getTitle(),
262  $post2translated->getUid(),
263  $post2translated->_getProperty('_localizedUid'),
264  $post2translated->getBlog()->getTitle(),
265  $post2translated->getBlog()->getUid(),
266  $post2translated->getBlog()->_getProperty('_localizedUid'),
267  $post2translated->getAuthor()->getFirstname(),
268  $post2translated->getAuthor()->getUid(),
269  $post2translated->getAuthor()->_getProperty('_localizedUid')
270  ]);
271  }
272 
282  public function ‪customFindByUidOverlayEnabled()
283  {
284  // we're in default lang and fetching by uid of the record in default language
285  $query = $this->postRepository->createQuery();
286  $querySettings = $query->getQuerySettings();
287  $querySettings->setLanguageUid(0);
288  $querySettings->setLanguageOverlayMode(true);
289  $query->matching($query->equals('uid', 2));
290  $post2 = $query->execute()->getFirst();
291 
292  //the expected state is the same with and without feature flag
293  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
294  $post2->getTitle(),
295  $post2->getUid(),
296  $post2->_getProperty('_localizedUid'),
297  $post2->getBlog()->getTitle(),
298  $post2->getBlog()->getUid(),
299  $post2->getBlog()->_getProperty('_localizedUid'),
300  $post2->getAuthor()->getFirstname(),
301  $post2->getAuthor()->getUid(),
302  $post2->getAuthor()->_getProperty('_localizedUid')
303  ]);
304 
305  //this is needed because of https://forge.typo3.org/issues/59992
306  $this->persistenceManager->clearState();
307 
308  $query = $this->postRepository->createQuery();
309  $querySettings = $query->getQuerySettings();
310  $querySettings->setLanguageUid(0);
311  $querySettings->setLanguageOverlayMode(true);
312  $query->matching($query->equals('uid', 11));
313  $post2 = $query->execute()->getFirst();
314 
315  //this assertion is true for both enabled and disabled flag
316  $this->assertNull($post2);
317 
318  //this is needed because of https://forge.typo3.org/issues/59992
319  $this->persistenceManager->clearState();
320 
321  $query = $this->postRepository->createQuery();
322  $querySettings = $query->getQuerySettings();
323  $querySettings->setLanguageUid(1);
324  $querySettings->setLanguageOverlayMode(true);
325  $query->matching($query->equals('uid', 2));
326  $post2 = $query->execute()->getFirst();
327 
328  $this->assertNull($post2);
329 
330  //this is needed because of https://forge.typo3.org/issues/59992
331  $this->persistenceManager->clearState();
332 
333  $query = $this->postRepository->createQuery();
334  $querySettings = $query->getQuerySettings();
335  $querySettings->setLanguageUid(1);
336  $querySettings->setLanguageOverlayMode(true);
337  $query->matching($query->equals('uid', 11));
338  $post2 = $query->execute()->getFirst();
339 
340  $this->assertEquals(['Post 2 - DK', 2, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
341  $post2->getTitle(),
342  $post2->getUid(),
343  $post2->_getProperty('_localizedUid'),
344  $post2->getBlog()->getTitle(),
345  $post2->getBlog()->getUid(),
346  $post2->getBlog()->_getProperty('_localizedUid'),
347  $post2->getAuthor()->getFirstname(),
348  $post2->getAuthor()->getUid(),
349  $post2->getAuthor()->_getProperty('_localizedUid')
350  ]);
351  }
352 
362  public function ‪customFindByUidOverlayDisabled()
363  {
364  $query = $this->postRepository->createQuery();
365  $querySettings = $query->getQuerySettings();
366  $querySettings->setLanguageUid(0);
367  $querySettings->setLanguageOverlayMode(false);
368  $query->matching($query->equals('uid', 2));
369  $post2 = $query->execute()->getFirst();
370 
371  $this->assertEquals(['Post 2', 2, 2, 'Blog 1', 1, 1, 'John', 1, 1], [
372  $post2->getTitle(),
373  $post2->getUid(),
374  $post2->_getProperty('_localizedUid'),
375  $post2->getBlog()->getTitle(),
376  $post2->getBlog()->getUid(),
377  $post2->getBlog()->_getProperty('_localizedUid'),
378  $post2->getAuthor()->getFirstname(),
379  $post2->getAuthor()->getUid(),
380  $post2->getAuthor()->_getProperty('_localizedUid')
381  ]);
382 
383  //this is needed because of https://forge.typo3.org/issues/59992
384  $this->persistenceManager->clearState();
385 
386  $query = $this->postRepository->createQuery();
387  $querySettings = $query->getQuerySettings();
388  $querySettings->setLanguageUid(0);
389  $querySettings->setLanguageOverlayMode(false);
390  $query->matching($query->equals('uid', 11));
391  $post2 = $query->execute()->getFirst();
392 
393  //this assertion is true for both enabled and disabled flag
394  $this->assertNull($post2);
395 
396  //this is needed because of https://forge.typo3.org/issues/59992
397  $this->persistenceManager->clearState();
398 
399  $query = $this->postRepository->createQuery();
400  $querySettings = $query->getQuerySettings();
401  $querySettings->setLanguageUid(1);
402  $querySettings->setLanguageOverlayMode(false);
403  $query->matching($query->equals('uid', 2));
404  $post2 = $query->execute()->getFirst();
405 
406  $this->assertNull($post2);
407 
408  //this is needed because of https://forge.typo3.org/issues/59992
409  $this->persistenceManager->clearState();
410 
411  $query = $this->postRepository->createQuery();
412  $querySettings = $query->getQuerySettings();
413  $querySettings->setLanguageUid(1);
414  $querySettings->setLanguageOverlayMode(false);
415  $query->matching($query->equals('uid', 11));
416  $post2 = $query->execute()->getFirst();
417 
418  $this->assertEquals(['Post 2 - DK', 11, 11, 'Blog 1 DK', 1, 2, 'Translated John', 1, 2], [
419  $post2->getTitle(),
420  $post2->getUid(),
421  $post2->_getProperty('_localizedUid'),
422  $post2->getBlog()->getTitle(),
423  $post2->getBlog()->getUid(),
424  $post2->getBlog()->_getProperty('_localizedUid'),
425  $post2->getAuthor()->getFirstname(),
426  $post2->getAuthor()->getUid(),
427  $post2->getAuthor()->_getProperty('_localizedUid')
428  ]);
429  }
430 
431  public function ‪queryFirst5PostsDataProvider()
432  {
433  //put it to variable to make cases with the same expected values explicit
434  $lang0Expected = [
435  [
436  'title' => 'Post 4',
437  'uid' => 4,
438  '_localizedUid' => 4,
439  'content' => 'A - content',
440  'blog.title' => 'Blog 1',
441  'blog.uid' => 1,
442  'blog._localizedUid' => 1,
443  'author.firstname' => 'John',
444  'author.uid' => 1,
445  'author._localizedUid' => 1,
446  'secondAuthor.firstname' => 'John',
447  'secondAuthor.uid' => 1,
448  'secondAuthor._localizedUid' => 1,
449  'tags' => [],
450  ],
451  [
452  'title' => 'Post 2',
453  'uid' => 2,
454  '_localizedUid' => 2,
455  'content' => 'B - content',
456  'blog.title' => 'Blog 1',
457  'blog.uid' => 1,
458  'blog._localizedUid' => 1,
459  'author.firstname' => 'John',
460  'author.uid' => 1,
461  'author._localizedUid' => 1,
462  'secondAuthor.firstname' => 'John',
463  'secondAuthor.uid' => 1,
464  'secondAuthor._localizedUid' => 1,
465  'tags.0.name' => 'Tag2',
466  'tags.0.uid' => 2,
467  'tags.0._localizedUid' => 2,
468  'tags.1.name' => 'Tag3',
469  'tags.1.uid' => 3,
470  'tags.1._localizedUid' => 3,
471  'tags.2.name' => 'Tag4',
472  'tags.2.uid' => 4,
473  'tags.2._localizedUid' => 4,
474  ],
475  [
476  'title' => 'Post 7',
477  'uid' => 7,
478  '_localizedUid' => 7,
479  'content' => 'C - content',
480  'blog.title' => 'Blog 1',
481  'blog.uid' => 1,
482  'blog._localizedUid' => 1,
483  'author.firstname' => 'John',
484  'author.uid' => 1,
485  'author._localizedUid' => 1,
486  'secondAuthor.firstname' => 'John',
487  'secondAuthor.uid' => 1,
488  'secondAuthor._localizedUid' => 1,
489  'tags' => [],
490  ],
491  [
492  'title' => 'Post 6',
493  'uid' => 6,
494  '_localizedUid' => 6,
495  'content' => 'F - content',
496  'blog.title' => 'Blog 1',
497  'blog.uid' => 1,
498  'blog._localizedUid' => 1,
499  'author.firstname' => 'John',
500  'author.uid' => 1,
501  'author._localizedUid' => 1,
502  'secondAuthor.firstname' => 'John',
503  'secondAuthor.uid' => 1,
504  'secondAuthor._localizedUid' => 1,
505  'tags' => [],
506  ],
507  [
508  'title' => 'Post 1 - not translated',
509  'uid' => 1,
510  '_localizedUid' => 1,
511  'content' => 'G - content',
512  'blog.title' => 'Blog 1',
513  'blog.uid' => 1,
514  'blog._localizedUid' => 1,
515  'author.firstname' => 'John',
516  'author.uid' => 1,
517  'author._localizedUid' => 1,
518  'secondAuthor.firstname' => 'Never translate me henry',
519  'secondAuthor.uid' => 3,
520  'secondAuthor._localizedUid' => 3,
521  'tags.0.name' => 'Tag1',
522  'tags.0.uid' => 1,
523  'tags.0._localizedUid' => 1,
524  'tags.1.name' => 'Tag2',
525  'tags.1.uid' => 2,
526  'tags.1._localizedUid' => 2,
527  'tags.2.name' => 'Tag3',
528  'tags.2.uid' => 3,
529  'tags.2._localizedUid' => 3,
530  ],
531  ];
532  return [
533  [
534  'language' => 0,
535  'overlay' => true,
536  'expected' => $lang0Expected
537  ],
538  [
539  'language' => 0,
540  'overlay' => false,
541  'expected' => $lang0Expected
542  ],
543  [
544  'language' => 1,
545  'overlay' => true,
546  'expected' => [
547  [
548  'title' => 'Post 5 - DK',
549  'uid' => 5,
550  '_localizedUid' => 13,
551  'content' => 'A - content',
552  'blog.title' => 'Blog 1 DK',
553  'blog.uid' => 1,
554  'blog._localizedUid' => 2,
555  'author.firstname' => 'Translated John',
556  'author.uid' => 1,
557  'author._localizedUid' => 2,
558  'secondAuthor.firstname' => 'Translated John',
559  'secondAuthor.uid' => 1,
560  'secondAuthor._localizedUid' => 2,
561  'tags' => [],
562  ],
563  [
564  'title' => 'Post 2 - DK',
565  'uid' => 2,
566  '_localizedUid' => 11,
567  'content' => 'C - content',
568  'blog.title' => 'Blog 1 DK',
569  'blog.uid' => 1,
570  'blog._localizedUid' => 2,
571  'author.firstname' => 'Translated John',
572  'author.uid' => 1,
573  'author._localizedUid' => 2,
574  'secondAuthor.firstname' => 'Translated John',
575  'secondAuthor.uid' => 1,
576  'secondAuthor._localizedUid' => 2,
577  'tags.0.name' => 'Tag 3 DK',
578  'tags.0.uid' => 3,
579  'tags.0._localizedUid' => 18,
580  'tags.1.name' => 'Tag4',
581  'tags.1.uid' => 4,
582  'tags.1._localizedUid' => 4,
583  'tags.2.name' => 'Tag5',
584  'tags.2.uid' => 5,
585  'tags.2._localizedUid' => 5,
586  'tags.3.name' => 'Tag 6 DK',
587  'tags.3.uid' => 6,
588  'tags.3._localizedUid' => 19,
589  'tags.4.name' => 'Tag7',
590  'tags.4.uid' => 7,
591  'tags.4._localizedUid' => 7,
592  ],
593  [
594  'title' => 'Post 6',
595  'uid' => 6,
596  '_localizedUid' => 6,
597  'content' => 'F - content',
598  'blog.title' => 'Blog 1 DK',
599  'blog.uid' => 1,
600  'blog._localizedUid' => 2,
601  'author.firstname' => 'Translated John',
602  'author.uid' => 1,
603  'author._localizedUid' => 2,
604  'secondAuthor.firstname' => 'Translated John',
605  'secondAuthor.uid' => 1,
606  'secondAuthor._localizedUid' => 2,
607  'tags' => [],
608  ],
609  [
610  'title' => 'Post 1 - not translated',
611  'uid' => 1,
612  '_localizedUid' => 1,
613  'content' => 'G - content',
614  'blog.title' => 'Blog 1 DK',
615  'blog.uid' => 1,
616  'blog._localizedUid' => 2,
617  'author.firstname' => 'Translated John',
618  'author.uid' => 1,
619  'author._localizedUid' => 2,
620  'secondAuthor.firstname' => 'Never translate me henry',
621  'secondAuthor.uid' => 3,
622  'secondAuthor._localizedUid' => 3,
623  'tags.0.name' => 'Tag 1 DK',
624  'tags.0.uid' => 1,
625  'tags.0._localizedUid' => 16,
626  'tags.1.name' => 'Tag 2 DK',
627  'tags.1.uid' => 2,
628  'tags.1._localizedUid' => 17,
629  'tags.2.name' => 'Tag 3 DK',
630  'tags.2.uid' => 3,
631  'tags.2._localizedUid' => 18,
632 
633  ],
634  [
635  'title' => 'Post 3',
636  'uid' => 3,
637  '_localizedUid' => 3,
638  'content' => 'I - content',
639  'blog.title' => 'Blog 1 DK',
640  'blog.uid' => 1,
641  'blog._localizedUid' => 2,
642  'author.firstname' => 'Translated John',
643  'author.uid' => 1,
644  'author._localizedUid' => 2,
645  'secondAuthor.firstname' => 'Translated John',
646  'secondAuthor.uid' => 1,
647  'secondAuthor._localizedUid' => 2,
648  'tags' => [],
649  ],
650  ],
651  ],
652  [
653  'language' => 1,
654  'overlay' => 'hideNonTranslated',
655  // here we have only 4 items instead of 5 as post "Post DK only" uid:15 has no language 0 parent,
656  // so with overlay enabled it's not shown
657  'expected' => [
658  [
659  'title' => 'Post 5 - DK',
660  'uid' => 5,
661  '_localizedUid' => 13,
662  'content' => 'A - content',
663  'blog.title' => 'Blog 1 DK',
664  'blog.uid' => 1,
665  'blog._localizedUid' => 2,
666  'author.firstname' => 'Translated John',
667  'author.uid' => 1,
668  'author._localizedUid' => 2,
669  'secondAuthor.firstname' => 'Translated John',
670  'secondAuthor.uid' => 1,
671  'secondAuthor._localizedUid' => 2,
672  'tags' => [],
673  ],
674  [
675  'title' => 'Post 2 - DK',
676  'uid' => 2,
677  '_localizedUid' => 11,
678  'content' => 'C - content',
679  'blog.title' => 'Blog 1 DK',
680  'blog.uid' => 1,
681  'blog._localizedUid' => 2,
682  'author.firstname' => 'Translated John',
683  'author.uid' => 1,
684  'author._localizedUid' => 2,
685  'secondAuthor.firstname' => 'Translated John',
686  'secondAuthor.uid' => 1,
687  'secondAuthor._localizedUid' => 2,
688  'tags.0.name' => 'Tag 3 DK',
689  'tags.0.uid' => 3,
690  'tags.0._localizedUid' => 18,
691  'tags.1.name' => 'Tag4',
692  'tags.1.uid' => 4,
693  'tags.1._localizedUid' => 4,
694  'tags.2.name' => 'Tag5',
695  'tags.2.uid' => 5,
696  'tags.2._localizedUid' => 5,
697  'tags.3.name' => 'Tag 6 DK',
698  'tags.3.uid' => 6,
699  'tags.3._localizedUid' => 19,
700  'tags.4.name' => 'Tag7',
701  'tags.4.uid' => 7,
702  'tags.4._localizedUid' => 7,
703  ],
704  [
705  'title' => 'Post 7 - DK',
706  'uid' => 7,
707  '_localizedUid' => 14,
708  'content' => 'S - content',
709  'blog.title' => 'Blog 1 DK',
710  'blog.uid' => 1,
711  'blog._localizedUid' => 2,
712  'author.firstname' => 'Translated John',
713  'author.uid' => 1,
714  'author._localizedUid' => 2,
715  'secondAuthor.firstname' => 'Translated John',
716  'secondAuthor.uid' => 1,
717  'secondAuthor._localizedUid' => 2,
718  'tags' => [],
719  ],
720  [
721  'title' => 'Post 4 - DK',
722  'uid' => 4,
723  '_localizedUid' => 12,
724  'content' => 'U - content',
725  'blog.title' => 'Blog 1 DK',
726  'blog.uid' => 1,
727  'blog._localizedUid' => 2,
728  'author.firstname' => 'Translated John',
729  'author.uid' => 1,
730  'author._localizedUid' => 2,
731  'secondAuthor.firstname' => 'Translated John',
732  'secondAuthor.uid' => 1,
733  'secondAuthor._localizedUid' => 2,
734  'tags' => [],
735  ],
736  ],
737  ],
738  [
739  'language' => 1,
740  'overlay' => false,
741  'expected' => [
742  [
743  'title' => 'Post 5 - DK',
744  'uid' => 13,
745  '_localizedUid' => 13,
746  'content' => 'A - content',
747  'blog.title' => 'Blog 1 DK',
748  'blog.uid' => 1,
749  'blog._localizedUid' => 2,
750  'author.firstname' => 'Translated John',
751  'author.uid' => 1,
752  'author._localizedUid' => 2,
753  'secondAuthor.firstname' => 'Translated John',
754  'secondAuthor.uid' => 1,
755  'secondAuthor._localizedUid' => 2,
756  'tags' => [],
757  ],
758  [
759  'title' => 'Post DK only',
760  'uid' => 15,
761  '_localizedUid' => 15,
762  'content' => 'B - content',
763  'blog.title' => 'Blog 1 DK',
764  'blog.uid' => 1,
765  'blog._localizedUid' => 2,
766  'author.firstname' => 'Translated John',
767  'author.uid' => 1,
768  'author._localizedUid' => 2,
769  'secondAuthor.firstname' => 'Translated John',
770  'secondAuthor.uid' => 1,
771  'secondAuthor._localizedUid' => 2,
772  'tags' => [],
773  ],
774  [
775  'title' => 'Post 2 - DK',
776  'uid' => 11,
777  '_localizedUid' => 11,
778  'content' => 'C - content',
779  'blog.title' => 'Blog 1 DK',
780  'blog.uid' => 1,
781  'blog._localizedUid' => 2,
782  'author.firstname' => 'Translated John',
783  'author.uid' => 1,
784  'author._localizedUid' => 2,
785  'secondAuthor.firstname' => 'Translated John',
786  'secondAuthor.uid' => 1,
787  'secondAuthor._localizedUid' => 2,
788  'tags.0.name' => 'Tag 3 DK',
789  'tags.0.uid' => 3,
790  'tags.0._localizedUid' => 18,
791  'tags.1.name' => 'Tag4',
792  'tags.1.uid' => 4,
793  'tags.1._localizedUid' => 4,
794  'tags.2.name' => 'Tag5',
795  'tags.2.uid' => 5,
796  'tags.2._localizedUid' => 5,
797  'tags.3.name' => 'Tag 6 DK',
798  'tags.3.uid' => 6,
799  'tags.3._localizedUid' => 19,
800  'tags.4.name' => 'Tag7',
801  'tags.4.uid' => 7,
802  'tags.4._localizedUid' => 7,
803  ],
804  [
805  'title' => 'Post 7 - DK',
806  'uid' => 14,
807  '_localizedUid' => 14,
808  'content' => 'S - content',
809  'blog.title' => 'Blog 1 DK',
810  'blog.uid' => 1,
811  'blog._localizedUid' => 2,
812  'author.firstname' => 'Translated John',
813  'author.uid' => 1,
814  'author._localizedUid' => 2,
815  'secondAuthor.firstname' => 'Translated John',
816  'secondAuthor.uid' => 1,
817  'secondAuthor._localizedUid' => 2,
818  'tags' => [],
819  ],
820  [
821  'title' => 'Post 4 - DK',
822  'uid' => 12,
823  '_localizedUid' => 12,
824  'content' => 'U - content',
825  'blog.title' => 'Blog 1 DK',
826  'blog.uid' => 1,
827  'blog._localizedUid' => 2,
828  'author.firstname' => 'Translated John',
829  'author.uid' => 1,
830  'author._localizedUid' => 2,
831  'secondAuthor.firstname' => 'Translated John',
832  'secondAuthor.uid' => 1,
833  'secondAuthor._localizedUid' => 2,
834  'tags' => [],
835  ],
836  ],
837  ],
838  ];
839  }
840 
853  public function ‪queryFirst5Posts($languageUid, $overlay, $expected)
854  {
855  $query = $this->postRepository->createQuery();
856  $querySettings = $query->getQuerySettings();
857  $querySettings->setLanguageUid($languageUid);
858  $querySettings->setLanguageOverlayMode($overlay);
859 
860  $query->setOrderings([
863  ]);
864  $query->setLimit(5);
865  $query->setOffset(0);
866  $posts = $query->execute()->toArray();
867 
868  $this->assertCount(count($expected), $posts);
869  $this->‪assertObjectsProperties($posts, $expected);
870  }
871 
872  public function ‪queryPostsByPropertyDataProvider()
873  {
874  $lang0Expected = [
875  [
876  'title' => 'Post 5',
877  'uid' => 5,
878  '_localizedUid' => 5,
879  'content' => 'Z - content',
880  'blog.title' => 'Blog 1',
881  'blog.uid' => 1,
882  'blog._localizedUid' => 1,
883  'author.firstname' => 'John',
884  'author.uid' => 1,
885  'author._localizedUid' => 1,
886  'secondAuthor.firstname' => 'John',
887  'secondAuthor.uid' => 1,
888  'secondAuthor._localizedUid' => 1,
889  ],
890  [
891  'title' => 'Post 6',
892  'uid' => 6,
893  '_localizedUid' => 6,
894  'content' => 'F - content',
895  'blog.title' => 'Blog 1',
896  'blog.uid' => 1,
897  'blog._localizedUid' => 1,
898  'author.firstname' => 'John',
899  'author.uid' => 1,
900  'author._localizedUid' => 1,
901  'secondAuthor.firstname' => 'John',
902  'secondAuthor.uid' => 1,
903  'secondAuthor._localizedUid' => 1,
904  'tags' => [],
905  ]
906  ];
907 
908  return [
909  [
910  'language' => 0,
911  'overlay' => true,
912  'expected' => $lang0Expected
913  ],
914  [
915  'language' => 0,
916  'overlay' => 'hideNonTranslated',
917  'expected' => $lang0Expected
918  ],
919  [
920  'language' => 0,
921  'overlay' => false,
922  'expected' => $lang0Expected
923  ],
924  [
925  'language' => 1,
926  'overlay' => true,
927  'expected' => [
928  [
929  'title' => 'Post 6',
930  'uid' => 6,
931  '_localizedUid' => 6,
932  'content' => 'F - content',
933  'blog.title' => 'Blog 1 DK',
934  'blog.uid' => 1,
935  'blog._localizedUid' => 2,
936  'author.firstname' => 'Translated John',
937  'author.uid' => 1,
938  'author._localizedUid' => 2,
939  'secondAuthor.firstname' => 'Translated John',
940  'secondAuthor.uid' => 1,
941  'secondAuthor._localizedUid' => 2,
942  ],
943  [
944  'title' => 'Post 5 - DK',
945  'uid' => 5,
946  '_localizedUid' => 13,
947  'content' => 'A - content',
948  'blog.title' => 'Blog 1 DK',
949  'blog.uid' => 1,
950  'blog._localizedUid' => 2,
951  'author.firstname' => 'Translated John',
952  'author.uid' => 1,
953  'author._localizedUid' => 2,
954  'secondAuthor.firstname' => 'Translated John',
955  'secondAuthor.uid' => 1,
956  'secondAuthor._localizedUid' => 2,
957  ],
958  ],
959  ],
960  [
961  'language' => 1,
962  'overlay' => 'hideNonTranslated',
963  'expected' => [
964  [
965  'title' => 'Post 5 - DK',
966  'uid' => 5,
967  '_localizedUid' => 13,
968  'content' => 'A - content',
969  'blog.title' => 'Blog 1 DK',
970  'blog.uid' => 1,
971  'blog._localizedUid' => 2,
972  'author.firstname' => 'Translated John',
973  'author.uid' => 1,
974  'author._localizedUid' => 2,
975  'secondAuthor.firstname' => 'Translated John',
976  'secondAuthor.uid' => 1,
977  'secondAuthor._localizedUid' => 2,
978  ],
979  ],
980  ],
981  [
982  'language' => 1,
983  'overlay' => false,
984  'expected' => [
985  [
986  'title' => 'Post 5 - DK',
987  'uid' => 13,
988  '_localizedUid' => 13,
989  'content' => 'A - content',
990  'blog.title' => 'Blog 1 DK',
991  'blog.uid' => 1,
992  'blog._localizedUid' => 2,
993  'author.firstname' => 'Translated John',
994  'author.uid' => 1,
995  'author._localizedUid' => 2,
996  'secondAuthor.firstname' => 'Translated John',
997  'secondAuthor.uid' => 1,
998  'secondAuthor._localizedUid' => 2,
999  ],
1000  [
1001  'title' => 'Post DK only',
1002  'uid' => 15,
1003  '_localizedUid' => 15,
1004  'content' => 'B - content',
1005  'blog.title' => 'Blog 1 DK',
1006  'blog.uid' => 1,
1007  'blog._localizedUid' => 2,
1008  'author.firstname' => 'Translated John',
1009  'author.uid' => 1,
1010  'author._localizedUid' => 2,
1011  'secondAuthor.firstname' => 'Translated John',
1012  'secondAuthor.uid' => 1,
1013  'secondAuthor._localizedUid' => 2,
1014  ],
1015  ],
1016  ],
1017  ];
1018  }
1019 
1034  public function ‪queryPostsByProperty($languageUid, $overlay, $expected)
1035  {
1036  $query = $this->postRepository->createQuery();
1037  $querySettings = $query->getQuerySettings();
1038  $querySettings->setLanguageUid($languageUid);
1039  $querySettings->setLanguageOverlayMode($overlay);
1040 
1041  $query->matching(
1042  $query->logicalOr(
1043  $query->like('title', 'Post 5%'),
1044  $query->like('title', 'Post 6%'),
1045  $query->like('title', 'Post DK only')
1046  )
1047  );
1048  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
1049  $posts = $query->execute()->toArray();
1051  $this->assertCount(count($expected), $posts);
1052  $this->‪assertObjectsProperties($posts, $expected);
1053  }
1054 
1056  {
1057  $lang0Expected = [
1058  [
1059  'title' => 'Blog 1',
1060  'uid' => 1,
1061  '_localizedUid' => 1,
1062  ],
1063  [
1064  'title' => 'Blog 1',
1065  'uid' => 1,
1066  '_localizedUid' => 1,
1067  ],
1068  ];
1069  $mixed = [
1070  [
1071  'title' => 'Blog 1',
1072  'uid' => 1,
1073  '_localizedUid' => 1,
1074  ],
1075  [
1076  'title' => 'Blog 1 DK',
1077  'uid' => 2,
1078  '_localizedUid' => 2,
1079  ],
1080  ];
1081  return [
1082  [
1083  'language' => 0,
1084  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1085  'mode' => null,
1086  'expected' => $lang0Expected
1087  ],
1088  [
1089  'language' => 0,
1090  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1091  'mode' => 'strict',
1092  'expected' => $lang0Expected
1093  ],
1094  [
1095  'language' => 0,
1096  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1097  'mode' => null,
1098  'expected' => $mixed
1099  ],
1100  [
1101  'language' => 0,
1102  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1103  'mode' => 'strict',
1104  'expected' => $mixed
1105  ],
1106  [
1107  'language' => 1,
1108  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1109  'mode' => null,
1110  'expected' => [
1111  [
1112  'title' => 'Blog 1 DK',
1113  'uid' => 1,
1114  '_localizedUid' => 2,
1115  ],
1116  [
1117  'title' => 'Blog 1 DK',
1118  'uid' => 1,
1119  '_localizedUid' => 2,
1120  ],
1121  ]
1122  ],
1123  [
1124  'language' => 1,
1125  'overlay' => ‪LanguageAspect::OVERLAYS_ON,
1126  'mode' => 'strict',
1127  'expected' => [
1128  [
1129  'title' => 'Blog 1 DK',
1130  'uid' => 1,
1131  '_localizedUid' => 2,
1132  ],
1133  [
1134  'title' => 'Blog 1 DK',
1135  'uid' => 1,
1136  '_localizedUid' => 2,
1137  ],
1138  ]
1139  ],
1140  [
1141  'language' => 1,
1142  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1143  'mode' => null,
1144  'expected' => $mixed
1145  ],
1146  [
1147  'language' => 1,
1148  'overlay' => ‪LanguageAspect::OVERLAYS_OFF,
1149  'mode' => 'strict',
1150  'expected' => $mixed
1151  ],
1152  ];
1153  }
1154 
1170  public function ‪postsWithoutRespectingSysLanguage($languageUid, $overlay, $languageMode, $expected)
1171  {
1172  $context = GeneralUtility::makeInstance(Context::class);
1173  $context->setAspect('language', new LanguageAspect($languageUid, $languageUid, $overlay));
1174 
1175  $blogRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
1176  $query = $blogRepository->createQuery();
1177  $querySettings = $query->getQuerySettings();
1178  $querySettings->setLanguageMode($languageMode);
1179  $querySettings->setRespectSysLanguage(false);
1180  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_ASCENDING]);
1181 
1182  $posts = $query->execute()->toArray();
1183 
1184  $this->assertCount(count($expected), $posts);
1185  $this->‪assertObjectsProperties($posts, $expected);
1186  }
1187 
1194  protected function ‪assertObjectsProperties($objects, $expected)
1195  {
1196  $actual = [];
1197  foreach ($objects as $key => $post) {
1198  $actualPost = [];
1199  $propertiesToCheck = array_keys($expected[$key]);
1200  foreach ($propertiesToCheck as $propertyPath) {
1201  $actualPost[$propertyPath] = ‪self::getPropertyPath($post, $propertyPath);
1202  }
1203  $actual[] = $actualPost;
1204  $this->assertEquals($expected[$key], $actual[$key], 'Assertion of the $expected[' . $key . '] failed');
1205  }
1206  $this->assertEquals($expected, $actual);
1207  }
1208 
1218  protected static function ‪getPropertyPath($subject, $propertyPath)
1219  {
1220  $propertyPathSegments = explode('.', $propertyPath);
1221  try {
1222  foreach ($propertyPathSegments as $pathSegment) {
1223  $subject = ‪ObjectAccess::getPropertyInternal($subject, $pathSegment, true);
1224  if ($subject instanceof \SplObjectStorage || $subject instanceof ObjectStorage) {
1225  $subject = iterator_to_array(clone $subject, false);
1226  }
1227  }
1228  } catch (\‪TYPO3\CMS\‪Extbase\Reflection\Exception\PropertyNotAccessibleException $error) {
1229  return null;
1230  }
1231  return $subject;
1232  }
1233 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\postsWithoutRespectingSysLanguageDataProvider
‪postsWithoutRespectingSysLanguageDataProvider()
Definition: QueryLocalizedDataTest.php:1050
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest
Definition: QueryLocalizedDataTest.php:30
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\customFindByUidOverlayDisabled
‪customFindByUidOverlayDisabled()
Definition: QueryLocalizedDataTest.php:357
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\setUpBasicFrontendEnvironment
‪setUpBasicFrontendEnvironment()
Definition: QueryLocalizedDataTest.php:82
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:26
‪TYPO3
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_ON
‪const OVERLAYS_ON
Definition: LanguageAspect.php:74
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\getPropertyPath
‪static mixed getPropertyPath($subject, $propertyPath)
Definition: QueryLocalizedDataTest.php:1213
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\findByUidNoOverlaysDefaultLanguage
‪findByUidNoOverlaysDefaultLanguage()
Definition: QueryLocalizedDataTest.php:154
‪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\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:95
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\$persistenceManager
‪$persistenceManager
Definition: QueryLocalizedDataTest.php:49
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\setUp
‪setUp()
Definition: QueryLocalizedDataTest.php:54
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\queryPostsByProperty
‪queryPostsByProperty($languageUid, $overlay, $expected)
Definition: QueryLocalizedDataTest.php:1029
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\findByUidNoOverlaysLanguage
‪findByUidNoOverlaysLanguage()
Definition: QueryLocalizedDataTest.php:233
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\postsWithoutRespectingSysLanguage
‪postsWithoutRespectingSysLanguage($languageUid, $overlay, $languageMode, $expected)
Definition: QueryLocalizedDataTest.php:1165
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyInternal
‪static mixed getPropertyInternal($subject, $propertyName, $forceDirectAccess=false)
Definition: ObjectAccess.php:80
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\findByUidOverlayModeOnDefaultLanguage
‪findByUidOverlayModeOnDefaultLanguage()
Definition: QueryLocalizedDataTest.php:112
‪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\QueryLocalizedDataTest\queryFirst5Posts
‪queryFirst5Posts($languageUid, $overlay, $expected)
Definition: QueryLocalizedDataTest.php:848
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\customFindByUidOverlayEnabled
‪customFindByUidOverlayEnabled()
Definition: QueryLocalizedDataTest.php:277
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: QueryLocalizedDataTest.php:33
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\queryFirst5PostsDataProvider
‪queryFirst5PostsDataProvider()
Definition: QueryLocalizedDataTest.php:426
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:72
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\PersistenceManager
‪PersistenceManager
Definition: QueryLocalizedDataTest.php:49
‪ExtbaseTeam
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\queryPostsByPropertyDataProvider
‪queryPostsByPropertyDataProvider()
Definition: QueryLocalizedDataTest.php:867
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: QueryLocalizedDataTest.php:37
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\findByUidOverlayModeOnLanguage
‪findByUidOverlayModeOnLanguage()
Definition: QueryLocalizedDataTest.php:194
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\$postRepository
‪TYPO3 CMS Extbase Persistence Repository $postRepository
Definition: QueryLocalizedDataTest.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\assertObjectsProperties
‪assertObjectsProperties($objects, $expected)
Definition: QueryLocalizedDataTest.php:1189
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\QueryLocalizedDataTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: QueryLocalizedDataTest.php:41