|
8 | 8 | use Magento\Framework\Api\Search\DocumentInterface;
|
9 | 9 | use Magento\Framework\Locale\ResolverInterface;
|
10 | 10 | use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
| 11 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
11 | 12 | use Magento\Framework\View\Element\UiComponentInterface;
|
12 | 13 | use Magento\Ui\Component\Listing\Columns;
|
13 | 14 | use Magento\Ui\Component\Listing\Columns\Column;
|
14 | 15 | use Magento\Ui\Component\MassAction\Filter;
|
15 | 16 | use Magento\Ui\Model\Export\MetadataProvider;
|
16 |
| -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
17 | 17 |
|
18 | 18 | /**
|
19 | 19 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
@@ -76,8 +76,10 @@ protected function setUp()
|
76 | 76 | /**
|
77 | 77 | * @param array $columnLabels
|
78 | 78 | * @param array $expected
|
| 79 | + * |
79 | 80 | * @return void
|
80 | 81 | * @dataProvider getColumnsDataProvider
|
| 82 | + * @throws \Exception |
81 | 83 | */
|
82 | 84 | public function testGetHeaders(array $columnLabels, array $expected): void
|
83 | 85 | {
|
@@ -156,11 +158,11 @@ protected function prepareColumns(
|
156 | 158 | $component->expects($this->any())
|
157 | 159 | ->method('getName')
|
158 | 160 | ->willReturn($componentName);
|
159 |
| - $component->expects($this->once()) |
| 161 | + $component->expects($this->atLeastOnce()) |
160 | 162 | ->method('getChildComponents')
|
161 | 163 | ->willReturn([$columns]);
|
162 | 164 |
|
163 |
| - $columns->expects($this->once()) |
| 165 | + $columns->expects($this->atLeastOnce()) |
164 | 166 | ->method('getChildComponents')
|
165 | 167 | ->willReturn([$column, $columnActions]);
|
166 | 168 |
|
@@ -267,52 +269,110 @@ public function getRowDataProvider()
|
267 | 269 | * @param string $filter
|
268 | 270 | * @param array $options
|
269 | 271 | * @param array $expected
|
| 272 | + * |
270 | 273 | * @dataProvider getOptionsDataProvider
|
| 274 | + * @throws \Magento\Framework\Exception\LocalizedException |
271 | 275 | */
|
272 | 276 | public function testGetOptions($filter, $options, $expected)
|
273 | 277 | {
|
| 278 | + $component = $this->prepareColumnsWithOptions($filter, $options); |
| 279 | + |
| 280 | + $this->filter->expects($this->exactly(2)) |
| 281 | + ->method('getComponent') |
| 282 | + ->willReturn($component); |
| 283 | + |
| 284 | + $result = $this->model->getOptions(); |
| 285 | + $this->assertTrue(is_array($result)); |
| 286 | + $this->assertCount(1, $result); |
| 287 | + $this->assertEquals($expected, $result); |
| 288 | + } |
| 289 | + |
| 290 | + /** |
| 291 | + * @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject |
| 292 | + */ |
| 293 | + protected function prepareColumnsWithOptions(string $filter, array $options) |
| 294 | + { |
| 295 | + /** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */ |
274 | 296 | $component = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
|
275 |
| - ->getMockForAbstractClass(); |
| 297 | + ->getMockForAbstractClass(); |
276 | 298 |
|
277 |
| - $childComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class) |
278 |
| - ->getMockForAbstractClass(); |
| 299 | + $listingTopComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class) |
| 300 | + ->getMockForAbstractClass(); |
279 | 301 |
|
280 | 302 | $filters = $this->getMockBuilder(\Magento\Ui\Component\Filters::class)
|
281 |
| - ->disableOriginalConstructor() |
282 |
| - ->getMock(); |
| 303 | + ->disableOriginalConstructor() |
| 304 | + ->getMock(); |
283 | 305 |
|
284 |
| - $select = $this->getMockBuilder(\Magento\Ui\Component\Filters\Type\Select::class) |
285 |
| - ->disableOriginalConstructor() |
286 |
| - ->getMock(); |
| 306 | + /** @var Columns|\PHPUnit_Framework_MockObject_MockObject $columns */ |
| 307 | + $columns = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns::class) |
| 308 | + ->disableOriginalConstructor() |
| 309 | + ->getMock(); |
287 | 310 |
|
288 |
| - $this->filter->expects($this->once()) |
289 |
| - ->method('getComponent') |
290 |
| - ->willReturn($component); |
| 311 | + /** @var Column|\PHPUnit_Framework_MockObject_MockObject $column */ |
| 312 | + $column = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\Column::class) |
| 313 | + ->disableOriginalConstructor() |
| 314 | + ->getMock(); |
| 315 | + /** @var Column|\PHPUnit_Framework_MockObject_MockObject $columnActions */ |
| 316 | + $columnActions = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\Column::class) |
| 317 | + ->disableOriginalConstructor() |
| 318 | + ->getMock(); |
291 | 319 |
|
292 |
| - $component->expects($this->once()) |
293 |
| - ->method('getChildComponents') |
294 |
| - ->willReturn(['listing_top' => $childComponent]); |
| 320 | + $component->expects($this->any()) |
| 321 | + ->method('getName') |
| 322 | + ->willReturn('columns_component_name'); |
| 323 | + $component->expects($this->atLeastOnce()) |
| 324 | + ->method('getChildComponents') |
| 325 | + ->willReturn(['columns' => $columns, 'listing_top' => $listingTopComponent]); |
295 | 326 |
|
296 |
| - $childComponent->expects($this->once()) |
297 |
| - ->method('getChildComponents') |
298 |
| - ->willReturn([$filters]); |
| 327 | + $listingTopComponent->expects($this->once()) |
| 328 | + ->method('getChildComponents') |
| 329 | + ->willReturn([$filters]); |
| 330 | + |
| 331 | + $select = $this->getMockBuilder(\Magento\Ui\Component\Filters\Type\Select::class) |
| 332 | + ->disableOriginalConstructor() |
| 333 | + ->getMock(); |
299 | 334 |
|
300 | 335 | $filters->expects($this->once())
|
301 |
| - ->method('getChildComponents') |
302 |
| - ->willReturn([$select]); |
| 336 | + ->method('getChildComponents') |
| 337 | + ->willReturn([$select]); |
303 | 338 |
|
304 | 339 | $select->expects($this->any())
|
305 |
| - ->method('getName') |
306 |
| - ->willReturn($filter); |
| 340 | + ->method('getName') |
| 341 | + ->willReturn($filter); |
307 | 342 | $select->expects($this->any())
|
308 |
| - ->method('getData') |
309 |
| - ->with('config/options') |
310 |
| - ->willReturn($options); |
| 343 | + ->method('getData') |
| 344 | + ->with('config/options') |
| 345 | + ->willReturn($options); |
311 | 346 |
|
312 |
| - $result = $this->model->getOptions(); |
313 |
| - $this->assertTrue(is_array($result)); |
314 |
| - $this->assertCount(1, $result); |
315 |
| - $this->assertEquals($expected, $result); |
| 347 | + $columns->expects($this->atLeastOnce()) |
| 348 | + ->method('getChildComponents') |
| 349 | + ->willReturn([$column, $columnActions]); |
| 350 | + |
| 351 | + $column->expects($this->any()) |
| 352 | + ->method('getName') |
| 353 | + ->willReturn('column_name'); |
| 354 | + $column->expects($this->any()) |
| 355 | + ->method('getData') |
| 356 | + ->willReturnMap( |
| 357 | + [ |
| 358 | + ['config/label', null, 'column_label'], |
| 359 | + ['config/dataType', null, 'data_type'], |
| 360 | + ] |
| 361 | + ); |
| 362 | + |
| 363 | + $columnActions->expects($this->any()) |
| 364 | + ->method('getName') |
| 365 | + ->willReturn('column_actions_name'); |
| 366 | + $columnActions->expects($this->any()) |
| 367 | + ->method('getData') |
| 368 | + ->willReturnMap( |
| 369 | + [ |
| 370 | + ['config/label', null, 'column_actions_label'], |
| 371 | + ['config/dataType', null, 'actions'], |
| 372 | + ] |
| 373 | + ); |
| 374 | + |
| 375 | + return $component; |
316 | 376 | }
|
317 | 377 |
|
318 | 378 | /**
|
|
0 commit comments