TYPO3 CMS  TYPO3_6-2
CheckboxViewHelperTest.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\\CheckboxViewHelper', array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue', 'registerFieldNameForFormTokenGeneration'));
27  $this->arguments['property'] = '';
28  $this->injectDependenciesIntoViewHelper($this->viewHelper);
29  $this->viewHelper->initializeArguments();
30  }
31 
36  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
37  $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
38  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
39  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
40  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
41  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
42 
43  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
44  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
45  $this->viewHelper->_set('tag', $mockTagBuilder);
46 
47  $this->viewHelper->initialize();
48  $this->viewHelper->render();
49  }
50 
55  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
56  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
57  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', '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', 'checkbox');
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->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
81  $this->viewHelper->expects($this->any())->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', 'checkbox');
95  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
96  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
97  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
98 
99  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
100  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
101  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
102  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(TRUE));
103  $this->viewHelper->_set('tag', $mockTagBuilder);
104 
105  $this->viewHelper->initialize();
106  $this->viewHelper->render();
107  }
108 
113  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
114  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
115  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo[]');
116  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo[]');
117  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
118 
119  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
120  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
121  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
122  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array()));
123  $this->viewHelper->_set('tag', $mockTagBuilder);
124 
125  $this->viewHelper->initialize();
126  $this->viewHelper->render();
127  }
128 
133  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute'));
134  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
135  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo[]');
136  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
137  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
138 
139  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
140  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
141  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
142  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array('foo', 'bar', 'baz')));
143  $this->viewHelper->_set('tag', $mockTagBuilder);
144 
145  $this->viewHelper->initialize();
146  $this->viewHelper->render();
147  }
148 
153  $mockTagBuilder = $this->getMock('TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder', array('setTagName', 'addAttribute'));
154  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
155  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo[]');
156  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
157  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
158 
159  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
160  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
161  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
162  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(new \ArrayObject(array('foo', 'bar', 'baz'))));
163  $this->viewHelper->_set('tag', $mockTagBuilder);
164 
165  $this->viewHelper->initialize();
166  $this->viewHelper->render();
167  }
168 
173  $mockTagBuilder = $this->getMock('TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder', array('setTagName', 'addAttribute'));
174  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
175  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
176  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
177  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
178 
179  $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
180  $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
181  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
182  $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(new \stdClass()));
183  $this->viewHelper->_set('tag', $mockTagBuilder);
184 
185  $this->viewHelper->initialize();
186  $this->viewHelper->render();
187  }
188 
193  $mockTagBuilder = $this->getMock('TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder', array('setTagName', 'addAttribute'));
194  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
195  $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo[]');
196  $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 2);
197  $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
198 
199  $object1 = new \stdClass();
200  $object2 = new \stdClass();
201  $object3 = new \stdClass();
202 
203  $this->viewHelper->expects($this->any())->method('getName')->willReturn('foo');
204  $this->viewHelper->expects($this->any())->method('getValue')->willReturn(2);
205  $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->willReturn(TRUE);
206  $this->viewHelper->expects($this->any())->method('getPropertyValue')->willReturn(array($object1, $object2, $object3));
207  $this->viewHelper->_set('tag', $mockTagBuilder);
208 
209  $mockPersistenceManager = $this->getMock('TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface');
210  $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValueMap(array(
211  array($object1, 1),
212  array($object2, 2),
213  array($object3, 3),
214  )));
215  $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
216 
217  $this->viewHelper->initialize();
218  $this->viewHelper->render();
219  }
220 
225  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
226  $this->viewHelper->render();
227  }
228 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)