TYPO3 CMS  TYPO3_8-7
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 
22 class TranslationTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
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  * Post10 [hidden]
60  * -> GR: Post10 [hidden]
61  */
62  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
63  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
64  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translated-posts.xml');
65 
67 
68  $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
69  $this->postRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
70  }
71 
75  protected function setUpBasicFrontendEnvironment()
76  {
77  $environmentServiceMock = $this->createMock(\TYPO3\CMS\Extbase\Service\EnvironmentService::class);
78  $environmentServiceMock
79  ->expects($this->atLeast(1))
80  ->method('isEnvironmentInFrontendMode')
81  ->willReturn(true);
82  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Service\EnvironmentService::class, $environmentServiceMock);
83 
84  $pageRepositoryFixture = new PageRepository();
85  $frontendControllerMock = $this->createMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
86  $frontendControllerMock->sys_page = $pageRepositoryFixture;
87  $GLOBALS['TSFE'] = $frontendControllerMock;
88  }
89 
94  {
95  $query = $this->postRepository->createQuery();
96 
97  $querySettings = $query->getQuerySettings();
98  $querySettings->setStoragePageIds([1]);
99  $querySettings->setRespectSysLanguage(true);
100  $querySettings->setLanguageUid(0);
101 
102  $postCount = $query->execute()->count();
103  $this->assertSame(3, $postCount);
104  }
105 
110  {
111  $query = $this->postRepository->createQuery();
112 
113  $querySettings = $query->getQuerySettings();
114  $querySettings->setStoragePageIds([1]);
115  $querySettings->setRespectSysLanguage(true);
116  $querySettings->setLanguageUid(1);
117  $querySettings->setLanguageMode('strict');
118 
119  $postCount = $query->execute()->count();
120  $this->assertSame(2, $postCount);
121  }
122 
127  {
128  $query = $this->postRepository->createQuery();
129 
130  $querySettings = $query->getQuerySettings();
131  $querySettings->setStoragePageIds([1]);
132  $querySettings->setRespectSysLanguage(true);
133  $querySettings->setLanguageUid(1);
134 
135  $postCount = $query->execute()->count();
136  $this->assertSame(3, $postCount);
137  }
138 
143  {
144  $query = $this->postRepository->createQuery();
145 
146  $querySettings = $query->getQuerySettings();
147  $querySettings->setStoragePageIds([1]);
148  $querySettings->setRespectSysLanguage(true);
149  $querySettings->setLanguageUid(2);
150  $postCount = $query->execute()->count();
151 
152  $this->assertSame(3, $postCount);
153  }
154 
158  public function fetchingPostsReturnsEnglishPostsWithFallback()
159  {
160  $query = $this->postRepository->createQuery();
161 
162  $querySettings = $query->getQuerySettings();
163  $querySettings->setStoragePageIds([1]);
164  $querySettings->setRespectSysLanguage(true);
165  $querySettings->setLanguageUid(1);
166 
167  $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
168 
170  $posts = $query->execute()->toArray();
171 
172  $this->assertCount(3, $posts);
173  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
174  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
175  $this->assertSame('Post3', $posts[2]->getTitle());
176  }
177 
181  public function fetchingPostsReturnsGreekPostsWithFallback()
182  {
183  $query = $this->postRepository->createQuery();
184 
185  $querySettings = $query->getQuerySettings();
186  $querySettings->setStoragePageIds([1]);
187  $querySettings->setRespectSysLanguage(true);
188  $querySettings->setLanguageUid(2);
189 
190  $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
191 
193  $posts = $query->execute()->toArray();
194 
195  $this->assertCount(3, $posts);
196  $this->assertSame('GR:Post1', $posts[0]->getTitle());
197  $this->assertSame('Post2', $posts[1]->getTitle());
198  $this->assertSame('Post3', $posts[2]->getTitle());
199  }
200 
204  public function orderingByTitleRespectsEnglishTitles()
205  {
206  $query = $this->postRepository->createQuery();
207 
208  $querySettings = $query->getQuerySettings();
209  $querySettings->setStoragePageIds([1]);
210  $querySettings->setRespectSysLanguage(true);
211  $querySettings->setLanguageUid(1);
212 
213  $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
214 
216  $posts = $query->execute()->toArray();
217 
218  $this->assertCount(3, $posts);
219  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
220  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
221  $this->assertSame('Post3', $posts[2]->getTitle());
222  }
223 
231  public function fetchingHiddenPostsWithIgnoreEnableField()
232  {
233  $query = $this->postRepository->createQuery();
234 
235  $querySettings = $query->getQuerySettings();
236  $querySettings->setStoragePageIds([1]);
237  $querySettings->setRespectSysLanguage(true);
238  $querySettings->setIgnoreEnableFields(true);
239  $querySettings->setLanguageUid(0);
240  //we need it to have stable results on pgsql
241  $query->setOrderings(['uid' => QueryInterface::ORDER_ASCENDING]);
242 
244  $posts = $query->execute()->toArray();
245 
246  $this->assertCount(4, $posts);
247  $this->assertSame('Post10', $posts[3]->getTitle());
248  }
249 
259  public function fetchingHiddenPostsReturnsHiddenOverlay()
260  {
261  $query = $this->postRepository->createQuery();
262 
263  $querySettings = $query->getQuerySettings();
264  $querySettings->setStoragePageIds([1]);
265  $querySettings->setRespectSysLanguage(true);
266  $querySettings->setIgnoreEnableFields(true);
267  $querySettings->setLanguageUid(2);
268  //we need it to have stable results on pgsql
269  $query->setOrderings(['uid' => QueryInterface::ORDER_ASCENDING]);
270 
272  $posts = $query->execute()->toArray();
273 
274  $this->assertCount(4, $posts);
275  //This assertion is wrong, once the issue https://forge.typo3.org/issues/68672
276  //is fixed, the following assertion should be used.
277  $this->assertSame('Post10', $posts[3]->getTitle());
278  //$this->assertSame('GR:Post10', $posts[3]->getTitle());
279  }
280 }
static setSingletonInstance($className, SingletonInterface $instance)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']