Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CatalogProductSaveAfterObserverTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class CatalogProductSaveAfterObserverTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_model;
17 
21  protected $_quoteMock;
22 
26  protected $_observerMock;
27 
31  protected $_eventMock;
32 
33  protected function setUp()
34  {
35  $this->_quoteMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote::class);
36  $this->_observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
37  $this->_eventMock = $this->createPartialMock(
38  \Magento\Framework\Event::class,
39  ['getProduct', 'getStatus', 'getProductId']
40  );
41  $this->_observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->_eventMock));
42  $this->_model = new CatalogProductSaveAfterObserver($this->_quoteMock);
43  }
44 
50  public function testSaveProduct($productId, $productStatus)
51  {
52  $productMock = $this->createPartialMock(
53  \Magento\Catalog\Model\Product::class,
54  ['getId', 'getStatus', '__wakeup']
55  );
56  $this->_eventMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock));
57  $productMock->expects($this->once())->method('getId')->will($this->returnValue($productId));
58  $productMock->expects($this->once())->method('getStatus')->will($this->returnValue($productStatus));
59  $this->_quoteMock->expects($this->any())->method('markQuotesRecollect');
60  $this->_model->execute($this->_observerMock);
61  }
62 
66  public function statusUpdateDataProvider()
67  {
68  return [[125, 1], [100, 0]];
69  }
70 }