|
| 1 | +<?php |
| 2 | +/************************************************************************ |
| 3 | + * |
| 4 | + * Copyright 2024 Adobe |
| 5 | + * All Rights Reserved. |
| 6 | + * |
| 7 | + * NOTICE: All information contained herein is, and remains |
| 8 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 9 | + * and technical concepts contained herein are proprietary to Adobe |
| 10 | + * and its suppliers and are protected by all applicable intellectual |
| 11 | + * property laws, including trade secret and copyright laws. |
| 12 | + * Dissemination of this information or reproduction of this material |
| 13 | + * is strictly forbidden unless prior written permission is obtained |
| 14 | + * from Adobe. |
| 15 | + * ************************************************************************ |
| 16 | + */ |
| 17 | +declare(strict_types=1); |
| 18 | + |
| 19 | +namespace Magento\Theme\Observer; |
| 20 | + |
| 21 | +use Magento\Framework\App\Config\ReinitableConfigInterface; |
| 22 | +use Magento\Framework\Event\ManagerInterface; |
| 23 | +use Magento\Store\Model\ScopeInterface; |
| 24 | +use Magento\Store\Model\StoreManager; |
| 25 | +use Magento\TestFramework\Fixture\AppArea; |
| 26 | +use Magento\TestFramework\Fixture\Config; |
| 27 | +use Magento\TestFramework\Fixture\DataFixture; |
| 28 | +use Magento\TestFramework\Helper\Bootstrap; |
| 29 | +use Magento\TestFramework\Indexer\TestCase; |
| 30 | +use Magento\Theme\Api\DesignConfigRepositoryInterface; |
| 31 | +use Magento\Theme\Test\Fixture\DesignConfig as DesignConfigFixture; |
| 32 | + |
| 33 | +class MoveStoreLevelDesignConfigToWebsiteScopeOnSingleStoreModeTest extends TestCase |
| 34 | +{ |
| 35 | + private const XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER = 'design/footer/absolute_footer'; |
| 36 | + private const INITIAL_FOOTER_TEXT_STORES = 'test footer text for store scope'; |
| 37 | + private const INITIAL_FOOTER_TEXT_WEBSITES = 'test footer text for websites scope'; |
| 38 | + private const UPDATED_FOOTER_TEXT_WEBSITES = 'updated footer text for websites scope'; |
| 39 | + |
| 40 | + #[ |
| 41 | + DataFixture( |
| 42 | + DesignConfigFixture::class, |
| 43 | + [ |
| 44 | + 'scope_type' => ScopeInterface::SCOPE_WEBSITES, |
| 45 | + 'scope_id' => 1, |
| 46 | + 'data' => [ |
| 47 | + [ |
| 48 | + 'path' => self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, |
| 49 | + 'value' => self::INITIAL_FOOTER_TEXT_WEBSITES |
| 50 | + ] |
| 51 | + ] |
| 52 | + ] |
| 53 | + ), |
| 54 | + DataFixture( |
| 55 | + DesignConfigFixture::class, |
| 56 | + [ |
| 57 | + 'scope_type' => ScopeInterface::SCOPE_STORES, |
| 58 | + 'scope_id' => 1, |
| 59 | + 'data' => [ |
| 60 | + [ |
| 61 | + 'path' => self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, |
| 62 | + 'value' => self::INITIAL_FOOTER_TEXT_STORES |
| 63 | + ] |
| 64 | + ] |
| 65 | + ] |
| 66 | + ), |
| 67 | + Config(StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED, 1), |
| 68 | + AppArea('adminhtml') |
| 69 | + ] |
| 70 | + public function testExecute(): void |
| 71 | + { |
| 72 | + $eventManager = Bootstrap::getObjectManager()->get(ManagerInterface::class); |
| 73 | + $scopeConfig = Bootstrap::getObjectManager()->get(ReinitableConfigInterface::class); |
| 74 | + $this->assertEquals( |
| 75 | + self::INITIAL_FOOTER_TEXT_WEBSITES, |
| 76 | + $scopeConfig->getValue(self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, ScopeInterface::SCOPE_WEBSITES) |
| 77 | + ); |
| 78 | + $this->assertEquals( |
| 79 | + self::INITIAL_FOOTER_TEXT_STORES, |
| 80 | + $scopeConfig->getValue(self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, ScopeInterface::SCOPE_STORES) |
| 81 | + ); |
| 82 | + $eventManager->dispatch( |
| 83 | + 'admin_system_config_changed_section_general', |
| 84 | + [ |
| 85 | + 'website' => '', |
| 86 | + 'store' => '', |
| 87 | + 'changed_paths' => [ |
| 88 | + StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED |
| 89 | + ], |
| 90 | + ] |
| 91 | + ); |
| 92 | + $this->assertEquals( |
| 93 | + self::INITIAL_FOOTER_TEXT_STORES, |
| 94 | + $scopeConfig->getValue(self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, ScopeInterface::SCOPE_WEBSITES) |
| 95 | + ); |
| 96 | + $this->assertEquals( |
| 97 | + self::INITIAL_FOOTER_TEXT_STORES, |
| 98 | + $scopeConfig->getValue(self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, ScopeInterface::SCOPE_STORES) |
| 99 | + ); |
| 100 | + |
| 101 | + $this->updateConfig( |
| 102 | + self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, |
| 103 | + self::UPDATED_FOOTER_TEXT_WEBSITES, |
| 104 | + ScopeInterface::SCOPE_WEBSITES, |
| 105 | + 1 |
| 106 | + ); |
| 107 | + |
| 108 | + $this->assertEquals( |
| 109 | + self::UPDATED_FOOTER_TEXT_WEBSITES, |
| 110 | + $scopeConfig->getValue(self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, ScopeInterface::SCOPE_WEBSITES) |
| 111 | + ); |
| 112 | + $this->assertEquals( |
| 113 | + self::UPDATED_FOOTER_TEXT_WEBSITES, |
| 114 | + $scopeConfig->getValue(self::XML_PATH_DESIGN_FOOTER_ABSOLUTE_FOOTER, ScopeInterface::SCOPE_STORES) |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + private function updateConfig(string $path, string $value, string $scopeType, int $scopeId): void |
| 119 | + { |
| 120 | + $designConfigRepository = Bootstrap::getObjectManager()->get(DesignConfigRepositoryInterface::class); |
| 121 | + $designConfig = $designConfigRepository->getByScope($scopeType, $scopeId); |
| 122 | + $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData(); |
| 123 | + foreach ($fieldsData as $fieldData) { |
| 124 | + if ($fieldData->getPath() === $path) { |
| 125 | + $fieldData->setValue($value); |
| 126 | + } |
| 127 | + |
| 128 | + } |
| 129 | + $designConfig->setScope($scopeType); |
| 130 | + $designConfig->setScopeId($scopeId); |
| 131 | + $designConfigRepository->save($designConfig); |
| 132 | + } |
| 133 | +} |
0 commit comments