TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
TranslationTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
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->createMock(\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->createMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
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  $querySettings->setLanguageMode('strict');
116 
117  $postCount = $query->execute()->count();
118  $this->assertSame(2, $postCount);
119  }
120 
125  {
126  $query = $this->postRepository->createQuery();
127 
128  $querySettings = $query->getQuerySettings();
129  $querySettings->setStoragePageIds([1]);
130  $querySettings->setRespectSysLanguage(true);
131  $querySettings->setLanguageUid(1);
132 
133  $postCount = $query->execute()->count();
134  $this->assertSame(3, $postCount);
135  }
136 
141  {
142  $query = $this->postRepository->createQuery();
143 
144  $querySettings = $query->getQuerySettings();
145  $querySettings->setStoragePageIds([1]);
146  $querySettings->setRespectSysLanguage(true);
147  $querySettings->setLanguageUid(2);
148  $postCount = $query->execute()->count();
149 
150  $this->assertSame(3, $postCount);
151  }
152 
156  public function fetchingPostsReturnsEnglishPostsWithFallback()
157  {
158  $query = $this->postRepository->createQuery();
159 
160  $querySettings = $query->getQuerySettings();
161  $querySettings->setStoragePageIds([1]);
162  $querySettings->setRespectSysLanguage(true);
163  $querySettings->setLanguageUid(1);
164 
166  $posts = $query->execute()->toArray();
167 
168  $this->assertCount(3, $posts);
169  $this->assertSame('B EN:Post1', $posts[0]->getTitle());
170  $this->assertSame('A EN:Post2', $posts[1]->getTitle());
171  $this->assertSame('Post3', $posts[2]->getTitle());
172  }
173 
177  public function fetchingPostsReturnsGreekPostsWithFallback()
178  {
179  $query = $this->postRepository->createQuery();
180 
181  $querySettings = $query->getQuerySettings();
182  $querySettings->setStoragePageIds([1]);
183  $querySettings->setRespectSysLanguage(true);
184  $querySettings->setLanguageUid(2);
185 
187  $posts = $query->execute()->toArray();
188 
189  $this->assertCount(3, $posts);
190  $this->assertSame('GR:Post1', $posts[0]->getTitle());
191  $this->assertSame('Post2', $posts[1]->getTitle());
192  $this->assertSame('Post3', $posts[2]->getTitle());
193  }
194 
198  public function orderingByTitleRespectsEnglishTitles()
199  {
200  $query = $this->postRepository->createQuery();
201 
202  $querySettings = $query->getQuerySettings();
203  $querySettings->setStoragePageIds([1]);
204  $querySettings->setRespectSysLanguage(true);
205  $querySettings->setLanguageUid(1);
206 
207  $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
208 
210  $posts = $query->execute()->toArray();
211 
212  $this->assertCount(3, $posts);
213  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
214  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
215  $this->assertSame('Post3', $posts[2]->getTitle());
216  }
217 }
Definition: Post.php:20
static setSingletonInstance($className, SingletonInterface $instance)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)