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