CatalogAttributeDeleteAfterObserverTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Test\Unit\Observer;
  7. class CatalogAttributeDeleteAfterObserverTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\SalesRule\Observer\CatalogAttributeDeleteAfterObserver|\PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $model;
  13. /**
  14. * @var \Magento\SalesRule\Observer\CheckSalesRulesAvailability|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $checkSalesRulesAvailability;
  17. protected function setUp()
  18. {
  19. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  20. $this->initMocks();
  21. $this->model = $helper->getObject(
  22. \Magento\SalesRule\Observer\CatalogAttributeDeleteAfterObserver::class,
  23. [
  24. 'checkSalesRulesAvailability' => $this->checkSalesRulesAvailability
  25. ]
  26. );
  27. }
  28. protected function initMocks()
  29. {
  30. $this->checkSalesRulesAvailability = $this->createMock(
  31. \Magento\SalesRule\Observer\CheckSalesRulesAvailability::class
  32. );
  33. }
  34. public function testCatalogAttributeDeleteAfter()
  35. {
  36. $attributeCode = 'attributeCode';
  37. $observer = $this->createMock(\Magento\Framework\Event\Observer::class);
  38. $event = $this->createPartialMock(\Magento\Framework\Event::class, ['getAttribute', '__wakeup']);
  39. $attribute = $this->createPartialMock(
  40. \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
  41. ['dataHasChangedFor', 'getIsUsedForPromoRules', 'getAttributeCode', '__wakeup']
  42. );
  43. $observer->expects($this->once())
  44. ->method('getEvent')
  45. ->will($this->returnValue($event));
  46. $event->expects($this->any())
  47. ->method('getAttribute')
  48. ->will($this->returnValue($attribute));
  49. $attribute->expects($this->any())
  50. ->method('getIsUsedForPromoRules')
  51. ->will($this->returnValue(true));
  52. $attribute->expects($this->any())
  53. ->method('getAttributeCode')
  54. ->will($this->returnValue($attributeCode));
  55. $this->checkSalesRulesAvailability
  56. ->expects($this->once())
  57. ->method('checkSalesRulesAvailability')
  58. ->willReturn('true');
  59. $this->assertEquals($this->model, $this->model->execute($observer));
  60. }
  61. }