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