|
3 | 3 |
|
4 | 4 | namespace IntegerNet\GlobalCustomLayout\Test\Integration;
|
5 | 5 |
|
6 |
| -use IntegerNet\GlobalCustomLayout\Test\src\CategoryLayoutUpdateManager; |
7 |
| -use IntegerNet\GlobalCustomLayout\Test\src\PageLayoutUpdateManager; |
8 |
| -use IntegerNet\GlobalCustomLayout\Test\src\ProductLayoutUpdateManager; |
| 6 | +use Magento\Framework\App\DeploymentConfig\Reader; |
| 7 | +use Magento\Framework\App\DeploymentConfig\Writer; |
| 8 | +use Magento\Framework\Config\File\ConfigFilePool; |
| 9 | +use Magento\Framework\Exception\FileSystemException; |
| 10 | +use Magento\Framework\Exception\LocalizedException; |
| 11 | +use Magento\Framework\Exception\RuntimeException; |
| 12 | +use Magento\Framework\Module\Status as ModuleStatus; |
9 | 13 | use Magento\Framework\ObjectManagerInterface;
|
10 | 14 | use Magento\Framework\View\LayoutInterface;
|
11 | 15 | use Magento\TestFramework\Helper\Bootstrap;
|
|
14 | 18 | /**
|
15 | 19 | * @magentoAppIsolation enabled
|
16 | 20 | * @magentoAppArea frontend
|
| 21 | + * @magentoComponentsDir ../../../../vendor/integer-net/magento2-global-custom-layout/tests/Integration/_files/app/code/IntegerNet |
17 | 22 | */
|
18 | 23 | abstract class AbstractFrontendControllerTest extends AbstractController
|
19 | 24 | {
|
20 | 25 | /** @var int */
|
21 | 26 | const STORE_ID = 0;
|
22 | 27 |
|
23 |
| - const TEST_FILE = 'test-file'; |
| 28 | + /** @var string */ |
| 29 | + const GLOBAL_TEST_FILE = 'globalfile'; |
| 30 | + |
| 31 | + /** @var string */ |
| 32 | + const DEFAULT_TEST_FILE = 'defaultfile'; |
24 | 33 |
|
25 | 34 | /** @var int */
|
26 | 35 | const GLOBAL_IDENTIFIER = 0;
|
27 | 36 |
|
28 |
| - /** |
29 |
| - * @var ObjectManagerInterface |
30 |
| - */ |
| 37 | + /** @var ObjectManagerInterface */ |
31 | 38 | protected $objectManager;
|
32 | 39 |
|
33 |
| - /** |
34 |
| - * @var LayoutInterface |
35 |
| - */ |
36 |
| - protected $layoutInterface; |
| 40 | + /** @var LayoutInterface */ |
| 41 | + protected $layout; |
| 42 | + |
| 43 | + /** @var ModuleStatus */ |
| 44 | + protected $moduleStatus; |
| 45 | + |
| 46 | + /** @var Reader */ |
| 47 | + protected $configReader; |
| 48 | + |
| 49 | + /** @var Writer */ |
| 50 | + protected $configWriter; |
| 51 | + |
| 52 | + /** @var array */ |
| 53 | + protected $initialConfig; |
37 | 54 |
|
38 | 55 | /**
|
39 | 56 | * @inheritdoc
|
| 57 | + * @throws LocalizedException |
| 58 | + * @magentoComponentsDir ../../../../vendor/integer-net/magento2-global-custom-layout/tests/Integration/_files/app/code/IntegerNet |
40 | 59 | */
|
41 | 60 | protected function setUp(): void
|
42 | 61 | {
|
43 | 62 | $this->objectManager = Bootstrap::getObjectManager();
|
44 |
| - $this->layoutInterface = $this->objectManager->get(LayoutInterface::class); |
| 63 | + $this->layout = $this->objectManager->get(LayoutInterface::class); |
| 64 | + $this->configWriter = $this->objectManager->get(Writer::class); |
45 | 65 |
|
46 |
| - $this->setUpPreferences(); |
| 66 | + $this->backupInitialConfig(); |
| 67 | + $this->enableTestModuleInConfig(); |
47 | 68 |
|
48 | 69 | parent::setUp();
|
49 | 70 | }
|
50 | 71 |
|
51 |
| - private function setUpPreferences(): void |
| 72 | + protected function enableTestModuleInConfig() |
52 | 73 | {
|
53 |
| - $this->objectManager->configure( |
54 |
| - [ |
55 |
| - 'preferences' => [ |
56 |
| - \Magento\Catalog\Model\Category\Attribute\LayoutUpdateManager::class => CategoryLayoutUpdateManager::class, |
57 |
| - \Magento\Catalog\Model\Product\Attribute\LayoutUpdateManager::class => ProductLayoutUpdateManager::class, |
58 |
| - \Magento\Cms\Model\Page\CustomLayoutManagerInterface::class => PageLayoutUpdateManager::class, |
59 |
| - ], |
60 |
| - ] |
| 74 | + $this->moduleStatus = $this->objectManager->create(ModuleStatus::class); |
| 75 | + $this->moduleStatus->setIsEnabled(true, ['IntegerNet_GlobalCustomLayoutTest']); |
| 76 | + |
| 77 | + $this->objectManager->removeSharedInstance(\Magento\Framework\Module\Manager::class); |
| 78 | + $this->objectManager->removeSharedInstance(\Magento\Framework\Module\ModuleList::class); |
| 79 | + $this->objectManager->removeSharedInstance(\Magento\Framework\View\Model\Layout\Merge::class); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @throws FileSystemException |
| 84 | + */ |
| 85 | + protected function tearDown(): void |
| 86 | + { |
| 87 | + $this->restoreInitialConfig(); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @throws FileSystemException |
| 92 | + */ |
| 93 | + protected function restoreInitialConfig(): void |
| 94 | + { |
| 95 | + $this->configWriter->saveConfig( |
| 96 | + [ConfigFilePool::APP_CONFIG => ['modules' => $this->initialConfig['modules']]], |
| 97 | + true |
61 | 98 | );
|
62 | 99 | }
|
| 100 | + |
| 101 | + /** |
| 102 | + * @throws FileSystemException |
| 103 | + * @throws RuntimeException |
| 104 | + */ |
| 105 | + protected function backupInitialConfig(): void |
| 106 | + { |
| 107 | + if (!$this->initialConfig) { |
| 108 | + $this->configReader = $this->objectManager->get(Reader::class); |
| 109 | + $this->initialConfig = $this->configReader->load(); |
| 110 | + } |
| 111 | + } |
63 | 112 | }
|
0 commit comments