Skip to content

Commit d58c63e

Browse files
committed
MAGETWO-51008: Unable to process data upgrade when Google Analytics's "Content Experiments" enabled
1 parent 3b7548a commit d58c63e

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

app/code/Magento/GoogleOptimizer/Observer/AbstractSave.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function execute(Observer $observer)
5858
{
5959
$this->_initEntity($observer);
6060

61-
if ($this->_isGoogleExperimentActive()) {
61+
if ($this->_isGoogleExperimentActive() && $this->isDataAvailable()) {
6262
$this->_processCode();
6363
}
6464

@@ -112,11 +112,10 @@ protected function _processCode()
112112
*/
113113
protected function _initRequestParams()
114114
{
115-
$params = $this->_request->getParam('google_experiment');
116-
if (!is_array($params) || !isset($params['experiment_script']) || !isset($params['code_id'])) {
115+
if (!$this->isDataAvailable()) {
117116
throw new \InvalidArgumentException('Wrong request parameters');
118117
}
119-
$this->_params = $params;
118+
$this->_params = $this->getRequestData();
120119
}
121120

122121
/**
@@ -181,4 +180,21 @@ protected function _deleteCode()
181180
{
182181
$this->_modelCode->delete();
183182
}
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+
}
184200
}

app/code/Magento/GoogleOptimizer/Test/Unit/Observer/Category/SaveGoogleExperimentScriptObserverTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testCreatingCodeIfRequestIsValid()
8585
);
8686

8787
$this->_requestMock->expects(
88-
$this->once()
88+
$this->exactly(3)
8989
)->method(
9090
'getParam'
9191
)->with(
@@ -113,8 +113,6 @@ public function testCreatingCodeIfRequestIsValid()
113113

114114
/**
115115
* @param array $params
116-
* @expectedException \InvalidArgumentException
117-
* @expectedExceptionMessage Wrong request parameters
118116
* @dataProvider dataProviderWrongRequestForCreating
119117
*/
120118
public function testCreatingCodeIfRequestIsNotValid($params)
@@ -174,7 +172,7 @@ public function testEditingCodeIfRequestIsValid()
174172
);
175173

176174
$this->_requestMock->expects(
177-
$this->once()
175+
$this->exactly(3)
178176
)->method(
179177
'getParam'
180178
)->with(
@@ -223,7 +221,7 @@ public function testEditingCodeIfCodeModelIsNotFound()
223221
);
224222

225223
$this->_requestMock->expects(
226-
$this->once()
224+
$this->exactly(3)
227225
)->method(
228226
'getParam'
229227
)->with(
@@ -254,7 +252,7 @@ public function testRemovingCode()
254252
);
255253

256254
$this->_requestMock->expects(
257-
$this->once()
255+
$this->exactly(3)
258256
)->method(
259257
'getParam'
260258
)->with(

app/code/Magento/GoogleOptimizer/Test/Unit/Observer/CmsPage/SaveGoogleExperimentScriptObserverTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testCreatingCodeIfRequestIsValid()
7070
$this->_helperMock->expects($this->once())->method('isGoogleExperimentActive')->will($this->returnValue(true));
7171

7272
$this->_requestMock->expects(
73-
$this->once()
73+
$this->exactly(3)
7474
)->method(
7575
'getParam'
7676
)->with(
@@ -98,8 +98,6 @@ public function testCreatingCodeIfRequestIsValid()
9898

9999
/**
100100
* @param array $params
101-
* @expectedException \InvalidArgumentException
102-
* @expectedExceptionMessage Wrong request parameters
103101
* @dataProvider dataProviderWrongRequestForCreating
104102
*/
105103
public function testCreatingCodeIfRequestIsNotValid($params)
@@ -143,7 +141,7 @@ public function testEditingCodeIfRequestIsValid()
143141
$this->_helperMock->expects($this->once())->method('isGoogleExperimentActive')->will($this->returnValue(true));
144142

145143
$this->_requestMock->expects(
146-
$this->once()
144+
$this->exactly(3)
147145
)->method(
148146
'getParam'
149147
)->with(
@@ -184,7 +182,7 @@ public function testEditingCodeIfCodeModelIsNotFound()
184182
$this->_helperMock->expects($this->once())->method('isGoogleExperimentActive')->will($this->returnValue(true));
185183

186184
$this->_requestMock->expects(
187-
$this->once()
185+
$this->exactly(3)
188186
)->method(
189187
'getParam'
190188
)->with(
@@ -215,7 +213,7 @@ public function testRemovingCode()
215213
);
216214

217215
$this->_requestMock->expects(
218-
$this->once()
216+
$this->exactly(3)
219217
)->method(
220218
'getParam'
221219
)->with(

app/code/Magento/GoogleOptimizer/Test/Unit/Observer/Product/SaveGoogleExperimentScriptObserverTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testCreatingCodeIfRequestIsValid()
8585
);
8686

8787
$this->_requestMock->expects(
88-
$this->once()
88+
$this->exactly(3)
8989
)->method(
9090
'getParam'
9191
)->with(
@@ -113,8 +113,6 @@ public function testCreatingCodeIfRequestIsValid()
113113

114114
/**
115115
* @param array $params
116-
* @expectedException \InvalidArgumentException
117-
* @expectedExceptionMessage Wrong request parameters
118116
* @dataProvider dataProviderWrongRequestForCreating
119117
*/
120118
public function testCreatingCodeIfRequestIsNotValid($params)
@@ -174,7 +172,7 @@ public function testEditingCodeIfRequestIsValid()
174172
);
175173

176174
$this->_requestMock->expects(
177-
$this->once()
175+
$this->exactly(3)
178176
)->method(
179177
'getParam'
180178
)->with(
@@ -223,7 +221,7 @@ public function testEditingCodeIfCodeModelIsNotFound()
223221
);
224222

225223
$this->_requestMock->expects(
226-
$this->once()
224+
$this->exactly(3)
227225
)->method(
228226
'getParam'
229227
)->with(
@@ -254,7 +252,7 @@ public function testRemovingCode()
254252
);
255253

256254
$this->_requestMock->expects(
257-
$this->once()
255+
$this->exactly(3)
258256
)->method(
259257
'getParam'
260258
)->with(

0 commit comments

Comments
 (0)