32 $this->backupLocales = array(
33 'LC_COLLATE' => setlocale(LC_COLLATE, 0),
34 'LC_CTYPE' => setlocale(LC_CTYPE, 0),
35 'LC_MONETARY' => setlocale(LC_MONETARY, 0),
36 'LC_TIME' => setlocale(LC_TIME, 0),
38 $this->arguments[
'name'] =
'';
39 $this->arguments[
'sortByOptionLabel'] = FALSE;
40 $this->viewHelper = $this->
getAccessibleMock(
'TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\SelectViewHelper', array(
'setErrorClassAttribute',
'registerFieldNameForFormTokenGeneration'));
44 foreach ($this->backupLocales as $category => $locale) {
45 setlocale(constant($category), $locale);
54 $this->tagBuilder->expects($this->once())->method(
'setTagName')->with(
'select');
56 $this->arguments[
'options'] = array();
59 $this->viewHelper->initialize();
60 $this->viewHelper->render();
67 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
68 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
69 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value1">label1</option>' . chr(10) .
'<option value="value2" selected="selected">label2</option>' . chr(10));
70 $this->tagBuilder->expects($this->once())->method(
'render');
72 $this->arguments[
'options'] = array(
76 $this->arguments[
'value'] =
'value2';
77 $this->arguments[
'name'] =
'myName';
80 $this->viewHelper->initialize();
81 $this->viewHelper->render();
88 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
89 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
90 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value=""></option>' . chr(10));
91 $this->tagBuilder->expects($this->once())->method(
'render');
93 $this->arguments[
'options'] = array();
94 $this->arguments[
'value'] =
'value2';
95 $this->arguments[
'name'] =
'myName';
98 $this->viewHelper->initialize();
99 $this->viewHelper->render();
106 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
107 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
108 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value3">label3</option>' . chr(10) .
'<option value="value1">label1</option>' . chr(10) .
'<option value="value2" selected="selected">label2</option>' . chr(10));
109 $this->tagBuilder->expects($this->once())->method(
'render');
111 $this->arguments[
'options'] = array(
112 'value3' =>
'label3',
113 'value1' =>
'label1',
117 $this->arguments[
'value'] =
'value2';
118 $this->arguments[
'name'] =
'myName';
122 $this->viewHelper->initialize();
123 $this->viewHelper->render();
130 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
131 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
132 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value1">label1</option>' . chr(10) .
'<option value="value2" selected="selected">label2</option>' . chr(10) .
'<option value="value3">label3</option>' . chr(10));
133 $this->tagBuilder->expects($this->once())->method(
'render');
135 $this->arguments[
'options'] = array(
136 'value3' =>
'label3',
137 'value1' =>
'label1',
141 $this->arguments[
'value'] =
'value2';
142 $this->arguments[
'name'] =
'myName';
143 $this->arguments[
'sortByOptionLabel'] = TRUE;
146 $this->viewHelper->initialize();
147 $this->viewHelper->render();
154 $locale =
'de_DE.UTF-8';
155 if (!setlocale(LC_COLLATE, $locale)) {
156 $this->markTestSkipped(
'Locale ' . $locale .
' is not available.');
158 if (stristr(PHP_OS,
'Darwin')) {
159 $this->markTestSkipped(
'Test skipped caused by a bug in the C libraries on BSD/OSX');
162 setlocale(LC_CTYPE, $locale);
163 setlocale(LC_MONETARY, $locale);
164 setlocale(LC_TIME, $locale);
165 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
166 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
167 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value1">Bamberg</option>' . chr(10) .
'<option value="value2" selected="selected">Bämm</option>' . chr(10) .
'<option value="value3">Bar</option>' . chr(10) .
'<option value="value4">Bär</option>' . chr(10) .
'<option value="value5">Burg</option>' . chr(10));
168 $this->tagBuilder->expects($this->once())->method(
'render');
169 $this->arguments[
'options'] = array(
173 'value1' =>
'Bamberg',
176 $this->arguments[
'value'] =
'value2';
177 $this->arguments[
'name'] =
'myName';
178 $this->arguments[
'sortByOptionLabel'] = TRUE;
180 $this->viewHelper->initialize();
181 $this->viewHelper->render();
188 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
190 $this->arguments[
'options'] = array(
191 'value1' =>
'label1',
192 'value2' =>
'label2',
196 $this->arguments[
'value'] = array(
'value3',
'value1');
197 $this->arguments[
'name'] =
'myName';
198 $this->arguments[
'multiple'] =
'multiple';
202 $this->viewHelper->initializeArguments();
203 $this->viewHelper->initialize();
204 $result = $this->viewHelper->render();
205 $expected =
'<input type="hidden" name="myName" value="" /><select multiple="multiple" name="myName[]"><option value="value1" selected="selected">label1</option>' . chr(10) .
'<option value="value2">label2</option>' . chr(10) .
'<option value="value3" selected="selected">label3</option>' . chr(10) .
'</select>';
206 $this->assertSame($expected,
$result);
213 $mockPersistenceManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
214 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(NULL));
215 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
217 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
218 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
219 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="1">Ingmar</option>' . chr(10) .
'<option value="2" selected="selected">Sebastian</option>' . chr(10) .
'<option value="3">Robert</option>' . chr(10));
220 $this->tagBuilder->expects($this->once())->method(
'render');
222 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
223 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2,
'Sebastian',
'Kurfuerst');
224 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3,
'Robert',
'Lemke');
226 $this->arguments[
'options'] = array(
232 $this->arguments[
'value'] = $user_sk;
233 $this->arguments[
'optionValueField'] =
'id';
234 $this->arguments[
'optionLabelField'] =
'firstName';
235 $this->arguments[
'name'] =
'myName';
238 $this->viewHelper->initialize();
239 $this->viewHelper->render();
246 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
247 $this->viewHelper->expects($this->exactly(3))->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName[]');
249 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
250 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2,
'Sebastian',
'Kurfuerst');
251 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3,
'Robert',
'Lemke');
252 $this->arguments[
'options'] = array(
257 $this->arguments[
'value'] = array($user_rl, $user_is);
258 $this->arguments[
'optionValueField'] =
'id';
259 $this->arguments[
'optionLabelField'] =
'lastName';
260 $this->arguments[
'name'] =
'myName';
261 $this->arguments[
'multiple'] =
'multiple';
265 $this->viewHelper->initializeArguments();
266 $this->viewHelper->initialize();
267 $actual = $this->viewHelper->render();
268 $expected =
'<input type="hidden" name="myName" value="" /><select multiple="multiple" name="myName[]"><option value="1" selected="selected">Schlecht</option>' . chr(10) .
269 '<option value="2">Kurfuerst</option>' . chr(10) .
270 '<option value="3" selected="selected">Lemke</option>' . chr(10) .
273 $this->assertSame($expected, $actual);
279 public function multipleSelectOnDomainObjectsCreatesExpectedOptionsWithoutOptionValueField() {
281 $mockPersistenceManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
282 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnCallback(
284 return $object->getId();
287 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
289 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
290 $this->viewHelper->expects($this->exactly(3))->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName[]');
292 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
293 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2,
'Sebastian',
'Kurfuerst');
294 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3,
'Robert',
'Lemke');
296 $this->arguments[
'options'] = array($user_is,$user_sk,$user_rl);
297 $this->arguments[
'value'] = array($user_rl, $user_is);
298 $this->arguments[
'optionLabelField'] =
'lastName';
299 $this->arguments[
'name'] =
'myName';
300 $this->arguments[
'multiple'] =
'multiple';
304 $this->viewHelper->initializeArguments();
305 $this->viewHelper->initialize();
306 $actual = $this->viewHelper->render();
307 $expected =
'<input type="hidden" name="myName" value="" />' .
308 '<select multiple="multiple" name="myName[]">' .
309 '<option value="1" selected="selected">Schlecht</option>' . chr(10) .
310 '<option value="2">Kurfuerst</option>' . chr(10) .
311 '<option value="3" selected="selected">Lemke</option>' . chr(10) .
313 $this->assertSame($expected, $actual);
320 $mockPersistenceManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
321 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(
'fakeUID'));
322 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
324 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
325 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
326 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="fakeUID">fakeUID</option>' . chr(10));
327 $this->tagBuilder->expects($this->once())->method(
'render');
329 $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
331 $this->arguments[
'options'] = array(
334 $this->arguments[
'name'] =
'myName';
337 $this->viewHelper->initialize();
338 $this->viewHelper->render();
345 $mockPersistenceManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
346 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(
'fakeUID'));
347 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
349 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
350 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
351 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="fakeUID">toStringResult</option>' . chr(10));
352 $this->tagBuilder->expects($this->once())->method(
'render');
354 $user = $this->getMock(
'TYPO3\\CMS\\Fluid\\Tests\\Unit\\ViewHelpers\\Form\\Fixtures\\UserDomainClass', array(
'__toString'), array(1,
'Ingmar',
'Schlecht'));
355 $user->expects($this->atLeastOnce())->method(
'__toString')->will($this->returnValue(
'toStringResult'));
357 $this->arguments[
'options'] = array(
360 $this->arguments[
'name'] =
'myName';
363 $this->viewHelper->initialize();
364 $this->viewHelper->render();
372 $mockPersistenceManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
373 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(NULL));
374 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
376 $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
378 $this->arguments[
'options'] = array(
381 $this->arguments[
'name'] =
'myName';
384 $this->viewHelper->initialize();
385 $this->viewHelper->render();
392 $this->arguments[
'options'] = array();
396 $this->viewHelper->expects($this->once())->method(
'setErrorClassAttribute');
397 $this->viewHelper->render();
404 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value1" selected="selected">label1</option>' . chr(10) .
'<option value="value2" selected="selected">label2</option>' . chr(10) .
'<option value="value3" selected="selected">label3</option>' . chr(10));
406 $this->arguments[
'options'] = array(
407 'value1' =>
'label1',
408 'value2' =>
'label2',
411 $this->arguments[
'name'] =
'myName';
412 $this->arguments[
'multiple'] =
'multiple';
413 $this->arguments[
'selectAllByDefault'] = TRUE;
417 $this->viewHelper->initialize();
418 $this->viewHelper->render();
425 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value1" selected="selected">label1</option>' . chr(10) .
'<option value="value2" selected="selected">label2</option>' . chr(10) .
'<option value="value3">label3</option>' . chr(10));
427 $this->arguments[
'options'] = array(
428 'value1' =>
'label1',
429 'value2' =>
'label2',
432 $this->arguments[
'value'] = array(
'value2',
'value1');
433 $this->arguments[
'name'] =
'myName';
434 $this->arguments[
'multiple'] =
'multiple';
435 $this->arguments[
'selectAllByDefault'] = TRUE;
439 $this->viewHelper->initialize();
440 $this->viewHelper->render();
447 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
448 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
449 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="">please choose</option>' . chr(10) .
'<option value="value1">label1</option>' . chr(10) .
'<option value="value2">label2</option>' . chr(10) .
'<option value="value3">label3</option>' . chr(10));
450 $this->tagBuilder->expects($this->once())->method(
'render');
451 $this->arguments[
'options'] = array(
452 'value1' =>
'label1',
453 'value2' =>
'label2',
456 $this->arguments[
'name'] =
'myName';
457 $this->arguments[
'prependOptionLabel'] =
'please choose';
459 $this->viewHelper->initialize();
460 $this->viewHelper->render();
467 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
468 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
469 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="-1">please choose</option>' . chr(10) .
'<option value="value1">label1</option>' . chr(10) .
'<option value="value2">label2</option>' . chr(10) .
'<option value="value3">label3</option>' . chr(10));
470 $this->tagBuilder->expects($this->once())->method(
'render');
471 $this->arguments[
'options'] = array(
472 'value1' =>
'label1',
473 'value2' =>
'label2',
476 $this->arguments[
'name'] =
'myName';
477 $this->arguments[
'prependOptionLabel'] =
'please choose';
478 $this->arguments[
'prependOptionValue'] =
'-1';
480 $this->viewHelper->initialize();
481 $this->viewHelper->render();
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.