6
6
*/
7
7
namespace Magento \Catalog \Test \Unit \Controller \Adminhtml \Product ;
8
8
9
+ use Magento \Ui \Component \MassAction \Filter ;
10
+ use Magento \Backend \Model \View \Result \Redirect ;
11
+ use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
12
+ use Magento \Catalog \Controller \Adminhtml \Product \Builder ;
13
+ use Magento \Framework \Data \Collection \AbstractDb ;
14
+ use Magento \Catalog \Model \Product \Action ;
15
+
16
+ /**
17
+ * Class MassStatusTest
18
+ *
19
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
+ */
9
21
class MassStatusTest extends \Magento \Catalog \Test \Unit \Controller \Adminhtml \ProductTest
10
22
{
11
23
/**
12
- * @var \PHPUnit_Framework_MockObject_MockObject
24
+ * @var Processor| \PHPUnit_Framework_MockObject_MockObject
13
25
*/
14
- protected $ priceProcessor ;
26
+ private $ priceProcessorMock ;
15
27
16
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\View\Result\Redirect */
17
- protected $ resultRedirect ;
28
+ /**
29
+ * @var Redirect|\PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ private $ resultRedirectMock ;
32
+
33
+ /**
34
+ * @var Filter|\PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ private $ filterMock ;
37
+
38
+ /**
39
+ * @var Builder|\PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ private $ productBuilderMock ;
42
+
43
+ /**
44
+ * @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject
45
+ */
46
+ private $ abstractDbMock ;
47
+
48
+ /**
49
+ * @var Action|\PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ private $ actionMock ;
18
52
19
53
protected function setUp ()
20
54
{
21
- $ this ->priceProcessor = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Indexer \ Product \ Price \ Processor::class)
55
+ $ this ->priceProcessorMock = $ this ->getMockBuilder (Processor::class)
22
56
->disableOriginalConstructor ()->getMock ();
57
+ $ this ->productBuilderMock = $ this ->getMockBuilder (Builder::class)
58
+ ->setMethods (['build ' ])
59
+ ->disableOriginalConstructor ()
60
+ ->getMock ();
23
61
24
- $ productBuilder = $ this ->getMockBuilder (
25
- \Magento \Catalog \Controller \Adminhtml \Product \Builder::class
26
- )->setMethods (['build ' ])->disableOriginalConstructor ()->getMock ();
27
-
28
- $ product = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)->disableOriginalConstructor ()
29
- ->setMethods (['getTypeId ' , 'getStoreId ' , '__sleep ' , '__wakeup ' ])->getMock ();
30
- $ product ->expects ($ this ->any ())->method ('getTypeId ' )->will ($ this ->returnValue ('simple ' ));
31
- $ product ->expects ($ this ->any ())->method ('getStoreId ' )->will ($ this ->returnValue ('1 ' ));
32
- $ productBuilder ->expects ($ this ->any ())->method ('build ' )->will ($ this ->returnValue ($ product ));
62
+ $ productMock = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
63
+ ->disableOriginalConstructor ()
64
+ ->setMethods (['getTypeId ' , 'getStoreId ' , '__sleep ' , '__wakeup ' ])
65
+ ->getMock ();
66
+ $ productMock ->expects ($ this ->any ())
67
+ ->method ('getTypeId ' )
68
+ ->willReturn ('simple ' );
69
+ $ productMock ->expects ($ this ->any ())
70
+ ->method ('getStoreId ' )
71
+ ->willReturn ('1 ' );
72
+ $ this ->productBuilderMock ->expects ($ this ->any ())
73
+ ->method ('build ' )
74
+ ->willReturn ($ productMock );
33
75
34
- $ this ->resultRedirect = $ this ->getMockBuilder (\Magento \Backend \Model \View \Result \Redirect::class)
76
+ $ this ->resultRedirectMock = $ this ->getMockBuilder (\Magento \Backend \Model \View \Result \Redirect::class)
35
77
->disableOriginalConstructor ()
36
78
->getMock ();
37
79
$ resultFactory = $ this ->getMockBuilder (\Magento \Framework \Controller \ResultFactory::class)
@@ -41,47 +83,71 @@ protected function setUp()
41
83
$ resultFactory ->expects ($ this ->atLeastOnce ())
42
84
->method ('create ' )
43
85
->with (\Magento \Framework \Controller \ResultFactory::TYPE_REDIRECT )
44
- ->willReturn ($ this ->resultRedirect );
86
+ ->willReturn ($ this ->resultRedirectMock );
45
87
46
- $ abstractDbMock = $ this ->getMockBuilder (\ Magento \ Framework \ Data \ Collection \ AbstractDb::class)
88
+ $ this -> abstractDbMock = $ this ->getMockBuilder (AbstractDb::class)
47
89
->disableOriginalConstructor ()
48
90
->setMethods (['getAllIds ' , 'getResource ' ])
49
91
->getMock ();
50
- $ abstractDbMock ->expects ($ this ->any ())
51
- ->method ('getAllIds ' )
52
- ->willReturn ([]);
53
-
54
- $ filterMock = $ this ->getMockBuilder (\Magento \Ui \Component \MassAction \Filter::class)
92
+ $ this ->filterMock = $ this ->getMockBuilder (\Magento \Ui \Component \MassAction \Filter::class)
55
93
->disableOriginalConstructor ()
56
94
->setMethods (['getCollection ' ])
57
95
->getMock ();
58
- $ filterMock ->expects ($ this ->any ())
59
- ->method ('getCollection ' )
60
- ->willReturn ($ abstractDbMock );
61
-
62
- $ collectionFactoryMock = $ this ->getMockBuilder (
63
- \Magento \Catalog \Model \ResourceModel \Product \CollectionFactory::class
64
- )
96
+ $ this ->actionMock = $ this ->getMockBuilder (Action::class)
97
+ ->disableOriginalConstructor ()
98
+ ->getMock ();
99
+
100
+ $ collectionFactoryMock =
101
+ $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \CollectionFactory::class)
65
102
->disableOriginalConstructor ()
66
103
->setMethods (['create ' ])
67
104
->getMock ();
68
105
$ collectionFactoryMock ->expects ($ this ->any ())
69
106
->method ('create ' )
70
- ->willReturn ($ abstractDbMock );
107
+ ->willReturn ($ this ->abstractDbMock );
108
+
109
+ $ additionalParams = [
110
+ 'resultFactory ' => $ resultFactory
111
+ ];
112
+ /** @var \Magento\Backend\App\Action\Context $context */
113
+ $ context = $ this ->initContext ($ additionalParams , [[Action::class, $ this ->actionMock ]]);
71
114
72
- $ additionalParams = ['resultFactory ' => $ resultFactory ];
73
115
$ this ->action = new \Magento \Catalog \Controller \Adminhtml \Product \MassStatus (
74
- $ this -> initContext ( $ additionalParams ) ,
75
- $ productBuilder ,
76
- $ this ->priceProcessor ,
77
- $ filterMock ,
116
+ $ context ,
117
+ $ this -> productBuilderMock ,
118
+ $ this ->priceProcessorMock ,
119
+ $ this -> filterMock ,
78
120
$ collectionFactoryMock
79
121
);
80
122
}
81
123
82
124
public function testMassStatusAction ()
83
125
{
84
- $ this ->priceProcessor ->expects ($ this ->once ())->method ('reindexList ' );
126
+ $ storeId = 1 ;
127
+ $ status = \Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_DISABLED ;
128
+ $ filters = [
129
+ 'store_id ' => 2 ,
130
+ ];
131
+
132
+ $ this ->filterMock ->expects ($ this ->once ())
133
+ ->method ('getCollection ' )
134
+ ->willReturn ($ this ->abstractDbMock );
135
+ $ this ->abstractDbMock ->expects ($ this ->once ())
136
+ ->method ('getAllIds ' )
137
+ ->willReturn ([3 ]);
138
+ $ this ->request ->expects ($ this ->exactly (3 ))
139
+ ->method ('getParam ' )
140
+ ->willReturnMap ([
141
+ ['store ' , 0 , $ storeId ],
142
+ ['status ' , null , $ status ],
143
+ ['filters ' , [], $ filters ]
144
+ ]);
145
+ $ this ->actionMock ->expects ($ this ->once ())
146
+ ->method ('updateAttributes ' )
147
+ ->with ([3 ], ['status ' => $ status ], 2 );
148
+ $ this ->priceProcessorMock ->expects ($ this ->once ())
149
+ ->method ('reindexList ' );
150
+
85
151
$ this ->action ->execute ();
86
152
}
87
153
}
0 commit comments