9
9
10
10
class SaveTest extends \PHPUnit_Framework_TestCase
11
11
{
12
- /** @var \Magento\Backend\Controller\Adminhtml\System\Account */
13
- protected $ _controller ;
14
-
15
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\RequestInterface */
16
- protected $ _requestMock ;
17
-
18
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ResponseInterface */
19
- protected $ _responseMock ;
20
-
21
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManager\ObjectManager */
22
- protected $ _objectManagerMock ;
23
-
24
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Message\ManagerInterface */
25
- protected $ _messagesMock ;
26
-
27
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Helper\Data */
28
- protected $ _helperMock ;
29
-
30
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Auth\Session */
31
- protected $ _authSessionMock ;
32
-
33
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\User\Model\User */
34
- protected $ _userMock ;
35
-
36
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Validator\locale */
37
- protected $ _validatorMock ;
38
-
39
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Locale\Manager */
40
- protected $ _managerMock ;
41
-
42
- /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\TranslateInterface */
43
- protected $ _translatorMock ;
12
+ /**
13
+ * @var \Magento\Backend\Controller\Adminhtml\System\Account\Save
14
+ */
15
+ protected $ controller ;
16
+
17
+ /**
18
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\RequestInterface
19
+ */
20
+ protected $ requestMock ;
21
+
22
+ /**
23
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ResponseInterface
24
+ */
25
+ protected $ responseMock ;
26
+
27
+ /**
28
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManager\ObjectManager
29
+ */
30
+ protected $ objectManagerMock ;
31
+
32
+ /**
33
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Message\ManagerInterface
34
+ */
35
+ protected $ messagesMock ;
36
+
37
+ /**
38
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Helper\Data
39
+ */
40
+ protected $ helperMock ;
41
+
42
+ /**
43
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Auth\Session
44
+ */
45
+ protected $ authSessionMock ;
46
+
47
+ /**
48
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\User\Model\User
49
+ */
50
+ protected $ userMock ;
51
+
52
+ /**
53
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Validator\locale
54
+ */
55
+ protected $ validatorMock ;
56
+
57
+ /**
58
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Locale\Manager
59
+ */
60
+ protected $ managerMock ;
61
+
62
+ /**
63
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\TranslateInterface
64
+ */
65
+ protected $ translatorMock ;
44
66
45
67
protected function setUp ()
46
68
{
47
- $ this ->_requestMock = $ this ->getMockBuilder ('Magento\Framework\App\Request\Http ' )
69
+ $ frontControllerMock = $ this ->getMockBuilder ('Magento\Framework\App\FrontController ' )
70
+ ->disableOriginalConstructor ()
71
+ ->getMock ();
72
+
73
+ $ this ->requestMock = $ this ->getMockBuilder ('Magento\Framework\App\Request\Http ' )
48
74
->disableOriginalConstructor ()->setMethods (['getOriginalPathInfo ' ])
49
75
->getMock ();
50
- $ this ->_responseMock = $ this ->getMockBuilder ('Magento\Framework\App\Response\Http ' )
76
+ $ this ->responseMock = $ this ->getMockBuilder ('Magento\Framework\App\Response\Http ' )
51
77
->disableOriginalConstructor ()
52
78
->setMethods ([])
53
79
->getMock ();
54
- $ this ->_objectManagerMock = $ this ->getMockBuilder ('Magento\Framework\ObjectManager\ObjectManager ' )
80
+ $ this ->objectManagerMock = $ this ->getMockBuilder ('Magento\Framework\ObjectManager\ObjectManager ' )
55
81
->disableOriginalConstructor ()
56
82
->setMethods (['get ' , 'create ' ])
57
83
->getMock ();
58
- $ frontControllerMock = $ this ->getMockBuilder ('Magento\Framework\App\FrontController ' )
59
- ->disableOriginalConstructor ()
60
- ->getMock ();
61
-
62
- $ this ->_helperMock = $ this ->getMockBuilder ('Magento\Backend\Helper\Data ' )
84
+ $ this ->helperMock = $ this ->getMockBuilder ('Magento\Backend\Helper\Data ' )
63
85
->disableOriginalConstructor ()
64
86
->setMethods (['getUrl ' ])
65
87
->getMock ();
66
- $ this ->_messagesMock = $ this ->getMockBuilder ('Magento\Framework\Message\Manager ' )
88
+ $ this ->messagesMock = $ this ->getMockBuilder ('Magento\Framework\Message\Manager ' )
67
89
->disableOriginalConstructor ()
68
90
->setMethods (['addSuccess ' ])
69
91
->getMockForAbstractClass ();
70
-
71
- $ this ->_authSessionMock = $ this ->getMockBuilder ('Magento\Backend\Model\Auth\Session ' )
92
+ $ this ->authSessionMock = $ this ->getMockBuilder ('Magento\Backend\Model\Auth\Session ' )
72
93
->disableOriginalConstructor ()
73
94
->setMethods (['getUser ' ])
74
95
->getMock ();
75
-
76
- $ this ->_userMock = $ this ->getMockBuilder ('Magento\User\Model\User ' )
96
+ $ this ->userMock = $ this ->getMockBuilder ('Magento\User\Model\User ' )
77
97
->disableOriginalConstructor ()
78
98
->setMethods (
79
99
['load ' , 'save ' , 'sendPasswordResetNotificationEmail ' , 'verifyIdentity ' , '__sleep ' , '__wakeup ' ]
80
100
)
81
101
->getMock ();
82
-
83
- $ this ->_validatorMock = $ this ->getMockBuilder ('Magento\Framework\Validator\Locale ' )
102
+ $ this ->validatorMock = $ this ->getMockBuilder ('Magento\Framework\Validator\Locale ' )
84
103
->disableOriginalConstructor ()
85
104
->setMethods (['isValid ' ])
86
105
->getMock ();
87
-
88
- $ this ->_managerMock = $ this ->getMockBuilder ('Magento\Backend\Model\Locale\Manager ' )
106
+ $ this ->managerMock = $ this ->getMockBuilder ('Magento\Backend\Model\Locale\Manager ' )
89
107
->disableOriginalConstructor ()
90
108
->setMethods (['switchBackendInterfaceLocale ' ])
91
109
->getMock ();
92
-
93
- $ this ->_translatorMock = $ this ->getMockBuilder ('Magento\Framework\TranslateInterface ' )
110
+ $ this ->translatorMock = $ this ->getMockBuilder ('Magento\Framework\TranslateInterface ' )
94
111
->disableOriginalConstructor ()
95
112
->getMock ();
96
113
@@ -107,19 +124,19 @@ protected function setUp()
107
124
->willReturn ($ resultRedirect );
108
125
109
126
$ contextMock = $ this ->getMock ('Magento\Backend\App\Action\Context ' , [], [], '' , false );
110
- $ contextMock ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->_requestMock );
111
- $ contextMock ->expects ($ this ->any ())->method ('getResponse ' )->willReturn ($ this ->_responseMock );
112
- $ contextMock ->expects ($ this ->any ())->method ('getObjectManager ' )->willReturn ($ this ->_objectManagerMock );
127
+ $ contextMock ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->requestMock );
128
+ $ contextMock ->expects ($ this ->any ())->method ('getResponse ' )->willReturn ($ this ->responseMock );
129
+ $ contextMock ->expects ($ this ->any ())->method ('getObjectManager ' )->willReturn ($ this ->objectManagerMock );
113
130
$ contextMock ->expects ($ this ->any ())->method ('getFrontController ' )->willReturn ($ frontControllerMock );
114
- $ contextMock ->expects ($ this ->any ())->method ('getHelper ' )->willReturn ($ this ->_helperMock );
115
- $ contextMock ->expects ($ this ->any ())->method ('getMessageManager ' )->willReturn ($ this ->_messagesMock );
116
- $ contextMock ->expects ($ this ->any ())->method ('getTranslator ' )->willReturn ($ this ->_translatorMock );
131
+ $ contextMock ->expects ($ this ->any ())->method ('getHelper ' )->willReturn ($ this ->helperMock );
132
+ $ contextMock ->expects ($ this ->any ())->method ('getMessageManager ' )->willReturn ($ this ->messagesMock );
133
+ $ contextMock ->expects ($ this ->any ())->method ('getTranslator ' )->willReturn ($ this ->translatorMock );
117
134
$ contextMock ->expects ($ this ->once ())->method ('getResultFactory ' )->willReturn ($ resultFactory );
118
135
119
136
$ args = ['context ' => $ contextMock ];
120
137
121
138
$ testHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
122
- $ this ->_controller = $ testHelper ->getObject ('Magento\Backend\Controller\Adminhtml\System\Account\Save ' , $ args );
139
+ $ this ->controller = $ testHelper ->getObject ('Magento\Backend\Controller\Adminhtml\System\Account\Save ' , $ args );
123
140
}
124
141
125
142
public function testSaveAction ()
@@ -136,69 +153,50 @@ public function testSaveAction()
136
153
\Magento \Backend \Block \System \Account \Edit \Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password ' ,
137
154
];
138
155
139
- $ testedMessage = 'You saved the account. ' ;
140
-
141
- $ this ->_authSessionMock ->expects ($ this ->any ())->method ('getUser ' )->will ($ this ->returnValue ($ this ->_userMock ));
142
-
143
- $ this ->_userMock ->expects ($ this ->any ())->method ('load ' )->will ($ this ->returnSelf ());
144
- $ this ->_validatorMock ->expects (
145
- $ this ->once ()
146
- )->method (
147
- 'isValid '
148
- )->with (
149
- $ this ->equalTo ($ requestParams ['interface_locale ' ])
150
- )->will (
151
- $ this ->returnValue (true )
152
- );
153
- $ this ->_managerMock ->expects ($ this ->any ())->method ('switchBackendInterfaceLocale ' );
154
-
155
- $ this ->_objectManagerMock ->expects (
156
- $ this ->at (0 )
157
- )->method (
158
- 'get '
159
- )->with (
160
- $ this ->equalTo ('Magento\Backend\Model\Auth\Session ' )
161
- )->will (
162
- $ this ->returnValue ($ this ->_authSessionMock )
163
- );
164
- $ this ->_objectManagerMock ->expects (
165
- $ this ->at (1 )
166
- )->method (
167
- 'create '
168
- )->with (
169
- $ this ->equalTo ('Magento\User\Model\User ' )
170
- )->will (
171
- $ this ->returnValue ($ this ->_userMock )
172
- );
173
- $ this ->_objectManagerMock ->expects (
174
- $ this ->at (2 )
175
- )->method (
176
- 'get '
177
- )->with (
178
- $ this ->equalTo ('Magento\Framework\Validator\Locale ' )
179
- )->will (
180
- $ this ->returnValue ($ this ->_validatorMock )
181
- );
182
- $ this ->_objectManagerMock ->expects (
183
- $ this ->at (3 )
184
- )->method (
185
- 'get '
186
- )->with (
187
- $ this ->equalTo ('Magento\Backend\Model\Locale\Manager ' )
188
- )->will (
189
- $ this ->returnValue ($ this ->_managerMock )
190
- );
191
-
192
- $ this ->_userMock ->setUserId ($ userId );
193
-
194
- $ this ->_userMock ->expects ($ this ->once ())->method ('save ' );
195
- $ this ->_userMock ->expects ($ this ->once ())->method ('verifyIdentity ' )->will ($ this ->returnValue (true ));
196
- $ this ->_userMock ->expects ($ this ->once ())->method ('sendPasswordResetNotificationEmail ' );
197
-
198
- $ this ->_requestMock ->setParams ($ requestParams );
199
-
200
- $ this ->_messagesMock ->expects ($ this ->once ())->method ('addSuccess ' )->with ($ this ->equalTo ($ testedMessage ));
201
-
202
- $ this ->_controller ->execute ();
156
+ $ testedMessage = __ ('You saved the account. ' );
157
+
158
+ $ this ->authSessionMock ->expects ($ this ->any ())
159
+ ->method ('getUser ' )
160
+ ->willReturn ($ this ->userMock );
161
+ $ this ->userMock ->expects ($ this ->any ())
162
+ ->method ('load ' )
163
+ ->will ($ this ->returnSelf ());
164
+ $ this ->validatorMock ->expects ($ this ->once ())
165
+ ->method ('isValid ' )
166
+ ->with ($ this ->equalTo ($ requestParams ['interface_locale ' ]))
167
+ ->willReturn (true );
168
+ $ this ->managerMock ->expects ($ this ->any ())
169
+ ->method ('switchBackendInterfaceLocale ' );
170
+ $ this ->objectManagerMock ->expects ($ this ->at (0 ))
171
+ ->method ('get ' )
172
+ ->with ($ this ->equalTo ('Magento\Backend\Model\Auth\Session ' ))
173
+ ->willReturn ($ this ->authSessionMock );
174
+ $ this ->objectManagerMock ->expects ($ this ->at (1 ))
175
+ ->method ('create ' )
176
+ ->with ($ this ->equalTo ('Magento\User\Model\User ' ))
177
+ ->willReturn ($ this ->userMock );
178
+ $ this ->objectManagerMock ->expects ($ this ->at (2 ))
179
+ ->method ('get ' )
180
+ ->with ($ this ->equalTo ('Magento\Framework\Validator\Locale ' ))
181
+ ->willReturn ($ this ->validatorMock );
182
+ $ this ->objectManagerMock ->expects ($ this ->at (3 ))
183
+ ->method ('get ' )
184
+ ->with ($ this ->equalTo ('Magento\Backend\Model\Locale\Manager ' ))
185
+ ->willReturn ($ this ->managerMock );
186
+ $ this ->userMock ->expects ($ this ->once ())
187
+ ->method ('save ' );
188
+ $ this ->userMock ->expects ($ this ->once ())
189
+ ->method ('verifyIdentity ' )
190
+ ->willReturn (true );
191
+ $ this ->userMock ->expects ($ this ->once ())
192
+ ->method ('sendPasswordResetNotificationEmail ' );
193
+ $ this ->messagesMock ->expects ($ this ->once ())
194
+ ->method ('addSuccess ' )
195
+ ->with ($ this ->equalTo ($ testedMessage ));
196
+
197
+ $ this ->userMock ->setUserId ($ userId );
198
+ $ this ->requestMock ->setParams ($ requestParams );
199
+
200
+ $ this ->controller ->execute ();
203
201
}
204
202
}
0 commit comments