TYPO3 CMS  TYPO3_7-6
TranslationTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
23 {
27  protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
28 
32  protected $coreExtensionsToLoad = ['extbase', 'fluid'];
33 
37  protected $objectManager;
38 
42  protected $postRepository;
43 
47  protected function setUp()
48  {
49  parent::setUp();
50  /*
51  * Posts Dataset for the tests:
52  *
53  * Post1
54  * -> EN: Post1
55  * -> GR: Post1
56  * Post2
57  * -> EN: Post2
58  * Post3
59  */
60  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
61  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
62  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translated-posts.xml');
63 
64  $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
65  $this->postRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
66 
68  }
69 
73  protected function setUpBasicFrontendEnvironment()
74  {
75  $environmentServiceMock = $this->getMock(\TYPO3\CMS\Extbase\Service\EnvironmentService::class);
76  $environmentServiceMock
77  ->expects($this->any())
78  ->method('isEnvironmentInFrontendMode')
79  ->willReturn(true);
80  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Service\EnvironmentService::class, $environmentServiceMock);
81 
82  $pageRepositoryFixture = new PageRepository();
83  $frontendControllerMock = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, [], [], '', false);
84  $frontendControllerMock->sys_page = $pageRepositoryFixture;
85  $GLOBALS['TSFE'] = $frontendControllerMock;
86  }
87 
92  {
93  $query = $this->postRepository->createQuery();
94 
95  $querySettings = $query->getQuerySettings();
96  $querySettings->setStoragePageIds([1]);
97  $querySettings->setRespectSysLanguage(true);
98  $querySettings->setLanguageUid(0);
99 
100  $postCount = $query->execute()->count();
101  $this->assertSame(3, $postCount);
102  }
103 
108  {
109  $query = $this->postRepository->createQuery();
110 
111  $querySettings = $query->getQuerySettings();
112  $querySettings->setStoragePageIds([1]);
113  $querySettings->setRespectSysLanguage(true);
114  $querySettings->setLanguageUid(1);
115 
116  $postCount = $query->execute()->count();
117  $this->assertSame(3, $postCount);
118  }
119 
124  {
125  $query = $this->postRepository->createQuery();
126 
127  $querySettings = $query->getQuerySettings();
128  $querySettings->setStoragePageIds([1]);
129  $querySettings->setRespectSysLanguage(true);
130  $querySettings->setLanguageUid(2);
131  $postCount = $query->execute()->count();
132 
133  $this->assertSame(3, $postCount);
134  }
135 
139  public function fetchingPostsReturnsEnglishPostsWithFallback()
140  {
141  $query = $this->postRepository->createQuery();
142 
143  $querySettings = $query->getQuerySettings();
144  $querySettings->setStoragePageIds([1]);
145  $querySettings->setRespectSysLanguage(true);
146  $querySettings->setLanguageUid(1);
147 
149  $posts = $query->execute()->toArray();
150 
151  $this->assertCount(3, $posts);
152  $this->assertSame('B EN:Post1', $posts[0]->getTitle());
153  $this->assertSame('A EN:Post2', $posts[1]->getTitle());
154  $this->assertSame('Post3', $posts[2]->getTitle());
155  }
156 
160  public function fetchingPostsReturnsGreekPostsWithFallback()
161  {
162  $query = $this->postRepository->createQuery();
163 
164  $querySettings = $query->getQuerySettings();
165  $querySettings->setStoragePageIds([1]);
166  $querySettings->setRespectSysLanguage(true);
167  $querySettings->setLanguageUid(2);
168 
170  $posts = $query->execute()->toArray();
171 
172  $this->assertCount(3, $posts);
173  $this->assertSame('GR:Post1', $posts[0]->getTitle());
174  $this->assertSame('Post2', $posts[1]->getTitle());
175  $this->assertSame('Post3', $posts[2]->getTitle());
176  }
177 
181  public function orderingByTitleRespectsEnglishTitles()
182  {
183  $query = $this->postRepository->createQuery();
184 
185  $querySettings = $query->getQuerySettings();
186  $querySettings->setStoragePageIds([1]);
187  $querySettings->setRespectSysLanguage(true);
188  $querySettings->setLanguageUid(1);
189 
190  $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
191 
193  $posts = $query->execute()->toArray();
194 
195  $this->assertCount(3, $posts);
196  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
197  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
198  $this->assertSame('Post3', $posts[2]->getTitle());
199  }
200 }
static setSingletonInstance($className, SingletonInterface $instance)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']