File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
app/code/Magento/GoogleOptimizer
Test/Unit/Observer/Product Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 5
5
* Copyright © Magento, Inc. All rights reserved.
6
6
* See COPYING.txt for license details.
7
7
*/
8
+ declare (strict_types=1 );
9
+
8
10
namespace Magento \GoogleOptimizer \Observer ;
9
11
10
12
use Magento \Framework \Event \Observer ;
11
13
use Magento \Framework \Event \ObserverInterface ;
12
14
13
15
/**
16
+ * Abstract entity for saving codes
17
+ *
14
18
* @api
15
19
* @since 100.0.2
16
20
*/
@@ -96,7 +100,9 @@ protected function _processCode()
96
100
$ this ->_initRequestParams ();
97
101
98
102
if ($ this ->_isNewCode ()) {
99
- $ this ->_saveCode ();
103
+ if (!$ this ->_isEmptyCode ()) {
104
+ $ this ->_saveCode ();
105
+ }
100
106
} else {
101
107
$ this ->_loadCode ();
102
108
if ($ this ->_isEmptyCode ()) {
@@ -185,6 +191,8 @@ protected function _deleteCode()
185
191
}
186
192
187
193
/**
194
+ * Check data availability
195
+ *
188
196
* @return bool
189
197
*/
190
198
private function isDataAvailable ()
@@ -194,6 +202,8 @@ private function isDataAvailable()
194
202
}
195
203
196
204
/**
205
+ * Get request data
206
+ *
197
207
* @return mixed
198
208
*/
199
209
private function getRequestData ()
Original file line number Diff line number Diff line change @@ -127,6 +127,39 @@ public function testCreatingCodeIfRequestIsValid()
127
127
$ this ->_modelObserver ->execute ($ this ->_eventObserverMock );
128
128
}
129
129
130
+ /**
131
+ * Test that code is not saving when request is empty
132
+ *
133
+ * @return void
134
+ */
135
+ public function testCreatingCodeIfRequestIsEmpty (): void
136
+ {
137
+ $ this ->_helperMock ->expects (
138
+ $ this ->once ()
139
+ )->method (
140
+ 'isGoogleExperimentActive '
141
+ )->with (
142
+ $ this ->_storeId
143
+ )->willReturn (
144
+ true
145
+ );
146
+
147
+ $ this ->_requestMock ->expects (
148
+ $ this ->exactly (3 )
149
+ )->method (
150
+ 'getParam '
151
+ )->with (
152
+ 'google_experiment '
153
+ )->willReturn (
154
+ ['code_id ' => '' , 'experiment_script ' => '' ]
155
+ );
156
+
157
+ $ this ->_codeMock ->expects ($ this ->never ())->method ('addData ' );
158
+ $ this ->_codeMock ->expects ($ this ->never ())->method ('save ' );
159
+
160
+ $ this ->_modelObserver ->execute ($ this ->_eventObserverMock );
161
+ }
162
+
130
163
/**
131
164
* @param array $params
132
165
* @dataProvider dataProviderWrongRequestForCreating
You can’t perform that action at this time.
0 commit comments