PluginTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Test\Unit\Model\Design\Config;
  7. use Magento\Theme\Model\Design\Config\Plugin;
  8. class PluginTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  11. protected $eventManager;
  12. /** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  13. protected $storeManager;
  14. /** @var \Magento\Theme\Model\DesignConfigRepository|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $repository;
  16. /** @var \Magento\Theme\Api\Data\DesignConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $designConfig;
  18. /** @var \Magento\Store\Api\Data\WebsiteInterface|\PHPUnit_Framework_MockObject_MockObject */
  19. protected $website;
  20. /** @var \Magento\Store\Api\Data\StoreInterface|\PHPUnit_Framework_MockObject_MockObject */
  21. protected $store;
  22. /** @var Plugin */
  23. protected $plugin;
  24. public function setUp()
  25. {
  26. $this->eventManager = $this->getMockForAbstractClass(
  27. \Magento\Framework\Event\ManagerInterface::class,
  28. [],
  29. '',
  30. false
  31. );
  32. $this->storeManager = $this->getMockForAbstractClass(
  33. \Magento\Store\Model\StoreManagerInterface::class,
  34. [],
  35. '',
  36. false
  37. );
  38. $this->repository = $this->createMock(\Magento\Theme\Model\DesignConfigRepository::class);
  39. $this->designConfig = $this->getMockForAbstractClass(
  40. \Magento\Theme\Api\Data\DesignConfigInterface::class,
  41. [],
  42. '',
  43. false
  44. );
  45. $this->website = $this->getMockForAbstractClass(
  46. \Magento\Store\Api\Data\WebsiteInterface::class,
  47. [],
  48. '',
  49. false
  50. );
  51. $this->store = $this->getMockForAbstractClass(
  52. \Magento\Store\Api\Data\StoreInterface::class,
  53. [],
  54. '',
  55. false
  56. );
  57. $this->plugin = new Plugin($this->eventManager, $this->storeManager);
  58. }
  59. public function testAfterSave()
  60. {
  61. $this->designConfig->expects($this->exactly(2))
  62. ->method('getScope')
  63. ->willReturn('website');
  64. $this->designConfig->expects($this->once())
  65. ->method('getScopeId')
  66. ->willReturn(1);
  67. $this->storeManager->expects($this->once())
  68. ->method('getWebsite')
  69. ->with(1)
  70. ->willReturn($this->website);
  71. $this->eventManager->expects($this->once())
  72. ->method('dispatch')
  73. ->with(
  74. 'admin_system_config_changed_section_design',
  75. ['website' => $this->website, 'store' => '']
  76. );
  77. $this->plugin->afterSave($this->repository, $this->designConfig);
  78. }
  79. public function testAfterSaveDispatchWithStore()
  80. {
  81. $this->designConfig->expects($this->exactly(2))
  82. ->method('getScope')
  83. ->willReturn('store');
  84. $this->designConfig->expects($this->once())
  85. ->method('getScopeId')
  86. ->willReturn(1);
  87. $this->storeManager->expects($this->once())
  88. ->method('getStore')
  89. ->with(1)
  90. ->willReturn($this->store);
  91. $this->eventManager->expects($this->once())
  92. ->method('dispatch')
  93. ->with(
  94. 'admin_system_config_changed_section_design',
  95. ['website' => '', 'store' => $this->store]
  96. );
  97. $this->plugin->afterSave($this->repository, $this->designConfig);
  98. }
  99. }