47 $this->_helperMock = $this->createMock(\
Magento\GoogleOptimizer\Helper\Data::class);
48 $this->_productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
50 $this->_productMock->expects(
55 $this->returnValue($this->_storeId)
57 $event = $this->createPartialMock(\
Magento\Framework\Event::class, [
'getProduct']);
58 $event->expects($this->once())->method(
'getProduct')->will($this->returnValue($this->_productMock));
59 $this->_eventObserverMock = $this->createMock(\
Magento\Framework\Event\Observer::class);
60 $this->_eventObserverMock->expects($this->once())->method(
'getEvent')->will($this->returnValue($event));
61 $this->_codeMock = $this->createMock(\
Magento\GoogleOptimizer\Model\Code::class);
62 $this->_requestMock = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
64 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
65 $this->_modelObserver = $objectManagerHelper->getObject(
66 \
Magento\GoogleOptimizer\Observer\Product\SaveGoogleExperimentScriptObserver::class,
67 [
'helper' => $this->_helperMock,
'modelCode' => $this->_codeMock,
'request' => $this->_requestMock]
74 $experimentScript =
'some string';
76 $this->_productMock->expects($this->once())->method(
'getId')->will($this->returnValue(
$productId));
77 $this->_helperMock->expects(
80 'isGoogleExperimentActive' 84 $this->returnValue(
true)
87 $this->_requestMock->expects(
94 $this->returnValue([
'code_id' =>
'',
'experiment_script' => $experimentScript])
97 $this->_codeMock->expects(
103 'entity_type' => \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
105 'store_id' => $this->_storeId,
106 'experiment_script' => $experimentScript,
109 $this->_codeMock->expects($this->once())->method(
'save');
111 $this->_modelObserver->execute($this->_eventObserverMock);
120 $this->_helperMock->expects(
123 'isGoogleExperimentActive' 127 $this->returnValue(
true)
130 $this->_requestMock->expects(
140 $this->_modelObserver->execute($this->_eventObserverMock);
154 [[
'experiment_script' =>
'']]];
160 $experimentScript =
'some string';
163 $this->_productMock->expects($this->once())->method(
'getId')->will($this->returnValue(
$productId));
164 $this->_helperMock->expects(
167 'isGoogleExperimentActive' 171 $this->returnValue(
true)
174 $this->_requestMock->expects(
181 $this->returnValue([
'code_id' => $codeId,
'experiment_script' => $experimentScript])
184 $this->_codeMock->expects($this->once())->method(
'load')->with($codeId);
185 $this->_codeMock->expects($this->once())->method(
'getId')->will($this->returnValue($codeId));
187 $this->_codeMock->expects(
193 'entity_type' => \
Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
195 'store_id' => $this->_storeId,
196 'experiment_script' => $experimentScript,
199 $this->_codeMock->expects($this->once())->method(
'save');
201 $this->_modelObserver->execute($this->_eventObserverMock);
210 $experimentScript =
'some string';
213 $this->_helperMock->expects(
216 'isGoogleExperimentActive' 220 $this->returnValue(
true)
223 $this->_requestMock->expects(
230 $this->returnValue([
'code_id' => $codeId,
'experiment_script' => $experimentScript])
233 $this->_codeMock->expects($this->once())->method(
'load')->with($codeId);
234 $this->_codeMock->expects($this->atLeastOnce())->method(
'getId')->will($this->returnValue(
false));
235 $this->_codeMock->expects($this->never())->method(
'save');
237 $this->_modelObserver->execute($this->_eventObserverMock);
244 $this->_helperMock->expects(
247 'isGoogleExperimentActive' 251 $this->returnValue(
true)
254 $this->_requestMock->expects(
261 $this->returnValue([
'code_id' => $codeId,
'experiment_script' =>
''])
264 $this->_codeMock->expects($this->once())->method(
'load')->with($codeId);
265 $this->_codeMock->expects($this->once())->method(
'getId')->will($this->returnValue($codeId));
267 $this->_codeMock->expects($this->never())->method(
'save');
268 $this->_codeMock->expects($this->once())->method(
'delete');
270 $this->_modelObserver->execute($this->_eventObserverMock);
275 $this->_helperMock->expects(
278 'isGoogleExperimentActive' 282 $this->returnValue(
false)
284 $this->_codeMock->expects($this->never())->method(
'load');
285 $this->_codeMock->expects($this->never())->method(
'save');
286 $this->_codeMock->expects($this->never())->method(
'delete');
288 $this->_modelObserver->execute($this->_eventObserverMock);
testCreatingCodeIfRequestIsNotValid($params)
testManagingCodeIfGoogleExperimentIsDisabled()
testCreatingCodeIfRequestIsValid()
dataProviderWrongRequestForCreating()
testEditingCodeIfCodeModelIsNotFound()
testEditingCodeIfRequestIsValid()
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]