Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassactionKeyTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class MassactionKeyTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $plugin;
18 
22  protected $requestMock;
23 
27  protected $subjectMock;
28 
29  protected function setUp()
30  {
31  $this->closureMock = function () {
32  return 'Expected';
33  };
34  $this->subjectMock = $this->createMock(\Magento\Backend\App\AbstractAction::class);
35  $this->requestMock = $this->getMockForAbstractClass(
36  RequestInterface::class,
37  [],
38  '',
39  false,
40  false,
41  true,
42  ['getPost', 'setPostValue']
43  );
44 
45  $objectManager = new ObjectManager($this);
46  $this->plugin = $objectManager->getObject(
47  \Magento\Backend\App\Action\Plugin\MassactionKey::class,
48  [
49  'subject' => $this->subjectMock,
50  'request' => $this->requestMock,
51  ]
52  );
53  }
54 
61  {
62  $this->requestMock->expects($this->at(0))
63  ->method('getPost')
64  ->with('massaction_prepare_key')
65  ->will($this->returnValue('key'));
66  $this->requestMock->expects($this->at(1))
67  ->method('getPost')
68  ->with('key')
69  ->will($this->returnValue($postData));
70  $this->requestMock->expects($this->once())
71  ->method('setPostValue')
72  ->with('key', $convertedData);
73 
74  $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
75  }
76 
80  public function beforeDispatchDataProvider()
81  {
82  return [
83  'post_data_is_array' => [['key'], ['key']],
84  'post_data_is_string' => ['key, key_two', ['key', ' key_two']]
85  ];
86  }
87 
89  {
90  $this->requestMock->expects($this->once())
91  ->method('getPost')
92  ->with('massaction_prepare_key')
93  ->will($this->returnValue(false));
94  $this->requestMock->expects($this->never())
95  ->method('setPostValue');
96 
97  $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
98  }
99 }
$objectManager
Definition: bootstrap.php:17
testBeforeDispatchWhenMassactionPrepareKeyRequestExists($postData, $convertedData)