TYPO3 CMS  TYPO3_6-2
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 
18 
22  protected $viewHelper;
23 
24  public function setUp() {
25  parent::setUp();
26  $this->viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\RadioViewHelper', array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue', 'registerFieldNameForFormTokenGeneration'));
27  $this->injectDependenciesIntoViewHelper($this->viewHelper);
28  $this->viewHelper->initializeArguments();
29  }
30 
35  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
36  $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
37  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
38  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
39  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
40  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
41 
42  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
43  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
44  $this->viewHelper->_set('tag', $mockTagBuilder);
45 
46  $this->viewHelper->initialize();
47  $this->viewHelper->render();
48  }
49 
54  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
55  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
56  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
57  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
58  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
59  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
60 
61  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
62  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
63  $this->viewHelper->_set('tag', $mockTagBuilder);
64 
65  $this->viewHelper->initialize();
66  $this->viewHelper->render(TRUE);
67  }
68 
73  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
74  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
75  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
76  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
77 
78  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
79  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
80  $this->viewHelper->expects($this->never())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
81  $this->viewHelper->expects($this->never())->method('getPropertyValue')->will($this->returnValue(TRUE));
82  $this->viewHelper->_set('tag', $mockTagBuilder);
83 
84  $this->viewHelper->initialize();
85  $this->viewHelper->render(TRUE);
86  $this->viewHelper->render(FALSE);
87  }
88 
93  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
94  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
95  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
96  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
97  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
98  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
99 
100  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
101  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
102  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
103  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(TRUE));
104  $this->viewHelper->_set('tag', $mockTagBuilder);
105 
106  $this->viewHelper->initialize();
107  $this->viewHelper->render();
108  }
109 
114  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
115  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
116  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
117  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
118  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
119 
120  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
121  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
122  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
123  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array()));
124  $this->viewHelper->_set('tag', $mockTagBuilder);
125 
126  $this->viewHelper->initialize();
127  $this->viewHelper->render();
128  }
129 
134  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
135  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
136  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
137  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
138  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
139  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
140 
141  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
142  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
143  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
144  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue('bar'));
145  $this->viewHelper->_set('tag', $mockTagBuilder);
146 
147  $this->viewHelper->initialize();
148  $this->viewHelper->render();
149  }
150 
155  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
156  $this->viewHelper->render();
157  }
158 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)