TYPO3 CMS  TYPO3_7-6
RadioViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
15 
20 {
24  protected $viewHelper;
25 
26  protected function setUp()
27  {
28  parent::setUp();
29  $this->viewHelper = $this->getAccessibleMock(RadioViewHelper::class, ['setErrorClassAttribute', 'getName', 'getValueAttribute', 'isObjectAccessorMode', 'getPropertyValue', 'registerFieldNameForFormTokenGeneration']);
30  $this->injectDependenciesIntoViewHelper($this->viewHelper);
31  $this->viewHelper->initializeArguments();
32  }
33 
38  {
39  $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, ['setTagName', 'addAttribute']);
40  $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
41  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
42  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
43  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
44  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
45 
46  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
47  $this->viewHelper->expects($this->any())->method('getValueAttribute')->will($this->returnValue('bar'));
48  $this->viewHelper->_set('tag', $mockTagBuilder);
49 
50  $this->viewHelper->initialize();
51  $this->viewHelper->render();
52  }
53 
58  {
59  $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, ['setTagName', 'addAttribute']);
60  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
61  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
62  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
63  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
64  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
65 
66  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
67  $this->viewHelper->expects($this->any())->method('getValueAttribute')->will($this->returnValue('bar'));
68  $this->viewHelper->_set('tag', $mockTagBuilder);
69 
70  $this->viewHelper->initialize();
71  $this->viewHelper->render(true);
72  }
73 
78  {
79  $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, ['setTagName', 'addAttribute']);
80  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
81  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
82  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
83 
84  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
85  $this->viewHelper->expects($this->any())->method('getValueAttribute')->will($this->returnValue('bar'));
86  $this->viewHelper->expects($this->never())->method('isObjectAccessorMode')->will($this->returnValue(true));
87  $this->viewHelper->expects($this->never())->method('getPropertyValue')->will($this->returnValue(true));
88  $this->viewHelper->_set('tag', $mockTagBuilder);
89 
90  $this->viewHelper->initialize();
91  $this->viewHelper->render(true);
92  $this->viewHelper->render(false);
93  }
94 
99  {
100  $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, ['setTagName', 'addAttribute']);
101  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
102  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
103  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
104  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
105  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
106 
107  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
108  $this->viewHelper->expects($this->any())->method('getValueAttribute')->will($this->returnValue('bar'));
109  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
110  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(true));
111  $this->viewHelper->_set('tag', $mockTagBuilder);
112 
113  $this->viewHelper->initialize();
114  $this->viewHelper->render();
115  }
116 
121  {
122  $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, ['setTagName', 'addAttribute']);
123  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
124  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
125  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
126  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
127 
128  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
129  $this->viewHelper->expects($this->any())->method('getValueAttribute')->will($this->returnValue('bar'));
130  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
131  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue([]));
132  $this->viewHelper->_set('tag', $mockTagBuilder);
133 
134  $this->viewHelper->initialize();
135  $this->viewHelper->render();
136  }
137 
142  {
143  $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, ['setTagName', 'addAttribute']);
144  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
145  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
146  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
147  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
148  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
149 
150  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
151  $this->viewHelper->expects($this->any())->method('getValueAttribute')->will($this->returnValue('bar'));
152  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
153  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue('bar'));
154  $this->viewHelper->_set('tag', $mockTagBuilder);
155 
156  $this->viewHelper->initialize();
157  $this->viewHelper->render();
158  }
159 
164  {
165  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
166  $this->viewHelper->render();
167  }
168 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)