SwitchPriceAttributeScopeOnConfigChangeTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Observer;
  7. use Magento\Framework\App\Config\ReinitableConfigInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. class SwitchPriceAttributeScopeOnConfigChangeTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Framework\ObjectManagerInterface
  13. */
  14. private $objectManager;
  15. public function setUp()
  16. {
  17. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  18. }
  19. /**
  20. * @magentoDbIsolation enabled
  21. * @magentoAppArea adminhtml
  22. */
  23. public function testPriceAttributeHasScopeGlobal()
  24. {
  25. foreach (['price', 'cost', 'special_price'] as $attributeCode) {
  26. $attribute = $this->objectManager->get(\Magento\Eav\Model\Config::class)->getAttribute(
  27. 'catalog_product',
  28. $attributeCode
  29. );
  30. $this->assertTrue($attribute->isScopeGlobal());
  31. }
  32. }
  33. /**
  34. * @magentoDbIsolation enabled
  35. * @magentoAppArea adminhtml
  36. */
  37. public function testPriceAttributeHasScopeWebsite()
  38. {
  39. /** @var ReinitableConfigInterface $config */
  40. $config = $this->objectManager->get(
  41. ReinitableConfigInterface::class
  42. );
  43. $config->setValue(
  44. \Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
  45. \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE,
  46. ScopeConfigInterface::SCOPE_TYPE_DEFAULT
  47. );
  48. $eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
  49. $eventManager->dispatch(
  50. "admin_system_config_changed_section_catalog",
  51. ['website' => 0, 'store' => 0]
  52. );
  53. foreach (['price', 'cost', 'special_price'] as $attributeCode) {
  54. $attribute = $this->objectManager->get(\Magento\Eav\Model\Config::class)->getAttribute(
  55. 'catalog_product',
  56. $attributeCode
  57. );
  58. $this->assertTrue($attribute->isScopeWebsite());
  59. }
  60. }
  61. }