2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
27 $this->viewHelper = $this->getMock(\TYPO3\CMS\
Fluid\ViewHelpers\GroupedForViewHelper::class, array(
'renderChildren'));
29 $this->viewHelper->initializeArguments();
37 $this->assertEquals(
'', $this->viewHelper->render(null,
'foo',
'bar'));
45 $this->assertEquals(
'', $this->viewHelper->render(array(),
'foo',
'bar'));
54 $object = new \stdClass();
56 $this->viewHelper->render($object,
'innerVariable',
'someKey');
64 $photoshop = array(
'name' =>
'Adobe Photoshop',
'license' =>
'commercial');
65 $typo3 = array(
'name' =>
'TYPO3',
'license' =>
'GPL');
66 $office = array(
'name' =>
'Microsoft Office',
'license' =>
'commercial');
67 $drupal = array(
'name' =>
'Drupal',
'license' =>
'GPL');
68 $wordpress = array(
'name' =>
'Wordpress',
'license' =>
'GPL');
70 $products = array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office,
'drupal' => $drupal,
'wordpress' => $wordpress);
72 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey',
'commercial');
73 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'products', array(
'photoshop' => $photoshop,
'office' => $office));
74 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
75 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'products');
76 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey',
'GPL');
77 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'products', array(
'typo3' => $typo3,
'drupal' => $drupal,
'wordpress' => $wordpress));
78 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
79 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'products');
81 $this->viewHelper->render($products,
'products',
'license',
'myGroupKey');
89 $photoshop = new \ArrayObject(array(
'name' =>
'Adobe Photoshop',
'license' =>
'commercial'));
90 $typo3 = new \ArrayObject(array(
'name' =>
'TYPO3',
'license' =>
'GPL'));
91 $office = new \ArrayObject(array(
'name' =>
'Microsoft Office',
'license' =>
'commercial'));
92 $drupal = new \ArrayObject(array(
'name' =>
'Drupal',
'license' =>
'GPL'));
93 $wordpress = new \ArrayObject(array(
'name' =>
'Wordpress',
'license' =>
'GPL'));
95 $products = new \ArrayObject(array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office,
'drupal' => $drupal,
'wordpress' => $wordpress));
97 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey',
'commercial');
98 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'products', array(
'photoshop' => $photoshop,
'office' => $office));
99 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
100 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'products');
101 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey',
'GPL');
102 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'products', array(
'typo3' => $typo3,
'drupal' => $drupal,
'wordpress' => $wordpress));
103 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
104 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'products');
106 $this->viewHelper->render($products,
'products',
'license',
'myGroupKey');
114 $photoshop = new \stdClass();
115 $photoshop->name =
'Adobe Photoshop';
116 $photoshop->license =
'commercial';
117 $typo3 = new \stdClass();
118 $typo3->name =
'TYPO3';
119 $typo3->license =
'GPL';
120 $office = new \stdClass();
121 $office->name =
'Microsoft Office';
122 $office->license =
'commercial';
123 $drupal = new \stdClass();
124 $drupal->name =
'Drupal';
125 $drupal->license =
'GPL';
126 $wordpress = new \stdClass();
127 $wordpress->name =
'Wordpress';
128 $wordpress->license =
'GPL';
130 $products = array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office,
'drupal' => $drupal,
'wordpress' => $wordpress);
132 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey',
'commercial');
133 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'products', array(
'photoshop' => $photoshop,
'office' => $office));
134 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
135 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'products');
136 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey',
'GPL');
137 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'products', array(
'typo3' => $typo3,
'drupal' => $drupal,
'wordpress' => $wordpress));
138 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
139 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'products');
141 $this->viewHelper->render($products,
'products',
'license',
'myGroupKey');
149 $customer1 = new \stdClass();
150 $customer1->name =
'Anton Abel';
152 $customer2 = new \stdClass();
153 $customer2->name =
'Balthasar Bux';
155 $invoice1 = array(
'date' =>
new \DateTime(
'1980-12-13'),
'customer' => $customer1);
156 $invoice2 = array(
'date' =>
new \DateTime(
'2010-07-01'),
'customer' => $customer1);
157 $invoice3 = array(
'date' =>
new \DateTime(
'2010-07-04'),
'customer' => $customer2);
159 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
161 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey', $customer1);
162 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'invoices', array(
'invoice1' => $invoice1,
'invoice2' => $invoice2));
163 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
164 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'invoices');
165 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey', $customer2);
166 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'invoices', array(
'invoice3' => $invoice3));
167 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
168 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'invoices');
170 $this->viewHelper->render($invoices,
'invoices',
'customer',
'myGroupKey');
176 public function renderGroupsMultidimensionalArrayByPropertyPath()
178 $customer1 = new \stdClass();
179 $customer1->name =
'Anton Abel';
181 $customer2 = new \stdClass();
182 $customer2->name =
'Balthasar Bux';
184 $invoice1 = new \stdClass();
185 $invoice1->customer = $customer1;
187 $invoice2 = new \stdClass();
188 $invoice2->customer = $customer1;
190 $invoice3 = new \stdClass();
191 $invoice3->customer = $customer2;
193 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
194 $groupBy =
'customer.name';
196 $accessibleMock = $this->getAccessibleMock(\TYPO3\CMS\
Fluid\ViewHelpers\GroupedForViewHelper::class, array(
'dummy'));
197 $expectedResult = array(
199 'Anton Abel' =>
'Anton Abel',
200 'Balthasar Bux' =>
'Balthasar Bux'
203 'Anton Abel' => array(
204 'invoice1' => $invoice1,
205 'invoice2' => $invoice2
207 'Balthasar Bux' => array(
208 'invoice3' => $invoice3
212 $this->assertSame($expectedResult, $accessibleMock->_callRef(
'groupElements', $invoices, $groupBy));
220 $customer1 = new \stdClass();
221 $customer1->name =
'Anton Abel';
223 $customer2 = new \stdClass();
224 $customer2->name =
'Balthasar Bux';
226 $invoice1 = new \stdClass();
227 $invoice1->date = new \DateTime(
'1980-12-13');
228 $invoice1->customer = $customer1;
230 $invoice2 = new \stdClass();
231 $invoice2->date = new \DateTime(
'2010-07-01');
232 $invoice2->customer = $customer1;
234 $invoice3 = new \stdClass();
235 $invoice3->date = new \DateTime(
'2010-07-04');
236 $invoice3->customer = $customer2;
238 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
240 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey', $customer1);
241 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'invoices', array(
'invoice1' => $invoice1,
'invoice2' => $invoice2));
242 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
243 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'invoices');
244 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey', $customer2);
245 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'invoices', array(
'invoice3' => $invoice3));
246 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
247 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'invoices');
249 $this->viewHelper->render($invoices,
'invoices',
'customer',
'myGroupKey');
257 $date1 = new \DateTime(
'2010-07-01');
258 $date2 = new \DateTime(
'2010-07-04');
260 $invoice1 = new \stdClass();
261 $invoice1->date = $date1;
262 $invoice1->id = 12340;
264 $invoice2 = new \stdClass();
265 $invoice2->date = $date1;
266 $invoice2->id = 12341;
268 $invoice3 = new \stdClass();
269 $invoice3->date = $date2;
270 $invoice3->id = 12342;
272 $invoices = array(
'invoice1' => $invoice1,
'invoice2' => $invoice2,
'invoice3' => $invoice3);
274 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'myGroupKey', $date1);
275 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'invoices', array(
'invoice1' => $invoice1,
'invoice2' => $invoice2));
276 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'myGroupKey');
277 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'invoices');
278 $this->templateVariableContainer->expects($this->at(4))->method(
'add')->with(
'myGroupKey', $date2);
279 $this->templateVariableContainer->expects($this->at(5))->method(
'add')->with(
'invoices', array(
'invoice3' => $invoice3));
280 $this->templateVariableContainer->expects($this->at(6))->method(
'remove')->with(
'myGroupKey');
281 $this->templateVariableContainer->expects($this->at(7))->method(
'remove')->with(
'invoices');
283 $this->viewHelper->render($invoices,
'invoices',
'date',
'myGroupKey');
291 $photoshop = array(
'name' =>
'Adobe Photoshop',
'license' =>
'commercial');
292 $typo3 = array(
'name' =>
'TYPO3',
'license' =>
'GPL');
293 $office = array(
'name' =>
'Microsoft Office',
'license' =>
'commercial');
295 $products = array(
'photoshop' => $photoshop,
'typo3' => $typo3,
'office' => $office);
297 $this->templateVariableContainer->expects($this->at(0))->method(
'add')->with(
'groupKey', null);
298 $this->templateVariableContainer->expects($this->at(1))->method(
'add')->with(
'innerKey', $products);
299 $this->templateVariableContainer->expects($this->at(2))->method(
'remove')->with(
'groupKey');
300 $this->templateVariableContainer->expects($this->at(3))->method(
'remove')->with(
'innerKey');
302 $this->viewHelper->render($products,
'innerKey',
'NonExistingKey');
311 $values = array(
'some',
'simple',
'array');
313 $this->viewHelper->render($values,
'innerVariable',
'someKey');