TYPO3 CMS  TYPO3_6-2
TranslationTest.php
Go to the documentation of this file.
1 <?php
3 
21 
23 
27  protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
28 
32  protected $coreExtensionsToLoad = array('extbase', 'fluid');
33 
37  protected $objectManager;
38 
42  protected $postRepository;
43 
47  public function setUp() {
48  parent::setUp();
49  /*
50  * Posts Dataset for the tests:
51  *
52  * Post1
53  * -> EN: Post1
54  * -> GR: Post1
55  * Post2
56  * -> EN: Post2
57  * Post3
58  */
59  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
60  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
61  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translated-posts.xml');
62 
63  $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
64  $this->postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
65 
67  }
68 
72  protected function setUpBasicFrontendEnvironment() {
73  $environmentServiceMock = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\EnvironmentService');
74  $environmentServiceMock
75  ->expects($this->any())
76  ->method('isEnvironmentInFrontendMode')
77  ->willReturn(TRUE);
78  GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Service\\EnvironmentService', $environmentServiceMock);
79 
80  $pageRepositoryFixture = new PageRepository();
81  $frontendControllerMock = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
82  $frontendControllerMock->sys_page = $pageRepositoryFixture;
83  $GLOBALS['TSFE'] = $frontendControllerMock;
84  }
85 
90  $query = $this->postRepository->createQuery();
91 
92  $querySettings = $query->getQuerySettings();
93  $querySettings->setStoragePageIds(array(1));
94  $querySettings->setRespectSysLanguage(TRUE);
95  $querySettings->setLanguageUid(0);
96 
97  $postCount = $query->execute()->count();
98  $this->assertSame(3, $postCount);
99  }
100 
105  $query = $this->postRepository->createQuery();
106 
107  $querySettings = $query->getQuerySettings();
108  $querySettings->setStoragePageIds(array(1));
109  $querySettings->setRespectSysLanguage(TRUE);
110  $querySettings->setLanguageUid(1);
111 
112  $postCount = $query->execute()->count();
113  $this->assertSame(3, $postCount);
114  }
115 
120  $query = $this->postRepository->createQuery();
121 
122  $querySettings = $query->getQuerySettings();
123  $querySettings->setStoragePageIds(array(1));
124  $querySettings->setRespectSysLanguage(TRUE);
125  $querySettings->setLanguageUid(2);
126  $postCount = $query->execute()->count();
127 
128  $this->assertSame(3, $postCount);
129  }
130 
134  public function fetchingPostsReturnsEnglishPostsWithFallback() {
135  $query = $this->postRepository->createQuery();
136 
137  $querySettings = $query->getQuerySettings();
138  $querySettings->setStoragePageIds(array(1));
139  $querySettings->setRespectSysLanguage(TRUE);
140  $querySettings->setLanguageUid(1);
141 
143  $posts = $query->execute()->toArray();
144 
145  $this->assertCount(3, $posts);
146  $this->assertSame('B EN:Post1', $posts[0]->getTitle());
147  $this->assertSame('A EN:Post2', $posts[1]->getTitle());
148  $this->assertSame('Post3', $posts[2]->getTitle());
149  }
150 
154  public function fetchingPostsReturnsGreekPostsWithFallback() {
155  $query = $this->postRepository->createQuery();
156 
157  $querySettings = $query->getQuerySettings();
158  $querySettings->setStoragePageIds(array(1));
159  $querySettings->setRespectSysLanguage(TRUE);
160  $querySettings->setLanguageUid(2);
161 
163  $posts = $query->execute()->toArray();
164 
165  $this->assertCount(3, $posts);
166  $this->assertSame('GR:Post1', $posts[0]->getTitle());
167  $this->assertSame('Post2', $posts[1]->getTitle());
168  $this->assertSame('Post3', $posts[2]->getTitle());
169  }
170 
174  public function orderingByTitleRespectsEnglishTitles() {
175  $query = $this->postRepository->createQuery();
176 
177  $querySettings = $query->getQuerySettings();
178  $querySettings->setStoragePageIds(array(1));
179  $querySettings->setRespectSysLanguage(TRUE);
180  $querySettings->setLanguageUid(1);
181 
182  $query->setOrderings(array('title' => QueryInterface::ORDER_ASCENDING));
183 
185  $posts = $query->execute()->toArray();
186 
187  $this->assertCount(3, $posts);
188  $this->assertSame('A EN:Post2', $posts[0]->getTitle());
189  $this->assertSame('B EN:Post1', $posts[1]->getTitle());
190  $this->assertSame('Post3', $posts[2]->getTitle());
191  }
192 }
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]