Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CatalogAttributeSaveAfterObserverTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CatalogAttributeSaveAfterObserverTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
19 
20  protected function setUp()
21  {
22  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23  $this->initMocks();
24 
25  $this->model = $helper->getObject(
26  \Magento\SalesRule\Observer\CatalogAttributeSaveAfterObserver::class,
27  [
28  'checkSalesRulesAvailability' => $this->checkSalesRulesAvailability
29  ]
30  );
31  }
32 
33  protected function initMocks()
34  {
35  $this->checkSalesRulesAvailability = $this->createMock(
36  \Magento\SalesRule\Observer\CheckSalesRulesAvailability::class
37  );
38  }
39 
41  {
42  $attributeCode = 'attributeCode';
43  $observer = $this->createMock(\Magento\Framework\Event\Observer::class);
44  $event = $this->createPartialMock(\Magento\Framework\Event::class, ['getAttribute', '__wakeup']);
45  $attribute = $this->createPartialMock(
46  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
47  ['dataHasChangedFor', 'getIsUsedForPromoRules', 'getAttributeCode', '__wakeup']
48  );
49 
50  $observer->expects($this->once())
51  ->method('getEvent')
52  ->will($this->returnValue($event));
53  $event->expects($this->any())
54  ->method('getAttribute')
55  ->will($this->returnValue($attribute));
56  $attribute->expects($this->any())
57  ->method('dataHasChangedFor')
58  ->with('is_used_for_promo_rules')
59  ->will($this->returnValue(true));
60  $attribute->expects($this->any())
61  ->method('getIsUsedForPromoRules')
62  ->will($this->returnValue(false));
63  $attribute->expects($this->any())
64  ->method('getAttributeCode')
65  ->will($this->returnValue($attributeCode));
66 
67  $this->checkSalesRulesAvailability
68  ->expects($this->once())
69  ->method('checkSalesRulesAvailability')
70  ->willReturn('true');
71 
72  $this->assertEquals($this->model, $this->model->execute($observer));
73  }
74 }
$helper
Definition: iframe.phtml:13
$attributeCode
Definition: extend.phtml:12