[BUGFIX] Submitted form data has precedence over value argument
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Form / SelectViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Test for the "Select" Form view helper
16 */
17 class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase {
18
19 /**
20 * @var \TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper
21 */
22 protected $viewHelper;
23
24 /**
25 * @var array Backup of current locale, it is manipulated in tests
26 */
27 protected $backupLocales = array();
28
29 protected function setUp() {
30 parent::setUp();
31 // Store all locale categories manipulated in tests for reconstruction in tearDown
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),
37 );
38 $this->arguments['name'] = '';
39 $this->arguments['sortByOptionLabel'] = FALSE;
40 $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::class, array('setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration'));
41 }
42
43 protected function tearDown() {
44 foreach ($this->backupLocales as $category => $locale) {
45 setlocale(constant($category), $locale);
46 }
47 parent::tearDown();
48 }
49
50 /**
51 * @test
52 */
53 public function selectCorrectlySetsTagName() {
54 $this->tagBuilder->expects($this->once())->method('setTagName')->with('select');
55
56 $this->arguments['options'] = array();
57 $this->injectDependenciesIntoViewHelper($this->viewHelper);
58
59 $this->viewHelper->initialize();
60 $this->viewHelper->render();
61 }
62
63 /**
64 * @test
65 */
66 public function selectCreatesExpectedOptions() {
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');
71
72 $this->arguments['options'] = array(
73 'value1' => 'label1',
74 'value2' => 'label2'
75 );
76 $this->arguments['value'] = 'value2';
77 $this->arguments['name'] = 'myName';
78
79 $this->injectDependenciesIntoViewHelper($this->viewHelper);
80 $this->viewHelper->initialize();
81 $this->viewHelper->render();
82 }
83
84 /**
85 * @test
86 */
87 public function selectCreatesExpectedOptionsWithArraysAndOptionValueFieldAndOptionLabelFieldSet() {
88 $this->tagBuilder->expects($this->once())->method('setContent')->with(
89 '<option value="2"></option>' . chr(10) .
90 '<option value="-1">Bar</option>' . chr(10) .
91 '<option value="">Baz</option>' . chr(10) .
92 '<option value="1">Foo</option>' . chr(10)
93 );
94
95 $this->arguments['optionValueField'] = 'uid';
96 $this->arguments['optionLabelField'] = 'title';
97 $this->arguments['sortByOptionLabel'] = TRUE;
98 $this->arguments['options'] = array(
99 array(
100 'uid' => 1,
101 'title' => 'Foo'
102 ),
103 array(
104 'uid' => -1,
105 'title' => 'Bar'
106 ),
107 array(
108 'title' => 'Baz'
109 ),
110 array(
111 'uid' => '2'
112 ),
113 );
114
115 $this->injectDependenciesIntoViewHelper($this->viewHelper);
116 $this->viewHelper->initialize();
117 $this->viewHelper->render();
118 }
119
120 /**
121 * @test
122 */
123 public function selectCreatesExpectedOptionsWithStdClassesAndOptionValueFieldAndOptionLabelFieldSet() {
124 $this->tagBuilder->expects($this->once())->method('setContent')->with(
125 '<option value="2"></option>' . chr(10) .
126 '<option value="-1">Bar</option>' . chr(10) .
127 '<option value="">Baz</option>' . chr(10) .
128 '<option value="1">Foo</option>' . chr(10)
129 );
130
131 $obj1 = new \StdClass();
132 $obj1->uid = 1;
133 $obj1->title = 'Foo';
134
135 $obj2 = new \StdClass();
136 $obj2->uid = -1;
137 $obj2->title = 'Bar';
138
139 $obj3 = new \StdClass();
140 $obj3->title = 'Baz';
141
142 $obj4 = new \StdClass();
143 $obj4->uid = 2;
144
145 $this->arguments['optionValueField'] = 'uid';
146 $this->arguments['optionLabelField'] = 'title';
147 $this->arguments['sortByOptionLabel'] = TRUE;
148 $this->arguments['options'] = array($obj1, $obj2, $obj3, $obj4);
149
150 $this->injectDependenciesIntoViewHelper($this->viewHelper);
151 $this->viewHelper->initialize();
152 $this->viewHelper->render();
153 }
154
155 /**
156 * @test
157 */
158 public function selectCreatesExpectedOptionsWithArrayObjectsAndOptionValueFieldAndOptionLabelFieldSet() {
159 $this->tagBuilder->expects($this->once())->method('setContent')->with(
160 '<option value="2"></option>' . chr(10) .
161 '<option value="-1">Bar</option>' . chr(10) .
162 '<option value="">Baz</option>' . chr(10) .
163 '<option value="1">Foo</option>' . chr(10)
164 );
165
166 $this->arguments['optionValueField'] = 'uid';
167 $this->arguments['optionLabelField'] = 'title';
168 $this->arguments['sortByOptionLabel'] = TRUE;
169 $this->arguments['options'] = new \ArrayObject(array(
170 array(
171 'uid' => 1,
172 'title' => 'Foo'
173 ),
174 array(
175 'uid' => -1,
176 'title' => 'Bar'
177 ),
178 array(
179 'title' => 'Baz'
180 ),
181 array(
182 'uid' => '2'
183 ),
184 ));
185
186 $this->injectDependenciesIntoViewHelper($this->viewHelper);
187 $this->viewHelper->initialize();
188 $this->viewHelper->render();
189 }
190
191 /**
192 * @test
193 */
194 public function anEmptyOptionTagIsRenderedIfOptionsArrayIsEmptyToAssureXhtmlCompatibility() {
195 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
196 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
197 $this->tagBuilder->expects($this->once())->method('setContent')->with('<option value=""></option>' . chr(10));
198 $this->tagBuilder->expects($this->once())->method('render');
199
200 $this->arguments['options'] = array();
201 $this->arguments['value'] = 'value2';
202 $this->arguments['name'] = 'myName';
203 $this->injectDependenciesIntoViewHelper($this->viewHelper);
204
205 $this->viewHelper->initialize();
206 $this->viewHelper->render();
207 }
208
209 /**
210 * @test
211 */
212 public function OrderOfOptionsIsNotAlteredByDefault() {
213 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
214 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
215 $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));
216 $this->tagBuilder->expects($this->once())->method('render');
217
218 $this->arguments['options'] = array(
219 'value3' => 'label3',
220 'value1' => 'label1',
221 'value2' => 'label2'
222 );
223
224 $this->arguments['value'] = 'value2';
225 $this->arguments['name'] = 'myName';
226
227 $this->injectDependenciesIntoViewHelper($this->viewHelper);
228
229 $this->viewHelper->initialize();
230 $this->viewHelper->render();
231 }
232
233 /**
234 * @test
235 */
236 public function optionsAreSortedByLabelIfSortByOptionLabelIsSet() {
237 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
238 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
239 $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));
240 $this->tagBuilder->expects($this->once())->method('render');
241
242 $this->arguments['options'] = array(
243 'value3' => 'label3',
244 'value1' => 'label1',
245 'value2' => 'label2'
246 );
247
248 $this->arguments['value'] = 'value2';
249 $this->arguments['name'] = 'myName';
250 $this->arguments['sortByOptionLabel'] = TRUE;
251
252 $this->injectDependenciesIntoViewHelper($this->viewHelper);
253 $this->viewHelper->initialize();
254 $this->viewHelper->render();
255 }
256
257 /**
258 * @test
259 */
260 public function optionsAreSortedByLabelIfSortByOptionLabelIsSetAndLocaleEqualsUtf8() {
261 $locale = 'de_DE.UTF-8';
262 if (!setlocale(LC_COLLATE, $locale)) {
263 $this->markTestSkipped('Locale ' . $locale . ' is not available.');
264 }
265 if (stristr(PHP_OS, 'Darwin')) {
266 $this->markTestSkipped('Test skipped caused by a bug in the C libraries on BSD/OSX');
267 }
268
269 setlocale(LC_CTYPE, $locale);
270 setlocale(LC_MONETARY, $locale);
271 setlocale(LC_TIME, $locale);
272 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
273 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
274 $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));
275 $this->tagBuilder->expects($this->once())->method('render');
276 $this->arguments['options'] = array(
277 'value4' => 'Bär',
278 'value2' => 'Bämm',
279 'value5' => 'Burg',
280 'value1' => 'Bamberg',
281 'value3' => 'Bar'
282 );
283 $this->arguments['value'] = 'value2';
284 $this->arguments['name'] = 'myName';
285 $this->arguments['sortByOptionLabel'] = TRUE;
286 $this->injectDependenciesIntoViewHelper($this->viewHelper);
287 $this->viewHelper->initialize();
288 $this->viewHelper->render();
289 }
290
291 /**
292 * @test
293 */
294 public function multipleSelectCreatesExpectedOptions() {
295 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
296
297 $this->arguments['options'] = array(
298 'value1' => 'label1',
299 'value2' => 'label2',
300 'value3' => 'label3'
301 );
302
303 $this->arguments['value'] = array('value3', 'value1');
304 $this->arguments['name'] = 'myName';
305 $this->arguments['multiple'] = 'multiple';
306
307 $this->injectDependenciesIntoViewHelper($this->viewHelper);
308
309 $this->viewHelper->initializeArguments();
310 $this->viewHelper->initialize();
311 $result = $this->viewHelper->render();
312 $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>';
313 $this->assertSame($expected, $result);
314 }
315
316 /**
317 * @test
318 */
319 public function selectOnDomainObjectsCreatesExpectedOptions() {
320 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
321 $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue(2));
322 $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
323
324 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName[__identity]');
325 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName[__identity]');
326 $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));
327 $this->tagBuilder->expects($this->once())->method('render');
328
329 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
330 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2, 'Sebastian', 'Kurfuerst');
331 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3, 'Robert', 'Lemke');
332
333 $this->arguments['options'] = array(
334 $user_is,
335 $user_sk,
336 $user_rl
337 );
338
339 $this->arguments['value'] = $user_sk;
340 $this->arguments['optionValueField'] = 'id';
341 $this->arguments['optionLabelField'] = 'firstName';
342 $this->arguments['name'] = 'myName';
343 $this->injectDependenciesIntoViewHelper($this->viewHelper);
344
345 $this->viewHelper->initialize();
346 $this->viewHelper->render();
347 }
348
349 /**
350 * @test
351 */
352 public function multipleSelectOnDomainObjectsCreatesExpectedOptions() {
353 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
354 $this->viewHelper->expects($this->exactly(3))->method('registerFieldNameForFormTokenGeneration')->with('myName[]');
355
356 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
357 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2, 'Sebastian', 'Kurfuerst');
358 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3, 'Robert', 'Lemke');
359 $this->arguments['options'] = array(
360 $user_is,
361 $user_sk,
362 $user_rl
363 );
364 $this->arguments['value'] = array($user_rl, $user_is);
365 $this->arguments['optionValueField'] = 'id';
366 $this->arguments['optionLabelField'] = 'lastName';
367 $this->arguments['name'] = 'myName';
368 $this->arguments['multiple'] = 'multiple';
369
370 $this->injectDependenciesIntoViewHelper($this->viewHelper);
371
372 $this->viewHelper->initializeArguments();
373 $this->viewHelper->initialize();
374 $actual = $this->viewHelper->render();
375 $expected = '<input type="hidden" name="myName" value="" /><select multiple="multiple" name="myName[]"><option value="1" selected="selected">Schlecht</option>' . chr(10) .
376 '<option value="2">Kurfuerst</option>' . chr(10) .
377 '<option value="3" selected="selected">Lemke</option>' . chr(10) .
378 '</select>';
379
380 $this->assertSame($expected, $actual);
381 }
382
383 /**
384 * @test
385 */
386 public function multipleSelectOnDomainObjectsCreatesExpectedOptionsWithoutOptionValueField() {
387 /** @var $mockPersistenceManager \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface */
388 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
389 $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnCallback(
390 function ($object) {
391 return $object->getId();
392 }
393 ));
394 $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
395
396 $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
397 $this->viewHelper->expects($this->exactly(3))->method('registerFieldNameForFormTokenGeneration')->with('myName[]');
398
399 $user_is = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
400 $user_sk = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(2, 'Sebastian', 'Kurfuerst');
401 $user_rl = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(3, 'Robert', 'Lemke');
402
403 $this->arguments['options'] = array($user_is,$user_sk,$user_rl);
404 $this->arguments['value'] = array($user_rl, $user_is);
405 $this->arguments['optionLabelField'] = 'lastName';
406 $this->arguments['name'] = 'myName';
407 $this->arguments['multiple'] = 'multiple';
408
409 $this->injectDependenciesIntoViewHelper($this->viewHelper);
410
411 $this->viewHelper->initializeArguments();
412 $this->viewHelper->initialize();
413 $actual = $this->viewHelper->render();
414 $expected = '<input type="hidden" name="myName" value="" />' .
415 '<select multiple="multiple" name="myName[]">' .
416 '<option value="1" selected="selected">Schlecht</option>' . chr(10) .
417 '<option value="2">Kurfuerst</option>' . chr(10) .
418 '<option value="3" selected="selected">Lemke</option>' . chr(10) .
419 '</select>';
420 $this->assertSame($expected, $actual);
421 }
422
423 /**
424 * @test
425 */
426 public function selectWithoutFurtherConfigurationOnDomainObjectsUsesUuidForValueAndLabel() {
427 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
428 $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('fakeUID'));
429 $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
430
431 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
432 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
433 $this->tagBuilder->expects($this->once())->method('setContent')->with('<option value="fakeUID">fakeUID</option>' . chr(10));
434 $this->tagBuilder->expects($this->once())->method('render');
435
436 $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
437
438 $this->arguments['options'] = array(
439 $user
440 );
441 $this->arguments['name'] = 'myName';
442 $this->injectDependenciesIntoViewHelper($this->viewHelper);
443
444 $this->viewHelper->initialize();
445 $this->viewHelper->render();
446 }
447
448 /**
449 * @test
450 */
451 public function selectWithoutFurtherConfigurationOnDomainObjectsUsesToStringForLabelIfAvailable() {
452 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
453 $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('fakeUID'));
454 $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
455
456 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
457 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
458 $this->tagBuilder->expects($this->once())->method('setContent')->with('<option value="fakeUID">toStringResult</option>' . chr(10));
459 $this->tagBuilder->expects($this->once())->method('render');
460
461 $user = $this->getMock(\TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass::class, array('__toString'), array(1, 'Ingmar', 'Schlecht'));
462 $user->expects($this->atLeastOnce())->method('__toString')->will($this->returnValue('toStringResult'));
463
464 $this->arguments['options'] = array(
465 $user
466 );
467 $this->arguments['name'] = 'myName';
468 $this->injectDependenciesIntoViewHelper($this->viewHelper);
469
470 $this->viewHelper->initialize();
471 $this->viewHelper->render();
472 }
473
474 /**
475 * @test
476 * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
477 */
478 public function selectOnDomainObjectsThrowsExceptionIfNoValueCanBeFound() {
479 $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
480 $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue(NULL));
481 $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
482
483 $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
484
485 $this->arguments['options'] = array(
486 $user
487 );
488 $this->arguments['name'] = 'myName';
489 $this->injectDependenciesIntoViewHelper($this->viewHelper);
490
491 $this->viewHelper->initialize();
492 $this->viewHelper->render();
493 }
494
495 /**
496 * @test
497 */
498 public function renderCallsSetErrorClassAttribute() {
499 $this->arguments['options'] = array();
500
501 $this->injectDependenciesIntoViewHelper($this->viewHelper);
502
503 $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
504 $this->viewHelper->render();
505 }
506
507 /**
508 * @test
509 */
510 public function allOptionsAreSelectedIfSelectAllIsTrue() {
511 $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));
512
513 $this->arguments['options'] = array(
514 'value1' => 'label1',
515 'value2' => 'label2',
516 'value3' => 'label3'
517 );
518 $this->arguments['name'] = 'myName';
519 $this->arguments['multiple'] = 'multiple';
520 $this->arguments['selectAllByDefault'] = TRUE;
521
522 $this->injectDependenciesIntoViewHelper($this->viewHelper);
523
524 $this->viewHelper->initialize();
525 $this->viewHelper->render();
526 }
527
528 /**
529 * @test
530 */
531 public function selectAllHasNoEffectIfValueIsSet() {
532 $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));
533
534 $this->arguments['options'] = array(
535 'value1' => 'label1',
536 'value2' => 'label2',
537 'value3' => 'label3'
538 );
539 $this->arguments['value'] = array('value2', 'value1');
540 $this->arguments['name'] = 'myName';
541 $this->arguments['multiple'] = 'multiple';
542 $this->arguments['selectAllByDefault'] = TRUE;
543
544 $this->injectDependenciesIntoViewHelper($this->viewHelper);
545
546 $this->viewHelper->initialize();
547 $this->viewHelper->render();
548 }
549
550 /**
551 * @test
552 */
553 public function optionsContainPrependedItemWithEmptyValueIfPrependOptionLabelIsSet() {
554 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
555 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
556 $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));
557 $this->tagBuilder->expects($this->once())->method('render');
558 $this->arguments['options'] = array(
559 'value1' => 'label1',
560 'value2' => 'label2',
561 'value3' => 'label3'
562 );
563 $this->arguments['name'] = 'myName';
564 $this->arguments['prependOptionLabel'] = 'please choose';
565 $this->injectDependenciesIntoViewHelper($this->viewHelper);
566 $this->viewHelper->initialize();
567 $this->viewHelper->render();
568 }
569
570 /**
571 * @test
572 */
573 public function optionsContainPrependedItemWithCorrectValueIfPrependOptionLabelAndPrependOptionValueAreSet() {
574 $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
575 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
576 $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));
577 $this->tagBuilder->expects($this->once())->method('render');
578 $this->arguments['options'] = array(
579 'value1' => 'label1',
580 'value2' => 'label2',
581 'value3' => 'label3'
582 );
583 $this->arguments['name'] = 'myName';
584 $this->arguments['prependOptionLabel'] = 'please choose';
585 $this->arguments['prependOptionValue'] = '-1';
586 $this->injectDependenciesIntoViewHelper($this->viewHelper);
587 $this->viewHelper->initialize();
588 $this->viewHelper->render();
589 }
590
591 }