Skip to content

Commit 1505a25

Browse files
committed
MC-31618: Move static config to files - PLUGIN_LIST
- Add plugin list config generation integration test;
1 parent e042f82 commit 1505a25

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

dev/tests/integration/framework/Magento/TestFramework/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ protected function getCustomDirs()
714714
DirectoryList::TMP => [$path => "{$var}/tmp"],
715715
DirectoryList::UPLOAD => [$path => "{$var}/upload"],
716716
DirectoryList::PUB => [$path => "{$this->installDir}/pub"],
717+
DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"]
717718
];
718719
return $customDirs;
719720
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Interception;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem\DriverInterface;
11+
use Magento\TestFramework\Application;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
class PluginListGeneratorTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* Generated plugin list config for frontend scope
18+
*/
19+
const CACHE_ID = 'primary|global|frontend|plugin-list';
20+
21+
/**
22+
* @var PluginListGenerator
23+
*/
24+
private $model;
25+
26+
/**
27+
* @var DirectoryList
28+
*/
29+
private $directoryList;
30+
31+
/**
32+
* @var DriverInterface
33+
*/
34+
private $file;
35+
36+
/**
37+
* @var Application
38+
*/
39+
private $application;
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
protected function setUp(): void
45+
{
46+
$this->application = Bootstrap::getInstance()->getBootstrap()->getApplication();
47+
$this->directoryList = new DirectoryList(BP, $this->getCustomDirs());
48+
$this->file = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
49+
DriverInterface::class
50+
);
51+
$this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
52+
PluginListGenerator::class
53+
);
54+
}
55+
56+
/**
57+
* Test plugin list configuration generation and load.
58+
*/
59+
public function testPluginListConfigGeneration()
60+
{
61+
$scopes = ['frontend'];
62+
$this->model->write($scopes);
63+
$configData = $this->model->load(self::CACHE_ID);
64+
$this->assertNotEmpty($configData[0]);
65+
$this->assertNotEmpty($configData[1]);
66+
$this->assertNotEmpty($configData[2]);
67+
$expected = [
68+
1 => [
69+
0 => 'genericHeaderPlugin',
70+
1 => 'asyncCssLoad',
71+
2 => 'response-http-page-cache'
72+
]
73+
];
74+
// Here in test I assume that this class below has 3 plugins. But the amount of plugins and class itself
75+
// may vary. If it is changed, please update these assertions.
76+
$this->assertArrayHasKey(
77+
'Magento\\Framework\\App\\Response\\Http_sendResponse___self',
78+
$configData[2],
79+
'Processed plugin does not exist in the processed plugins array.'
80+
);
81+
$this->assertSame(
82+
$expected,
83+
$configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'],
84+
'Plugin configurations are not equal'
85+
);
86+
}
87+
88+
/**
89+
* Gets customized directory paths
90+
*
91+
* @return array
92+
*/
93+
private function getCustomDirs()
94+
{
95+
$path = DirectoryList::PATH;
96+
$generated = "{$this->application->getTempDir()}/generated";
97+
98+
return [
99+
DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"],
100+
];
101+
}
102+
103+
/**
104+
* @inheritDoc
105+
*/
106+
protected function tearDown(): void
107+
{
108+
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
109+
. '/' . self::CACHE_ID . '.' . 'php';
110+
111+
if (file_exists($filePath)) {
112+
$this->file->deleteFile($filePath);
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)