2 declare(strict_types = 1);
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
33 protected function setUp(): void
36 $this->viewHelper = $this->getMockBuilder(OptionViewHelper::class)
37 ->setMethods([
'isValueSelected',
'registerFieldNameForFormTokenGeneration',
'renderChildren'])
39 $this->arguments[
'selected'] =
null;
40 $this->arguments[
'value'] =
null;
41 $this->tagBuilder =
new TagBuilder();
42 $this->viewHelper->setTagBuilder($this->tagBuilder);
43 $this->injectDependenciesIntoViewHelper($this->viewHelper);
51 $tagBuilder = $this->createMock(TagBuilder::class);
52 $tagBuilder->expects($this->atLeastOnce())->method(
'setTagName')->with(
'option');
53 $this->viewHelper->setTagBuilder($tagBuilder);
54 $this->viewHelper->initializeArgumentsAndRender();
62 $this->viewHelper->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'Option Label'));
63 $expected =
'<option value="Option Label">Option Label</option>';
64 $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
72 $this->arguments[
'value'] =
'value';
73 $this->viewHelper->setArguments($this->arguments);
74 $this->viewHelper->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'Option Label'));
75 $expected =
'<option value="value">Option Label</option>';
76 $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
84 $this->arguments[
'selected'] =
null;
85 $this->viewHelper->setArguments($this->arguments);
87 $this->viewHelper->expects($this->once())->method(
'isValueSelected')->will($this->returnValue(
true));
88 $this->viewHelper->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'Option Label'));
90 $expected =
'<option selected="selected" value="Option Label">Option Label</option>';
91 $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
99 $this->arguments[
'selected'] =
null;
100 $this->viewHelper->setArguments($this->arguments);
102 $this->viewHelper->expects($this->once())->method(
'isValueSelected')->will($this->returnValue(
false));
103 $this->viewHelper->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'Option Label'));
105 $expected =
'<option value="Option Label">Option Label</option>';
106 $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
114 $this->arguments[
'selected'] =
false;
115 $this->viewHelper->setArguments($this->arguments);
116 $this->viewHelper->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'Option Label'));
118 $expected =
'<option value="Option Label">Option Label</option>';
119 $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
127 $this->arguments[
'selected'] =
true;
128 $this->viewHelper->setArguments($this->arguments);
129 $this->viewHelper->expects($this->once())->method(
'renderChildren')->will($this->returnValue(
'Option Label'));
131 $expected =
'<option selected="selected" value="Option Label">Option Label</option>';
132 $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());