5
5
*/
6
6
namespace Magento \GroupedProduct \Test \Unit \Controller \Adminhtml \Edit ;
7
7
8
+ use Magento \Framework \Controller \ResultFactory ;
9
+
8
10
class PopupTest extends \PHPUnit_Framework_TestCase
9
11
{
10
12
/**
@@ -17,6 +19,11 @@ class PopupTest extends \PHPUnit_Framework_TestCase
17
19
*/
18
20
protected $ action ;
19
21
22
+ /**
23
+ * @var \Magento\Backend\App\Action\Context
24
+ */
25
+ protected $ context ;
26
+
20
27
/**
21
28
* @var \PHPUnit_Framework_MockObject_MockObject
22
29
*/
@@ -33,25 +40,46 @@ class PopupTest extends \PHPUnit_Framework_TestCase
33
40
protected $ registry ;
34
41
35
42
/**
36
- * @var \PHPUnit_Framework_MockObject_MockObject
43
+ * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject
44
+ */
45
+ protected $ resultFactoryMock ;
46
+
47
+ /**
48
+ * @var \Magento\Framework\View\Result\Layout|\PHPUnit_Framework_MockObject_MockObject
37
49
*/
38
- protected $ view ;
50
+ protected $ resultLayoutMock ;
39
51
40
52
protected function setUp ()
41
53
{
42
54
$ this ->request = $ this ->getMock ('Magento\Framework\App\RequestInterface ' , [], [], '' , false );
43
55
$ this ->factory = $ this ->getMock ('Magento\Catalog\Model\ProductFactory ' , ['create ' ], [], '' , false );
44
56
$ this ->registry = $ this ->getMock ('Magento\Framework\Registry ' , [], [], '' , false );
45
- $ this ->view = $ this ->getMock ('Magento\Framework\App\ViewInterface ' , [], [], '' , false );
57
+ $ this ->resultFactoryMock = $ this ->getMockBuilder ('Magento\Framework\Controller\ResultFactory ' )
58
+ ->disableOriginalConstructor ()
59
+ ->getMock ();
60
+ $ this ->resultLayoutMock = $ this ->getMockBuilder ('Magento\Framework\View\Result\Layout ' )
61
+ ->disableOriginalConstructor ()
62
+ ->getMock ();
63
+
64
+ $ this ->resultFactoryMock ->expects ($ this ->any ())
65
+ ->method ('create ' )
66
+ ->with (ResultFactory::TYPE_LAYOUT , [])
67
+ ->willReturn ($ this ->resultLayoutMock );
46
68
47
69
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
70
+ $ this ->context = $ this ->objectManager ->getObject (
71
+ 'Magento\Backend\App\Action\Context ' ,
72
+ [
73
+ 'request ' => $ this ->request ,
74
+ 'resultFactory ' => $ this ->resultFactoryMock
75
+ ]
76
+ );
48
77
$ this ->action = $ this ->objectManager ->getObject (
49
78
'Magento\GroupedProduct\Controller\Adminhtml\Edit\Popup ' ,
50
79
[
51
- 'request ' => $ this ->request ,
80
+ 'context ' => $ this ->context ,
52
81
'factory ' => $ this ->factory ,
53
- 'registry ' => $ this ->registry ,
54
- 'view ' => $ this ->view
82
+ 'registry ' => $ this ->registry
55
83
]
56
84
);
57
85
}
@@ -90,10 +118,7 @@ public function testPopupActionNoProductId()
90
118
$ this ->request ->expects ($ this ->at (3 ))->method ('getParam ' )->with ('set ' )->will ($ this ->returnValue ($ setId ));
91
119
$ this ->registry ->expects ($ this ->once ())->method ('register ' )->with ('current_product ' , $ product );
92
120
93
- $ this ->view ->expects ($ this ->once ())->method ('loadLayout ' )->with (false );
94
- $ this ->view ->expects ($ this ->once ())->method ('renderLayout ' );
95
-
96
- $ this ->action ->execute ();
121
+ $ this ->assertSame ($ this ->resultLayoutMock , $ this ->action ->execute ());
97
122
}
98
123
99
124
public function testPopupActionWithProductIdNoSetId ()
@@ -130,9 +155,6 @@ public function testPopupActionWithProductIdNoSetId()
130
155
$ this ->request ->expects ($ this ->at (3 ))->method ('getParam ' )->with ('set ' )->will ($ this ->returnValue ($ setId ));
131
156
$ this ->registry ->expects ($ this ->once ())->method ('register ' )->with ('current_product ' , $ product );
132
157
133
- $ this ->view ->expects ($ this ->once ())->method ('loadLayout ' )->with (false );
134
- $ this ->view ->expects ($ this ->once ())->method ('renderLayout ' );
135
-
136
- $ this ->action ->execute ();
158
+ $ this ->assertSame ($ this ->resultLayoutMock , $ this ->action ->execute ());
137
159
}
138
160
}
0 commit comments