TYPO3 CMS  TYPO3_7-6
DatabaseSystemLanguageRowsTest.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 
28 
33 {
37  protected $subject;
41  protected $dbProphecy;
42 
46  protected $singletonInstances = [];
47 
48  protected function setUp()
49  {
50  $this->singletonInstances = GeneralUtility::getSingletonInstances();
51  $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
52  $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
53  $languageService = $this->prophesize(LanguageService::class);
54  $GLOBALS['LANG'] = $languageService->reveal();
55  $languageService->sL(Argument::cetera())->willReturnArgument(0);
56  $this->subject = new DatabaseSystemLanguageRows();
57  }
58 
59  protected function tearDown()
60  {
62  GeneralUtility::resetSingletonInstances($this->singletonInstances);
63  parent::tearDown();
64  }
65 
70  {
71  $this->dbProphecy->exec_SELECTgetRows(Argument::cetera())->willReturn(null);
72  $this->dbProphecy->sql_error(Argument::cetera())->willReturn(null);
73  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438170741);
74  $this->subject->addData([]);
75  }
76 
81  {
82  $expected = [
83  'systemLanguageRows' => [
84  -1 => [
85  'uid' => -1,
86  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages',
87  'iso' => 'DEF',
88  'flagIconIdentifier' => 'flags-multiple',
89  ],
90  0 => [
91  'uid' => 0,
92  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage',
93  'iso' => 'DEF',
94  'flagIconIdentifier' => 'empty-empty',
95  ],
96  ],
97  ];
98  $this->dbProphecy->exec_SELECTgetRows(Argument::cetera())->willReturn([]);
99  $this->assertSame($expected, $this->subject->addData([]));
100  }
101 
106  {
107  $input = [
108  'pageTsConfig' => [
109  'mod.' => [
110  'SHARED.' => [
111  'defaultLanguageLabel' => 'foo',
112  ],
113  ]
114  ],
115  ];
116  $this->dbProphecy->exec_SELECTgetRows(Argument::cetera())->willReturn([]);
117  $expected = $input;
118  $expected['systemLanguageRows'] = [
119  -1 => [
120  'uid' => -1,
121  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages',
122  'iso' => 'DEF',
123  'flagIconIdentifier' => 'flags-multiple',
124  ],
125  0 => [
126  'uid' => 0,
127  'title' => 'foo (LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage)',
128  'iso' => 'DEF',
129  'flagIconIdentifier' => 'empty-empty',
130  ],
131  ];
132  $this->assertSame($expected, $this->subject->addData($input));
133  }
134 
139  {
140  $input = [
141  'pageTsConfig' => [
142  'mod.' => [
143  'SHARED.' => [
144  'defaultLanguageFlag' => 'uk',
145  ],
146  ]
147  ],
148  ];
149  $this->dbProphecy->exec_SELECTgetRows(Argument::cetera())->willReturn([]);
150  $expected = $input;
151  $expected['systemLanguageRows'] = [
152  -1 => [
153  'uid' => -1,
154  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages',
155  'iso' => 'DEF',
156  'flagIconIdentifier' => 'flags-multiple',
157  ],
158  0 => [
159  'uid' => 0,
160  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage',
161  'iso' => 'DEF',
162  'flagIconIdentifier' => 'flags-uk',
163  ],
164  ];
165  $this->assertSame($expected, $this->subject->addData($input));
166  }
167 
172  {
173  $dbRows = [
174  [
175  'uid' => 3,
176  'title' => 'french',
177  'language_isocode' => 'fr',
178  'static_lang_isocode' => '',
179  'flag' => 'fr',
180  ],
181  ];
182  $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode,flag', 'sys_language', 'pid=0')->willReturn($dbRows);
183  $expected = [
184  'systemLanguageRows' => [
185  -1 => [
186  'uid' => -1,
187  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages',
188  'iso' => 'DEF',
189  'flagIconIdentifier' => 'flags-multiple',
190  ],
191  0 => [
192  'uid' => 0,
193  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage',
194  'iso' => 'DEF',
195  'flagIconIdentifier' => 'empty-empty',
196  ],
197  3 => [
198  'uid' => 3,
199  'title' => 'french',
200  'flagIconIdentifier' => 'flags-fr',
201  'iso' => 'fr',
202  ],
203  ],
204  ];
205  $this->assertSame($expected, $this->subject->addData([]));
206  }
207 
212  {
213  if (ExtensionManagementUtility::isLoaded('static_info_tables') === false) {
214  $this->markTestSkipped('no ext:static_info_tables available');
215  }
216  $dbRows = [
217  [
218  'uid' => 3,
219  'title' => 'french',
220  'language_isocode' => '',
221  'static_lang_isocode' => 42,
222  'flag' => 'fr',
223  ],
224  ];
225  $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode,flag', 'sys_language', 'pid=0')->shouldBeCalled()->willReturn($dbRows);
226  // Needed for backendUtility::getRecord()
227  $GLOBALS['TCA']['static_languages'] = [ 'foo' ];
228  $this->dbProphecy->exec_SELECTgetSingleRow('lg_iso_2', 'static_languages', 'uid=42')->shouldBeCalled()->willReturn([ 'lg_iso_2' => 'FR' ]);
229  $expected = [
230  'systemLanguageRows' => [
231  -1 => [
232  'uid' => -1,
233  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages',
234  'iso' => 'DEF',
235  'flagIconIdentifier' => 'flags-multiple',
236  ],
237  0 => [
238  'uid' => 0,
239  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage',
240  'iso' => 'DEF',
241  'flagIconIdentifier' => 'empty-empty',
242  ],
243  3 => [
244  'uid' => 3,
245  'title' => 'french',
246  'flagIconIdentifier' => 'flags-fr',
247  'iso' => 'FR',
248  ],
249  ],
250  ];
251  $this->assertSame($expected, $this->subject->addData([]));
252  }
253 
257  public function addDataAddFlashMessageWithMissingIsoCode()
258  {
259  $dbRows = [
260  [
261  'uid' => 3,
262  'title' => 'french',
263  'language_isocode' => '',
264  'static_lang_isocode' => '',
265  'flag' => 'fr',
266  ],
267  ];
268  $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode,flag', 'sys_language', 'pid=0')->shouldBeCalled()->willReturn($dbRows);
269  // Needed for backendUtility::getRecord()
270  $GLOBALS['TCA']['static_languages'] = [ 'foo' ];
271  $expected = [
272  'systemLanguageRows' => [
273  -1 => [
274  'uid' => -1,
275  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages',
276  'iso' => 'DEF',
277  'flagIconIdentifier' => 'flags-multiple',
278  ],
279  0 => [
280  'uid' => 0,
281  'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage',
282  'iso' => 'DEF',
283  'flagIconIdentifier' => 'empty-empty',
284  ],
285  3 => [
286  'uid' => 3,
287  'title' => 'french',
288  'flagIconIdentifier' => 'flags-fr',
289  'iso' => '',
290  ],
291  ],
292  ];
293 
295  $flashMessage = $this->prophesize(FlashMessage::class);
296  GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
298  $flashMessageService = $this->prophesize(FlashMessageService::class);
299  GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
301  $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
302  $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
303 
304  $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
305 
306  $this->assertSame($expected, $this->subject->addData([]));
307  }
308 }
static addInstance($className, $instance)
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']