26 $this->viewHelper = $this->getMock(
'TYPO3\\CMS\\Fluid\\ViewHelpers\\GroupedForViewHelper', array(
'renderChildren'));
28 $this->viewHelper->initializeArguments();
35 $this->assertEquals(
'', $this->viewHelper->render(NULL,
'foo',
'bar'));
42 $this->assertEquals(
'', $this->viewHelper->render(array(),
'foo',
'bar'));
50 $object = new \stdClass();
52 $this->viewHelper->render($object,
'innerVariable',
'someKey');
59 $photoshop = array(
'name' =>
'Adobe Photoshop',
'license' =>
'commercial');
60 $typo3 = array(
'name' =>
'TYPO3',
'license' =>
'GPL');
61 $office = array(
'name' =>
'Microsoft Office',
'license' =>
'commercial');
62 $drupal = array(
'name' =>
'Drupal',
'license' =>
'GPL');
63 $wordpress = array(
'name' =>
'Wordpress',
'license' =>
'GPL');
65 $products = array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office,
'drupal' => $drupal,
'wordpress' => $wordpress);
67 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey',
'commercial');
68 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'products', array(
'photoshop' => $photoshop,
'office' => $office));
69 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
70 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'products');
71 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey',
'GPL');
72 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'products', array(
'typo3' => $typo3,
'drupal' => $drupal,
'wordpress' => $wordpress));
73 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
74 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'products');
76 $this->viewHelper->render($products,
'products',
'license',
'myGroupKey');
83 $photoshop = new \ArrayObject(array(
'name' =>
'Adobe Photoshop',
'license' =>
'commercial'));
84 $typo3 = new \ArrayObject(array(
'name' =>
'TYPO3',
'license' =>
'GPL'));
85 $office = new \ArrayObject(array(
'name' =>
'Microsoft Office',
'license' =>
'commercial'));
86 $drupal = new \ArrayObject(array(
'name' =>
'Drupal',
'license' =>
'GPL'));
87 $wordpress = new \ArrayObject(array(
'name' =>
'Wordpress',
'license' =>
'GPL'));
89 $products = new \ArrayObject(array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office,
'drupal' => $drupal,
'wordpress' => $wordpress));
91 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey',
'commercial');
92 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'products', array(
'photoshop' => $photoshop,
'office' => $office));
93 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
94 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'products');
95 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey',
'GPL');
96 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'products', array(
'typo3' => $typo3,
'drupal' => $drupal,
'wordpress' => $wordpress));
97 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
98 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'products');
100 $this->viewHelper->render($products,
'products',
'license',
'myGroupKey');
107 $photoshop = new \stdClass();
108 $photoshop->name =
'Adobe Photoshop';
109 $photoshop->license =
'commercial';
110 $typo3 = new \stdClass();
111 $typo3->name =
'TYPO3';
112 $typo3->license =
'GPL';
113 $office = new \stdClass();
114 $office->name =
'Microsoft Office';
115 $office->license =
'commercial';
116 $drupal = new \stdClass();
117 $drupal->name =
'Drupal';
118 $drupal->license =
'GPL';
119 $wordpress = new \stdClass();
120 $wordpress->name =
'Wordpress';
121 $wordpress->license =
'GPL';
123 $products = array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office,
'drupal' => $drupal,
'wordpress' => $wordpress);
125 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey',
'commercial');
126 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'products', array(
'photoshop' => $photoshop,
'office' => $office));
127 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
128 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'products');
129 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey',
'GPL');
130 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'products', array(
'typo3' => $typo3,
'drupal' => $drupal,
'wordpress' => $wordpress));
131 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
132 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'products');
134 $this->viewHelper->render($products,
'products',
'license',
'myGroupKey');
141 $customer1 = new \stdClass();
142 $customer1->name =
'Anton Abel';
144 $customer2 = new \stdClass();
145 $customer2->name =
'Balthasar Bux';
147 $invoice1 = array(
'date' =>
new \DateTime(
'1980-12-13'),
'customer' => $customer1);
148 $invoice2 = array(
'date' =>
new \DateTime(
'2010-07-01'),
'customer' => $customer1);
149 $invoice3 = array(
'date' =>
new \DateTime(
'2010-07-04'),
'customer' => $customer2);
151 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
153 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey', $customer1);
154 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'invoices', array(
'invoice1' => $invoice1,
'invoice2' => $invoice2));
155 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
156 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'invoices');
157 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey', $customer2);
158 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'invoices', array(
'invoice3' => $invoice3));
159 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
160 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'invoices');
162 $this->viewHelper->render($invoices,
'invoices',
'customer',
'myGroupKey');
168 public function renderGroupsMultidimensionalArrayByPropertyPath() {
169 $customer1 = new \stdClass();
170 $customer1->name =
'Anton Abel';
172 $customer2 = new \stdClass();
173 $customer2->name =
'Balthasar Bux';
175 $invoice1 = new \stdClass();
176 $invoice1->customer = $customer1;
178 $invoice2 = new \stdClass();
179 $invoice2->customer = $customer1;
181 $invoice3 = new \stdClass();
182 $invoice3->customer = $customer2;
184 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
185 $groupBy =
'customer.name';
187 $accessibleMock = $this->
getAccessibleMock(
'TYPO3\\CMS\\Fluid\\ViewHelpers\\GroupedForViewHelper', array(
'dummy'));
188 $expectedResult = array(
190 'Anton Abel' =>
'Anton Abel',
191 'Balthasar Bux' =>
'Balthasar Bux' 194 'Anton Abel' => array(
195 'invoice1' => $invoice1,
196 'invoice2' => $invoice2
198 'Balthasar Bux' => array(
199 'invoice3' => $invoice3
203 $this->assertSame($expectedResult, $accessibleMock->_callRef(
'groupElements', $invoices, $groupBy));
210 $customer1 = new \stdClass();
211 $customer1->name =
'Anton Abel';
213 $customer2 = new \stdClass();
214 $customer2->name =
'Balthasar Bux';
216 $invoice1 = new \stdClass();
217 $invoice1->date = new \DateTime(
'1980-12-13');
218 $invoice1->customer = $customer1;
220 $invoice2 = new \stdClass();
221 $invoice2->date = new \DateTime(
'2010-07-01');
222 $invoice2->customer = $customer1;
224 $invoice3 = new \stdClass();
225 $invoice3->date = new \DateTime(
'2010-07-04');
226 $invoice3->customer = $customer2;
228 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
230 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey', $customer1);
231 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'invoices', array(
'invoice1' => $invoice1,
'invoice2' => $invoice2));
232 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
233 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'invoices');
234 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey', $customer2);
235 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'invoices', array(
'invoice3' => $invoice3));
236 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
237 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'invoices');
239 $this->viewHelper->render($invoices,
'invoices',
'customer',
'myGroupKey');
247 $date1 = new \DateTime(
'2010-07-01');
248 $date2 = new \DateTime(
'2010-07-04');
250 $invoice1 = new \stdClass();
251 $invoice1->date = $date1;
252 $invoice1->id = 12340;
254 $invoice2 = new \stdClass();
255 $invoice2->date = $date1;
256 $invoice2->id = 12341;
258 $invoice3 = new \stdClass();
259 $invoice3->date = $date2;
260 $invoice3->id = 12342;
262 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
264 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey', $date1);
265 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'invoices', array(
'invoice1' => $invoice1,
'invoice2' => $invoice2));
266 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
267 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'invoices');
268 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey', $date2);
269 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'invoices', array(
'invoice3' => $invoice3));
270 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
271 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'invoices');
273 $this->viewHelper->render($invoices,
'invoices',
'date',
'myGroupKey');
280 $photoshop = array(
'name' =>
'Adobe Photoshop',
'license' =>
'commercial');
281 $typo3 = array(
'name' =>
'TYPO3',
'license' =>
'GPL');
282 $office = array(
'name' =>
'Microsoft Office',
'license' =>
'commercial');
284 $products = array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office);
286 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'groupKey', NULL);
287 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'innerKey', $products);
288 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'groupKey');
289 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'innerKey');
291 $this->viewHelper->render($products,
'innerKey',
'NonExistingKey');
299 $values = array(
'some',
'simple',
'array');
301 $this->viewHelper->render($values,
'innerVariable',
'someKey');
renderGroupsArrayOfObjectsAndPreservesKeys()
renderReturnsEmptyStringIfObjectIsEmptyArray()
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
renderGroupsMultidimensionalObjectByObjectKey()
renderGroupsMultidimensionalArrayByObjectKey()
renderGroupsMultidimensionalObjectByDateTimeObject()
renderThrowsExceptionWhenPassingObjectsToEachThatAreNotTraversable()
renderReturnsEmptyStringIfObjectIsNull()
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
groupingByAKeyThatDoesNotExistCreatesASingleGroup()
renderGroupsMultidimensionalArrayObjectAndPreservesKeys()
renderGroupsMultidimensionalArrayAndPreservesKeys()
renderThrowsExceptionWhenPassingOneDimensionalArraysToEach()