3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Customer \Test \Unit \Controller \Plugin ;
7
8
9
+ use Magento \Customer \Controller \AccountInterface ;
8
10
use Magento \Customer \Controller \Plugin \Account ;
9
11
use Magento \Customer \Model \Session ;
10
12
use Magento \Framework \App \ActionFlag ;
11
13
use Magento \Framework \App \ActionInterface ;
12
- use Magento \Framework \App \Action \AbstractAction ;
13
14
use Magento \Framework \App \Request \Http ;
15
+ use Magento \Framework \App \Request \Http as HttpRequest ;
14
16
use Magento \Framework \Controller \ResultInterface ;
15
17
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
18
+ use PHPUnit \Framework \MockObject \MockObject ;
19
+ use PHPUnit \Framework \TestCase ;
16
20
17
- class AccountTest extends \ PHPUnit \ Framework \ TestCase
21
+ class AccountTest extends TestCase
18
22
{
19
23
/**
20
24
* @var string
@@ -27,59 +31,51 @@ class AccountTest extends \PHPUnit\Framework\TestCase
27
31
protected $ plugin ;
28
32
29
33
/**
30
- * @var Session | \PHPUnit_Framework_MockObject_MockObject
34
+ * @var Session|MockObject
31
35
*/
32
- protected $ session ;
36
+ protected $ sessionMock ;
33
37
34
38
/**
35
- * @var AbstractAction | \PHPUnit_Framework_MockObject_MockObject
39
+ * @var AccountInterface|MockObject
36
40
*/
37
- protected $ subject ;
41
+ protected $ actionMock ;
38
42
39
43
/**
40
- * @var Http | \PHPUnit_Framework_MockObject_MockObject
44
+ * @var Http|MockObject
41
45
*/
42
- protected $ request ;
46
+ protected $ requestMock ;
43
47
44
48
/**
45
- * @var ActionFlag | \PHPUnit_Framework_MockObject_MockObject
49
+ * @var ActionFlag|MockObject
46
50
*/
47
- protected $ actionFlag ;
51
+ protected $ actionFlagMock ;
48
52
49
53
/**
50
- * @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject
54
+ * @var ResultInterface|MockObject
51
55
*/
52
- private $ resultInterface ;
56
+ private $ resultMock ;
53
57
54
58
protected function setUp ()
55
59
{
56
- $ this ->session = $ this ->getMockBuilder (\ Magento \ Customer \ Model \ Session::class)
60
+ $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
57
61
->disableOriginalConstructor ()
58
- ->setMethods ([
59
- 'setNoReferer ' ,
60
- 'unsNoReferer ' ,
61
- 'authenticate ' ,
62
- ])
62
+ ->setMethods (['setNoReferer ' , 'unsNoReferer ' , 'authenticate ' ])
63
63
->getMock ();
64
64
65
- $ this ->subject = $ this ->getMockBuilder (AbstractAction::class)
66
- ->setMethods ([
67
- 'getActionFlag ' ,
68
- ])
65
+ $ this ->actionMock = $ this ->getMockBuilder (AccountInterface::class)
66
+ ->setMethods (['getActionFlag ' ])
69
67
->disableOriginalConstructor ()
70
68
->getMockForAbstractClass ();
71
69
72
- $ this ->request = $ this ->getMockBuilder (\ Magento \ Framework \ App \ Request \Http ::class)
70
+ $ this ->requestMock = $ this ->getMockBuilder (HttpRequest ::class)
73
71
->disableOriginalConstructor ()
74
- ->setMethods ([
75
- 'getActionName ' ,
76
- ])
72
+ ->setMethods (['getActionName ' ])
77
73
->getMock ();
78
74
79
- $ this ->resultInterface = $ this ->getMockBuilder (ResultInterface::class)
75
+ $ this ->resultMock = $ this ->getMockBuilder (ResultInterface::class)
80
76
->getMockForAbstractClass ();
81
77
82
- $ this ->actionFlag = $ this ->getMockBuilder (\ Magento \ Framework \ App \ ActionFlag::class)
78
+ $ this ->actionFlagMock = $ this ->getMockBuilder (ActionFlag::class)
83
79
->disableOriginalConstructor ()
84
80
->getMock ();
85
81
}
@@ -90,47 +86,43 @@ protected function setUp()
90
86
* @param boolean $isActionAllowed
91
87
* @param boolean $isAuthenticated
92
88
*
93
- * @dataProvider beforeDispatchDataProvider
89
+ * @dataProvider beforeExecuteDataProvider
94
90
*/
95
- public function testBeforeDispatch (
96
- $ action ,
97
- $ allowedActions ,
98
- $ isActionAllowed ,
99
- $ isAuthenticated
100
- ) {
101
- $ this ->request ->expects ($ this ->once ())
91
+ public function testBeforeExecute ($ action , $ allowedActions , $ isActionAllowed , $ isAuthenticated )
92
+ {
93
+ $ this ->requestMock ->expects ($ this ->once ())
102
94
->method ('getActionName ' )
103
95
->willReturn ($ action );
104
96
105
97
if ($ isActionAllowed ) {
106
- $ this ->session ->expects ($ this ->once ())
98
+ $ this ->sessionMock ->expects ($ this ->once ())
107
99
->method ('setNoReferer ' )
108
100
->with (true )
109
101
->willReturnSelf ();
110
102
} else {
111
- $ this ->session ->expects ($ this ->once ())
103
+ $ this ->sessionMock ->expects ($ this ->once ())
112
104
->method ('authenticate ' )
113
105
->willReturn ($ isAuthenticated );
114
106
if (!$ isAuthenticated ) {
115
- $ this ->subject ->expects ($ this ->once ())
107
+ $ this ->actionMock ->expects ($ this ->once ())
116
108
->method ('getActionFlag ' )
117
- ->willReturn ($ this ->actionFlag );
109
+ ->willReturn ($ this ->actionFlagMock );
118
110
119
- $ this ->actionFlag ->expects ($ this ->once ())
111
+ $ this ->actionFlagMock ->expects ($ this ->once ())
120
112
->method ('set ' )
121
113
->with ('' , ActionInterface::FLAG_NO_DISPATCH , true )
122
114
->willReturnSelf ();
123
115
}
124
116
}
125
117
126
- $ plugin = new Account ($ this ->session , $ allowedActions );
127
- $ plugin ->beforeDispatch ($ this ->subject , $ this -> request );
118
+ $ plugin = new Account ($ this ->requestMock , $ this -> sessionMock , $ allowedActions );
119
+ $ plugin ->beforeExecute ($ this ->actionMock );
128
120
}
129
121
130
122
/**
131
123
* @return array
132
124
*/
133
- public function beforeDispatchDataProvider ()
125
+ public function beforeExecuteDataProvider ()
134
126
{
135
127
return [
136
128
[
@@ -166,23 +158,23 @@ public function beforeDispatchDataProvider()
166
158
];
167
159
}
168
160
169
- public function testAfterDispatch ()
161
+ public function testAfterExecute ()
170
162
{
171
- $ this ->session ->expects ($ this ->once ())
163
+ $ this ->sessionMock ->expects ($ this ->once ())
172
164
->method ('unsNoReferer ' )
173
165
->with (false )
174
166
->willReturnSelf ();
175
167
176
168
$ plugin = (new ObjectManager ($ this ))->getObject (
177
169
Account::class,
178
170
[
179
- 'session ' => $ this ->session ,
171
+ 'session ' => $ this ->sessionMock ,
180
172
'allowedActions ' => ['testaction ' ]
181
173
]
182
174
);
183
175
$ this ->assertSame (
184
- $ this ->resultInterface ,
185
- $ plugin ->afterDispatch ($ this ->subject , $ this ->resultInterface , $ this ->request )
176
+ $ this ->resultMock ,
177
+ $ plugin ->afterExecute ($ this ->actionMock , $ this ->resultMock , $ this ->requestMock )
186
178
);
187
179
}
188
180
}
0 commit comments