Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteProductGoogleExperimentScriptObserverTest.php
Go to the documentation of this file.
1 <?php
7 
8 class DeleteProductGoogleExperimentScriptObserverTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_codeMock;
14 
19 
23  protected $_model;
24 
25  protected function setUp()
26  {
27  $entityId = 3;
28  $storeId = 0;
29 
30  $this->_codeMock = $this->createMock(\Magento\GoogleOptimizer\Model\Code::class);
31  $event = $this->createPartialMock(\Magento\Framework\Event::class, ['getProduct']);
32  $this->_eventObserverMock = $this->createMock(\Magento\Framework\Event\Observer::class);
33  $this->_eventObserverMock->expects($this->once())->method('getEvent')->will($this->returnValue($event));
34  $product = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getId', 'getStoreId', '__wakeup']);
35  $product->expects($this->once())->method('getId')->will($this->returnValue($entityId));
36  $product->expects($this->once())->method('getStoreId')->will($this->returnValue($storeId));
37  $event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
38 
39  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40  $this->_model = $objectManagerHelper->getObject(
41  \Magento\GoogleOptimizer\Observer\Product\DeleteProductGoogleExperimentScriptObserver::class,
42  ['modelCode' => $this->_codeMock]
43  );
44  }
45 
47  {
48  $entityId = 3;
49  $storeId = 0;
50 
51  $this->_codeMock->expects(
52  $this->once()
53  )->method(
54  'loadByEntityIdAndType'
55  )->with(
56  $entityId,
57  \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
58  $storeId
59  );
60  $this->_codeMock->expects($this->once())->method('getId')->will($this->returnValue(2));
61  $this->_codeMock->expects($this->once())->method('delete');
62 
63  $this->_model->execute($this->_eventObserverMock);
64  }
65 
67  {
68  $entityId = 3;
69  $storeId = 0;
70 
71  $this->_codeMock->expects(
72  $this->once()
73  )->method(
74  'loadByEntityIdAndType'
75  )->with(
76  $entityId,
77  \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
78  $storeId
79  );
80  $this->_codeMock->expects($this->once())->method('getId')->will($this->returnValue(0));
81  $this->_codeMock->expects($this->never())->method('delete');
82 
83  $this->_model->execute($this->_eventObserverMock);
84  }
85 }