14
14
15
15
class DeleteTest extends \Magento \Integration \Test \Unit \Controller \Adminhtml \IntegrationTest
16
16
{
17
+ /**
18
+ * @var \Magento\Integration\Controller\Adminhtml\Integration\Delete
19
+ */
20
+ protected $ integrationContr ;
21
+
22
+ protected function setUp ()
23
+ {
24
+ parent ::setUp ();
25
+
26
+ $ this ->integrationContr = $ this ->_createIntegrationController ('Delete ' );
27
+
28
+ $ resultRedirect = $ this ->getMockBuilder ('Magento\Backend\Model\View\Result\Redirect ' )
29
+ ->disableOriginalConstructor ()
30
+ ->getMock ();
31
+ $ resultRedirect ->expects ($ this ->any ())
32
+ ->method ('setPath ' )
33
+ ->with ('*/*/ ' )
34
+ ->willReturnSelf ();
35
+
36
+ $ this ->resultRedirectFactory ->expects ($ this ->any ())
37
+ ->method ('create ' )
38
+ ->willReturn ($ resultRedirect );
39
+ }
40
+
17
41
public function testDeleteAction ()
18
42
{
19
43
$ intData = $ this ->_getSampleIntegrationData ();
20
- $ this ->_requestMock ->expects (
21
- $ this ->once ()
22
- )->method (
23
- 'getParam '
24
- )->will (
25
- $ this ->returnValue (self ::INTEGRATION_ID )
26
- );
27
- $ this ->_integrationSvcMock ->expects (
28
- $ this ->any ()
29
- )->method (
30
- 'get '
31
- )->with (
32
- $ this ->anything ()
33
- )->will (
34
- $ this ->returnValue ($ intData )
35
- );
36
- $ this ->_integrationSvcMock ->expects (
37
- $ this ->any ()
38
- )->method (
39
- 'delete '
40
- )->with (
41
- $ this ->anything ()
42
- )->will (
43
- $ this ->returnValue ($ intData )
44
- );
44
+ $ this ->_requestMock ->expects ($ this ->once ())
45
+ ->method ('getParam ' )
46
+ ->willReturn (self ::INTEGRATION_ID );
47
+ $ this ->_integrationSvcMock ->expects ($ this ->any ())
48
+ ->method ('get ' )
49
+ ->with ($ this ->anything ())
50
+ ->willReturn ($ intData );
51
+ $ this ->_integrationSvcMock ->expects ($ this ->any ())
52
+ ->method ('delete ' )
53
+ ->with ($ this ->anything ())
54
+ ->willReturn ($ intData );
45
55
// Use real translate model
46
56
$ this ->_translateModelMock = null ;
47
57
// verify success message
48
- $ this ->_messageManager ->expects (
49
- $ this ->once ()
50
- )->method (
51
- 'addSuccess '
52
- )->with (
53
- __ ('The integration \'%1 \' has been deleted. ' , $ intData [Info::DATA_NAME ])
54
- );
55
- $ integrationContr = $ this ->_createIntegrationController ('Delete ' );
56
- $ integrationContr ->execute ();
58
+ $ this ->_messageManager ->expects ($ this ->once ())
59
+ ->method ('addSuccess ' )
60
+ ->with (__ ('The integration \'%1 \' has been deleted. ' , $ intData [Info::DATA_NAME ]));
61
+
62
+ $ this ->integrationContr ->execute ();
57
63
}
58
64
59
65
public function testDeleteActionWithConsumer ()
60
66
{
61
67
$ intData = $ this ->_getSampleIntegrationData ();
62
68
$ intData [Info::DATA_CONSUMER_ID ] = 1 ;
63
- $ this ->_requestMock ->expects (
64
- $ this ->once ()
65
- )->method (
66
- 'getParam '
67
- )->will (
68
- $ this ->returnValue (self ::INTEGRATION_ID )
69
- );
70
- $ this ->_integrationSvcMock ->expects (
71
- $ this ->any ()
72
- )->method (
73
- 'get '
74
- )->with (
75
- $ this ->anything ()
76
- )->will (
77
- $ this ->returnValue ($ intData )
78
- );
79
- $ this ->_integrationSvcMock ->expects (
80
- $ this ->once ()
81
- )->method (
82
- 'delete '
83
- )->with (
84
- $ this ->anything ()
85
- )->will (
86
- $ this ->returnValue ($ intData )
87
- );
88
- $ this ->_oauthSvcMock ->expects (
89
- $ this ->once ()
90
- )->method (
91
- 'deleteConsumer '
92
- )->with (
93
- $ this ->anything ()
94
- )->will (
95
- $ this ->returnValue ($ intData )
96
- );
69
+ $ this ->_requestMock ->expects ($ this ->once ())
70
+ ->method ('getParam ' )
71
+ ->willReturn (self ::INTEGRATION_ID );
72
+ $ this ->_integrationSvcMock ->expects ($ this ->any ())
73
+ ->method ('get ' )
74
+ ->with ($ this ->anything ())
75
+ ->willReturn ($ intData );
76
+ $ this ->_integrationSvcMock ->expects ($ this ->once ())
77
+ ->method ('delete ' )
78
+ ->with ($ this ->anything ())
79
+ ->willReturn ($ intData );
80
+ $ this ->_oauthSvcMock ->expects ($ this ->once ())
81
+ ->method ('deleteConsumer ' )
82
+ ->with ($ this ->anything ())
83
+ ->willReturn ($ intData );
97
84
// Use real translate model
98
85
$ this ->_translateModelMock = null ;
99
86
// verify success message
100
- $ this ->_messageManager ->expects (
101
- $ this ->once ()
102
- )->method (
103
- 'addSuccess '
104
- )->with (
105
- __ ('The integration \'%1 \' has been deleted. ' , $ intData [Info::DATA_NAME ])
106
- );
107
- $ integrationContr = $ this ->_createIntegrationController ('Delete ' );
108
- $ integrationContr ->execute ();
87
+ $ this ->_messageManager ->expects ($ this ->once ())
88
+ ->method ('addSuccess ' )
89
+ ->with (__ ('The integration \'%1 \' has been deleted. ' , $ intData [Info::DATA_NAME ]));
90
+
91
+ $ this ->integrationContr ->execute ();
109
92
}
110
93
111
94
public function testDeleteActionConfigSetUp ()
112
95
{
113
96
$ intData = $ this ->_getSampleIntegrationData ();
114
97
$ intData [Info::DATA_SETUP_TYPE ] = IntegrationModel::TYPE_CONFIG ;
115
- $ this ->_requestMock ->expects (
116
- $ this ->once ()
117
- )->method (
118
- 'getParam '
119
- )->will (
120
- $ this ->returnValue (self ::INTEGRATION_ID )
121
- );
122
- $ this ->_integrationSvcMock ->expects (
123
- $ this ->any ()
124
- )->method (
125
- 'get '
126
- )->with (
127
- $ this ->anything ()
128
- )->will (
129
- $ this ->returnValue ($ intData )
130
- );
131
- $ this ->_integrationHelperMock ->expects (
132
- $ this ->once ()
133
- )->method (
134
- 'isConfigType '
135
- )->with (
136
- $ intData
137
- )->will (
138
- $ this ->returnValue (true )
139
- );
98
+ $ this ->_requestMock ->expects ($ this ->once ())
99
+ ->method ('getParam ' )
100
+ ->willReturn (self ::INTEGRATION_ID );
101
+ $ this ->_integrationSvcMock ->expects ($ this ->any ())
102
+ ->method ('get ' )
103
+ ->with ($ this ->anything ())
104
+ ->willReturn ($ intData );
105
+ $ this ->_integrationHelperMock ->expects ($ this ->once ())
106
+ ->method ('isConfigType ' )
107
+ ->with ($ intData )
108
+ ->willReturn (true );
140
109
// verify error message
141
- $ this ->_messageManager ->expects (
142
- $ this ->once ()
143
- )->method (
144
- 'addError '
145
- )->with (
146
- __ ('Uninstall the extension to remove integration \'%1 \'. ' , $ intData [Info::DATA_NAME ])
147
- );
110
+ $ this ->_messageManager ->expects ($ this ->once ())
111
+ ->method ('addError ' )
112
+ ->with (__ ('Uninstall the extension to remove integration \'%1 \'. ' , $ intData [Info::DATA_NAME ]));
148
113
$ this ->_integrationSvcMock ->expects ($ this ->never ())->method ('delete ' );
149
114
// Use real translate model
150
115
$ this ->_translateModelMock = null ;
151
116
// verify success message
152
117
$ this ->_messageManager ->expects ($ this ->never ())->method ('addSuccess ' );
153
- $ integrationContr = $ this -> _createIntegrationController ( ' Delete ' );
154
- $ integrationContr ->execute ();
118
+
119
+ $ this -> integrationContr ->execute ();
155
120
}
156
121
157
122
public function testDeleteActionMissingId ()
@@ -161,85 +126,62 @@ public function testDeleteActionMissingId()
161
126
// Use real translate model
162
127
$ this ->_translateModelMock = null ;
163
128
// verify error message
164
- $ this ->_messageManager ->expects (
165
- $ this ->once ()
166
- )->method (
167
- 'addError '
168
- )->with (
169
- __ ('Integration ID is not specified or is invalid. ' )
170
- );
171
- $ integrationContr = $ this ->_createIntegrationController ('Delete ' );
172
- $ integrationContr ->execute ();
129
+ $ this ->_messageManager ->expects ($ this ->once ())
130
+ ->method ('addError ' )
131
+ ->with (__ ('Integration ID is not specified or is invalid. ' ));
132
+
133
+ $ this ->integrationContr ->execute ();
173
134
}
174
135
136
+ /**
137
+ * @expectedException \Exception
138
+ * @expectedExceptionMessage Integration with ID '1' doesn't exist.
139
+ */
175
140
public function testDeleteActionForServiceIntegrationException ()
176
141
{
177
142
$ intData = $ this ->_getSampleIntegrationData ();
178
- $ this ->_integrationSvcMock ->expects (
179
- $ this ->any ()
180
- )->method (
181
- 'get '
182
- )->with (
183
- $ this ->anything ()
184
- )->will (
185
- $ this ->returnValue ($ intData )
186
- );
187
- $ this ->_requestMock ->expects (
188
- $ this ->once ()
189
- )->method (
190
- 'getParam '
191
- )->will (
192
- $ this ->returnValue (self ::INTEGRATION_ID )
193
- );
143
+ $ this ->_integrationSvcMock ->expects ($ this ->any ())
144
+ ->method ('get ' )
145
+ ->with ($ this ->anything ())
146
+ ->willReturn ($ intData );
147
+ $ this ->_requestMock ->expects ($ this ->once ())
148
+ ->method ('getParam ' )
149
+ ->willReturn (self ::INTEGRATION_ID );
194
150
// Use real translate model
195
151
$ this ->_translateModelMock = null ;
196
152
$ exceptionMessage = __ ("Integration with ID '%1' doesn't exist. " , $ intData [Info::DATA_ID ]);
197
153
$ invalidIdException = new IntegrationException ($ exceptionMessage );
198
- $ this ->_integrationSvcMock ->expects (
199
- $ this ->once ()
200
- )->method (
201
- 'delete '
202
- )->will (
203
- $ this ->throwException ($ invalidIdException )
204
- );
205
- $ this ->_messageManager ->expects ($ this ->once ())->method ('addError ' )->with ($ exceptionMessage );
206
- $ integrationContr = $ this ->_createIntegrationController ('Delete ' );
207
- $ integrationContr ->execute ();
154
+ $ this ->_integrationSvcMock ->expects ($ this ->once ())
155
+ ->method ('delete ' )
156
+ ->willThrowException ($ invalidIdException );
157
+ $ this ->_messageManager ->expects ($ this ->never ())->method ('addError ' );
158
+
159
+ $ this ->integrationContr ->execute ();
208
160
}
209
161
162
+ /**
163
+ * @expectedException \Exception
164
+ * @expectedExceptionMessage Integration with ID '1' doesn't exist.
165
+ */
210
166
public function testDeleteActionForServiceGenericException ()
211
167
{
212
168
$ intData = $ this ->_getSampleIntegrationData ();
213
- $ this ->_integrationSvcMock ->expects (
214
- $ this ->any ()
215
- )->method (
216
- 'get '
217
- )->with (
218
- $ this ->anything ()
219
- )->will (
220
- $ this ->returnValue ($ intData )
221
- );
222
- $ this ->_requestMock ->expects (
223
- $ this ->once ()
224
- )->method (
225
- 'getParam '
226
- )->will (
227
- $ this ->returnValue (self ::INTEGRATION_ID )
228
- );
169
+ $ this ->_integrationSvcMock ->expects ($ this ->any ())
170
+ ->method ('get ' )
171
+ ->with ($ this ->anything ())
172
+ ->willReturn ($ intData );
173
+ $ this ->_requestMock ->expects ($ this ->once ())
174
+ ->method ('getParam ' )
175
+ ->willReturn (self ::INTEGRATION_ID );
229
176
// Use real translate model
230
177
$ this ->_translateModelMock = null ;
231
178
$ exceptionMessage = __ ("Integration with ID '%1' doesn't exist. " , $ intData [Info::DATA_ID ]);
232
179
$ invalidIdException = new \Exception ($ exceptionMessage );
233
- $ this ->_integrationSvcMock ->expects (
234
- $ this ->once ()
235
- )->method (
236
- 'delete '
237
- )->will (
238
- $ this ->throwException ($ invalidIdException )
239
- );
240
- //Generic Exception(non-Service) should never add the message in session for user display
180
+ $ this ->_integrationSvcMock ->expects ($ this ->once ())
181
+ ->method ('delete ' )
182
+ ->willThrowException ($ invalidIdException );
241
183
$ this ->_messageManager ->expects ($ this ->never ())->method ('addError ' );
242
- $ integrationContr = $ this -> _createIntegrationController ( ' Delete ' );
243
- $ integrationContr ->execute ();
184
+
185
+ $ this -> integrationContr ->execute ();
244
186
}
245
187
}
0 commit comments