File tree 4 files changed +32
-22
lines changed
app/code/Magento/GoogleOptimizer
4 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ public function execute(Observer $observer)
58
58
{
59
59
$ this ->_initEntity ($ observer );
60
60
61
- if ($ this ->_isGoogleExperimentActive ()) {
61
+ if ($ this ->_isGoogleExperimentActive () && $ this -> isDataAvailable () ) {
62
62
$ this ->_processCode ();
63
63
}
64
64
@@ -112,11 +112,10 @@ protected function _processCode()
112
112
*/
113
113
protected function _initRequestParams ()
114
114
{
115
- $ params = $ this ->_request ->getParam ('google_experiment ' );
116
- if (!is_array ($ params ) || !isset ($ params ['experiment_script ' ]) || !isset ($ params ['code_id ' ])) {
115
+ if (!$ this ->isDataAvailable ()) {
117
116
throw new \InvalidArgumentException ('Wrong request parameters ' );
118
117
}
119
- $ this ->_params = $ params ;
118
+ $ this ->_params = $ this -> getRequestData () ;
120
119
}
121
120
122
121
/**
@@ -181,4 +180,21 @@ protected function _deleteCode()
181
180
{
182
181
$ this ->_modelCode ->delete ();
183
182
}
183
+
184
+ /**
185
+ * @return array
186
+ */
187
+ private function isDataAvailable ()
188
+ {
189
+ $ params = $ this ->getRequestData ();
190
+ return is_array ($ params ) && isset ($ params ['experiment_script ' ]) && isset ($ params ['code_id ' ]);
191
+ }
192
+
193
+ /**
194
+ * @return mixed
195
+ */
196
+ private function getRequestData ()
197
+ {
198
+ return $ this ->_request ->getParam ('google_experiment ' );
199
+ }
184
200
}
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ public function testCreatingCodeIfRequestIsValid()
85
85
);
86
86
87
87
$ this ->_requestMock ->expects (
88
- $ this ->once ( )
88
+ $ this ->exactly ( 3 )
89
89
)->method (
90
90
'getParam '
91
91
)->with (
@@ -113,8 +113,6 @@ public function testCreatingCodeIfRequestIsValid()
113
113
114
114
/**
115
115
* @param array $params
116
- * @expectedException \InvalidArgumentException
117
- * @expectedExceptionMessage Wrong request parameters
118
116
* @dataProvider dataProviderWrongRequestForCreating
119
117
*/
120
118
public function testCreatingCodeIfRequestIsNotValid ($ params )
@@ -174,7 +172,7 @@ public function testEditingCodeIfRequestIsValid()
174
172
);
175
173
176
174
$ this ->_requestMock ->expects (
177
- $ this ->once ( )
175
+ $ this ->exactly ( 3 )
178
176
)->method (
179
177
'getParam '
180
178
)->with (
@@ -223,7 +221,7 @@ public function testEditingCodeIfCodeModelIsNotFound()
223
221
);
224
222
225
223
$ this ->_requestMock ->expects (
226
- $ this ->once ( )
224
+ $ this ->exactly ( 3 )
227
225
)->method (
228
226
'getParam '
229
227
)->with (
@@ -254,7 +252,7 @@ public function testRemovingCode()
254
252
);
255
253
256
254
$ this ->_requestMock ->expects (
257
- $ this ->once ( )
255
+ $ this ->exactly ( 3 )
258
256
)->method (
259
257
'getParam '
260
258
)->with (
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ public function testCreatingCodeIfRequestIsValid()
70
70
$ this ->_helperMock ->expects ($ this ->once ())->method ('isGoogleExperimentActive ' )->will ($ this ->returnValue (true ));
71
71
72
72
$ this ->_requestMock ->expects (
73
- $ this ->once ( )
73
+ $ this ->exactly ( 3 )
74
74
)->method (
75
75
'getParam '
76
76
)->with (
@@ -98,8 +98,6 @@ public function testCreatingCodeIfRequestIsValid()
98
98
99
99
/**
100
100
* @param array $params
101
- * @expectedException \InvalidArgumentException
102
- * @expectedExceptionMessage Wrong request parameters
103
101
* @dataProvider dataProviderWrongRequestForCreating
104
102
*/
105
103
public function testCreatingCodeIfRequestIsNotValid ($ params )
@@ -143,7 +141,7 @@ public function testEditingCodeIfRequestIsValid()
143
141
$ this ->_helperMock ->expects ($ this ->once ())->method ('isGoogleExperimentActive ' )->will ($ this ->returnValue (true ));
144
142
145
143
$ this ->_requestMock ->expects (
146
- $ this ->once ( )
144
+ $ this ->exactly ( 3 )
147
145
)->method (
148
146
'getParam '
149
147
)->with (
@@ -184,7 +182,7 @@ public function testEditingCodeIfCodeModelIsNotFound()
184
182
$ this ->_helperMock ->expects ($ this ->once ())->method ('isGoogleExperimentActive ' )->will ($ this ->returnValue (true ));
185
183
186
184
$ this ->_requestMock ->expects (
187
- $ this ->once ( )
185
+ $ this ->exactly ( 3 )
188
186
)->method (
189
187
'getParam '
190
188
)->with (
@@ -215,7 +213,7 @@ public function testRemovingCode()
215
213
);
216
214
217
215
$ this ->_requestMock ->expects (
218
- $ this ->once ( )
216
+ $ this ->exactly ( 3 )
219
217
)->method (
220
218
'getParam '
221
219
)->with (
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ public function testCreatingCodeIfRequestIsValid()
85
85
);
86
86
87
87
$ this ->_requestMock ->expects (
88
- $ this ->once ( )
88
+ $ this ->exactly ( 3 )
89
89
)->method (
90
90
'getParam '
91
91
)->with (
@@ -113,8 +113,6 @@ public function testCreatingCodeIfRequestIsValid()
113
113
114
114
/**
115
115
* @param array $params
116
- * @expectedException \InvalidArgumentException
117
- * @expectedExceptionMessage Wrong request parameters
118
116
* @dataProvider dataProviderWrongRequestForCreating
119
117
*/
120
118
public function testCreatingCodeIfRequestIsNotValid ($ params )
@@ -174,7 +172,7 @@ public function testEditingCodeIfRequestIsValid()
174
172
);
175
173
176
174
$ this ->_requestMock ->expects (
177
- $ this ->once ( )
175
+ $ this ->exactly ( 3 )
178
176
)->method (
179
177
'getParam '
180
178
)->with (
@@ -223,7 +221,7 @@ public function testEditingCodeIfCodeModelIsNotFound()
223
221
);
224
222
225
223
$ this ->_requestMock ->expects (
226
- $ this ->once ( )
224
+ $ this ->exactly ( 3 )
227
225
)->method (
228
226
'getParam '
229
227
)->with (
@@ -254,7 +252,7 @@ public function testRemovingCode()
254
252
);
255
253
256
254
$ this ->_requestMock ->expects (
257
- $ this ->once ( )
255
+ $ this ->exactly ( 3 )
258
256
)->method (
259
257
'getParam '
260
258
)->with (
You can’t perform that action at this time.
0 commit comments