Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassActionTest.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class MassActionTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $contextMock;
21 
25  protected $objectManager;
26 
30  protected function setUp()
31  {
32  $this->objectManager = new ObjectManager($this);
33 
34  $this->contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
35  ->getMockForAbstractClass();
36  }
37 
43  public function testGetComponentName()
44  {
45  $this->contextMock->expects($this->never())->method('getProcessor');
47  $massAction = $this->objectManager->getObject(
48  \Magento\Ui\Component\MassAction::class,
49  [
50  'context' => $this->contextMock,
51  'data' => []
52  ]
53  );
54 
55  $this->assertTrue($massAction->getComponentName() === MassAction::NAME);
56  }
57 
66  public function testPrepare($componentName, $componentData)
67  {
68  $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
69  ->disableOriginalConstructor()
70  ->getMock();
71  $this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($processor);
73  $action = $this->objectManager->getObject(
74  \Magento\Ui\Component\MassAction::class,
75  [
76  'context' => $this->contextMock,
77  'data' => [
78  'name' => $componentName,
79  'config' => $componentData,
80  ]
81  ]
82  );
84  $massAction = $this->objectManager->getObject(
85  \Magento\Ui\Component\MassAction::class,
86  [
87  'context' => $this->contextMock,
88  'data' => []
89  ]
90  );
91  $massAction->addComponent('action', $action);
92  $massAction->prepare();
93  $this->assertEquals(['actions' => [$action->getConfiguration()]], $massAction->getConfiguration());
94  }
95 
99  public function getPrepareDataProvider()
100  {
101  return [
102  [
103  'test_component1',
104  [
105  'type' => 'first_action',
106  'label' => 'First Action',
107  'url' => '/module/controller/firstAction'
108  ],
109  ],
110  [
111  'test_component2',
112  [
113  'type' => 'second_action',
114  'label' => 'Second Action',
115  'actions' => [
116  [
117  'type' => 'second_sub_action1',
118  'label' => 'Second Sub Action 1',
119  'url' => '/module/controller/secondSubAction1'
120  ],
121  [
122  'type' => 'second_sub_action2',
123  'label' => 'Second Sub Action 2',
124  'url' => '/module/controller/secondSubAction2'
125  ],
126  ]
127  ],
128  ],
129  ];
130  }
131 }
$processor
Definition: 404.php:10