2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form;
33 $this->backupLocales = array(
34 'LC_COLLATE' => setlocale(LC_COLLATE, 0),
35 'LC_CTYPE' => setlocale(LC_CTYPE, 0),
36 'LC_MONETARY' => setlocale(LC_MONETARY, 0),
37 'LC_TIME' => setlocale(LC_TIME, 0),
39 $this->arguments[
'name'] =
'';
40 $this->arguments[
'sortByOptionLabel'] =
false;
41 $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\
Fluid\ViewHelpers\Form\SelectViewHelper::class, array(
'setErrorClassAttribute',
'registerFieldNameForFormTokenGeneration'));
46 foreach ($this->backupLocales as $category => $locale) {
47 setlocale(constant($category), $locale);
57 $this->tagBuilder->expects($this->once())->method(
'setTagName')->with(
'select');
59 $this->arguments[
'options'] = array();
62 $this->viewHelper->initialize();
63 $this->viewHelper->render();
71 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
72 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
73 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="value1">label1</option>' . chr(10) .
'<option value="value2" selected="selected">label2</option>' . chr(10));
74 $this->tagBuilder->expects($this->once())->method(
'render');
76 $this->arguments[
'options'] = array(
80 $this->arguments[
'value'] =
'value2';
81 $this->arguments[
'name'] =
'myName';
84 $this->viewHelper->initialize();
85 $this->viewHelper->render();
93 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
94 '<option value="2"></option>' . chr(10) .
95 '<option value="-1">Bar</option>' . chr(10) .
96 '<option value="">Baz</option>' . chr(10) .
97 '<option value="1">Foo</option>' . chr(10)
100 $this->arguments[
'optionValueField'] =
'uid';
101 $this->arguments[
'optionLabelField'] =
'title';
102 $this->arguments[
'sortByOptionLabel'] =
true;
103 $this->arguments[
'options'] = array(
121 $this->viewHelper->initialize();
122 $this->viewHelper->render();
130 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
131 '<option value="2"></option>' . chr(10) .
132 '<option value="-1">Bar</option>' . chr(10) .
133 '<option value="">Baz</option>' . chr(10) .
134 '<option value="1">Foo</option>' . chr(10)
137 $obj1 = new \StdClass();
139 $obj1->title =
'Foo';
141 $obj2 = new \StdClass();
143 $obj2->title =
'Bar';
145 $obj3 = new \StdClass();
146 $obj3->title =
'Baz';
148 $obj4 = new \StdClass();
151 $this->arguments[
'optionValueField'] =
'uid';
152 $this->arguments[
'optionLabelField'] =
'title';
153 $this->arguments[
'sortByOptionLabel'] =
true;
154 $this->arguments[
'options'] = array($obj1, $obj2, $obj3, $obj4);
157 $this->viewHelper->initialize();
158 $this->viewHelper->render();
166 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
167 '<option value="2"></option>' . chr(10) .
168 '<option value="-1">Bar</option>' . chr(10) .
169 '<option value="">Baz</option>' . chr(10) .
170 '<option value="1">Foo</option>' . chr(10)
173 $this->arguments[
'optionValueField'] =
'uid';
174 $this->arguments[
'optionLabelField'] =
'title';
175 $this->arguments[
'sortByOptionLabel'] =
true;
176 $this->arguments[
'options'] = new \ArrayObject(array(
194 $this->viewHelper->initialize();
195 $this->viewHelper->render();
203 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
204 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
205 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value=""></option>' . chr(10));
206 $this->tagBuilder->expects($this->once())->method(
'render');
208 $this->arguments[
'options'] = array();
209 $this->arguments[
'value'] =
'value2';
210 $this->arguments[
'name'] =
'myName';
213 $this->viewHelper->initialize();
214 $this->viewHelper->render();
222 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
223 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
224 $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));
225 $this->tagBuilder->expects($this->once())->method(
'render');
227 $this->arguments[
'options'] = array(
228 'value3' =>
'label3',
229 'value1' =>
'label1',
233 $this->arguments[
'value'] =
'value2';
234 $this->arguments[
'name'] =
'myName';
238 $this->viewHelper->initialize();
239 $this->viewHelper->render();
247 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
248 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
249 $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));
250 $this->tagBuilder->expects($this->once())->method(
'render');
252 $this->arguments[
'options'] = array(
253 'value3' =>
'label3',
254 'value1' =>
'label1',
258 $this->arguments[
'value'] =
'value2';
259 $this->arguments[
'name'] =
'myName';
260 $this->arguments[
'sortByOptionLabel'] =
true;
263 $this->viewHelper->initialize();
264 $this->viewHelper->render();
272 $locale =
'de_DE.UTF-8';
273 if (!setlocale(LC_COLLATE, $locale)) {
274 $this->markTestSkipped(
'Locale ' . $locale .
' is not available.');
276 if (stristr(PHP_OS,
'Darwin')) {
277 $this->markTestSkipped(
'Test skipped caused by a bug in the C libraries on BSD/OSX');
280 setlocale(LC_CTYPE, $locale);
281 setlocale(LC_MONETARY, $locale);
282 setlocale(LC_TIME, $locale);
283 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
284 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
285 $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));
286 $this->tagBuilder->expects($this->once())->method(
'render');
287 $this->arguments[
'options'] = array(
291 'value1' =>
'Bamberg',
294 $this->arguments[
'value'] =
'value2';
295 $this->arguments[
'name'] =
'myName';
296 $this->arguments[
'sortByOptionLabel'] =
true;
298 $this->viewHelper->initialize();
299 $this->viewHelper->render();
307 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
309 $this->arguments[
'options'] = array(
310 'value1' =>
'label1',
311 'value2' =>
'label2',
315 $this->arguments[
'value'] = array(
'value3',
'value1');
316 $this->arguments[
'name'] =
'myName';
317 $this->arguments[
'multiple'] =
'multiple';
321 $this->viewHelper->initializeArguments();
322 $this->viewHelper->initialize();
323 $result = $this->viewHelper->render();
324 $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>';
325 $this->assertSame($expected, $result);
333 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
334 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(2));
335 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
337 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName[__identity]');
338 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName[__identity]');
339 $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));
340 $this->tagBuilder->expects($this->once())->method(
'render');
342 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
343 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2,
'Sebastian',
'Kurfuerst');
344 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3,
'Robert',
'Lemke');
346 $this->arguments[
'options'] = array(
352 $this->arguments[
'value'] = $user_sk;
353 $this->arguments[
'optionValueField'] =
'id';
354 $this->arguments[
'optionLabelField'] =
'firstName';
355 $this->arguments[
'name'] =
'myName';
358 $this->viewHelper->initialize();
359 $this->viewHelper->render();
367 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
368 $this->viewHelper->expects($this->exactly(3))->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName[]');
370 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
371 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2,
'Sebastian',
'Kurfuerst');
372 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3,
'Robert',
'Lemke');
373 $this->arguments[
'options'] = array(
378 $this->arguments[
'value'] = array($user_rl, $user_is);
379 $this->arguments[
'optionValueField'] =
'id';
380 $this->arguments[
'optionLabelField'] =
'lastName';
381 $this->arguments[
'name'] =
'myName';
382 $this->arguments[
'multiple'] =
'multiple';
386 $this->viewHelper->initializeArguments();
387 $this->viewHelper->initialize();
388 $actual = $this->viewHelper->render();
389 $expected =
'<input type="hidden" name="myName" value="" /><select multiple="multiple" name="myName[]"><option value="1" selected="selected">Schlecht</option>' . chr(10) .
390 '<option value="2">Kurfuerst</option>' . chr(10) .
391 '<option value="3" selected="selected">Lemke</option>' . chr(10) .
394 $this->assertSame($expected, $actual);
400 public function multipleSelectOnDomainObjectsCreatesExpectedOptionsWithoutOptionValueField()
403 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
404 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnCallback(
406 return $object->getId();
409 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
411 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
412 $this->viewHelper->expects($this->exactly(3))->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName[]');
414 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
415 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2,
'Sebastian',
'Kurfuerst');
416 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3,
'Robert',
'Lemke');
418 $this->arguments[
'options'] = array($user_is,$user_sk,$user_rl);
419 $this->arguments[
'value'] = array($user_rl, $user_is);
420 $this->arguments[
'optionLabelField'] =
'lastName';
421 $this->arguments[
'name'] =
'myName';
422 $this->arguments[
'multiple'] =
'multiple';
426 $this->viewHelper->initializeArguments();
427 $this->viewHelper->initialize();
428 $actual = $this->viewHelper->render();
429 $expected =
'<input type="hidden" name="myName" value="" />' .
430 '<select multiple="multiple" name="myName[]">' .
431 '<option value="1" selected="selected">Schlecht</option>' . chr(10) .
432 '<option value="2">Kurfuerst</option>' . chr(10) .
433 '<option value="3" selected="selected">Lemke</option>' . chr(10) .
435 $this->assertSame($expected, $actual);
443 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
444 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(
'fakeUID'));
445 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
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="fakeUID">fakeUID</option>' . chr(10));
450 $this->tagBuilder->expects($this->once())->method(
'render');
452 $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
454 $this->arguments[
'options'] = array(
457 $this->arguments[
'name'] =
'myName';
460 $this->viewHelper->initialize();
461 $this->viewHelper->render();
469 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
470 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(
'fakeUID'));
471 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
473 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
474 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
475 $this->tagBuilder->expects($this->once())->method(
'setContent')->with(
'<option value="fakeUID">toStringResult</option>' . chr(10));
476 $this->tagBuilder->expects($this->once())->method(
'render');
478 $user = $this->getMock(\TYPO3\CMS\
Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass::class, array(
'__toString'), array(1,
'Ingmar',
'Schlecht'));
479 $user->expects($this->atLeastOnce())->method(
'__toString')->will($this->returnValue(
'toStringResult'));
481 $this->arguments[
'options'] = array(
484 $this->arguments[
'name'] =
'myName';
487 $this->viewHelper->initialize();
488 $this->viewHelper->render();
497 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
498 $mockPersistenceManager->expects($this->any())->method(
'getIdentifierByObject')->will($this->returnValue(null));
499 $this->viewHelper->_set(
'persistenceManager', $mockPersistenceManager);
501 $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1,
'Ingmar',
'Schlecht');
503 $this->arguments[
'options'] = array(
506 $this->arguments[
'name'] =
'myName';
509 $this->viewHelper->initialize();
510 $this->viewHelper->render();
518 $this->arguments[
'options'] = array();
522 $this->viewHelper->expects($this->once())->method(
'setErrorClassAttribute');
523 $this->viewHelper->render();
531 $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));
533 $this->arguments[
'options'] = array(
534 'value1' =>
'label1',
535 'value2' =>
'label2',
538 $this->arguments[
'name'] =
'myName';
539 $this->arguments[
'multiple'] =
'multiple';
540 $this->arguments[
'selectAllByDefault'] =
true;
544 $this->viewHelper->initialize();
545 $this->viewHelper->render();
553 $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));
555 $this->arguments[
'options'] = array(
556 'value1' =>
'label1',
557 'value2' =>
'label2',
560 $this->arguments[
'value'] = array(
'value2',
'value1');
561 $this->arguments[
'name'] =
'myName';
562 $this->arguments[
'multiple'] =
'multiple';
563 $this->arguments[
'selectAllByDefault'] =
true;
567 $this->viewHelper->initialize();
568 $this->viewHelper->render();
576 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
577 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
578 $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));
579 $this->tagBuilder->expects($this->once())->method(
'render');
580 $this->arguments[
'options'] = array(
581 'value1' =>
'label1',
582 'value2' =>
'label2',
585 $this->arguments[
'name'] =
'myName';
586 $this->arguments[
'prependOptionLabel'] =
'please choose';
588 $this->viewHelper->initialize();
589 $this->viewHelper->render();
597 $this->tagBuilder->expects($this->once())->method(
'addAttribute')->with(
'name',
'myName');
598 $this->viewHelper->expects($this->once())->method(
'registerFieldNameForFormTokenGeneration')->with(
'myName');
599 $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));
600 $this->tagBuilder->expects($this->once())->method(
'render');
601 $this->arguments[
'options'] = array(
602 'value1' =>
'label1',
603 'value2' =>
'label2',
606 $this->arguments[
'name'] =
'myName';
607 $this->arguments[
'prependOptionLabel'] =
'please choose';
608 $this->arguments[
'prependOptionValue'] =
'-1';
610 $this->viewHelper->initialize();
611 $this->viewHelper->render();