Skip to content

Commit 5cf97c9

Browse files
committed
Fix issue disabled modules still include less
1 parent 6f79389 commit 5cf97c9

File tree

4 files changed

+153
-5
lines changed

4 files changed

+153
-5
lines changed

app/code/Magento/Developer/etc/di.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@
202202
<argument name="fileSource" xsi:type="object">Magento\Framework\Css\PreProcessor\File\Collector\Aggregated</argument>
203203
</arguments>
204204
</type>
205+
205206
<type name="Magento\Framework\Css\PreProcessor\File\Collector\Aggregated">
206207
<arguments>
207208
<argument name="libraryFiles" xsi:type="object">Magento\Framework\Css\PreProcessor\File\Collector\Library</argument>
208209
<argument name="baseFiles" xsi:type="object">cssSourceBaseFilesSorted</argument>
209-
<argument name="overriddenBaseFiles" xsi:type="object">cssSourceOverriddenBaseFiles</argument>
210+
<argument name="overriddenBaseFiles" xsi:type="object">cssSourceOverriddenBaseFilesSorted</argument>
210211
</arguments>
211212
</type>
212213

@@ -215,17 +216,31 @@
215216
<argument name="subject" xsi:type="object">cssSourceBaseFilesFiltered</argument>
216217
</arguments>
217218
</virtualType>
219+
218220
<virtualType name="cssSourceBaseFilesFiltered" type="Magento\Framework\View\File\Collector\Decorator\ModuleOutput">
219221
<arguments>
220222
<argument name="subject" xsi:type="object">cssSourceBaseFiles</argument>
221223
</arguments>
222224
</virtualType>
225+
223226
<virtualType name="cssSourceBaseFiles" type="Magento\Framework\View\File\Collector\Base">
224227
<arguments>
225228
<argument name="subDir" xsi:type="string">web</argument>
226229
</arguments>
227230
</virtualType>
228231

232+
<virtualType name="cssSourceOverriddenBaseFilesSorted" type="Magento\Framework\View\File\Collector\Decorator\ModuleDependency">
233+
<arguments>
234+
<argument name="subject" xsi:type="object">cssSourceOverriddenBaseFilesFiltered</argument>
235+
</arguments>
236+
</virtualType>
237+
238+
<virtualType name="cssSourceOverriddenBaseFilesFiltered" type="Magento\Framework\View\File\Collector\Decorator\ModuleEnabled">
239+
<arguments>
240+
<argument name="subject" xsi:type="object">cssSourceOverriddenBaseFiles</argument>
241+
</arguments>
242+
</virtualType>
243+
229244
<virtualType name="cssSourceOverriddenBaseFiles" type="Magento\Framework\View\File\Collector\Override\Base">
230245
<arguments>
231246
<argument name="subDir" xsi:type="string">web</argument>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\View\File\Collector\Decorator;
9+
10+
use Magento\Framework\Module\Manager as ModuleManager;
11+
use Magento\Framework\View\Design\ThemeInterface;
12+
use Magento\Framework\View\File;
13+
use Magento\Framework\View\File\CollectorInterface;
14+
15+
class ModuleEnabled implements CollectorInterface
16+
{
17+
/**
18+
* Subject
19+
*
20+
* @var CollectorInterface
21+
*/
22+
private $subject;
23+
24+
/**
25+
* Module manager
26+
*
27+
* @var ModuleManager
28+
*/
29+
private $moduleManager;
30+
31+
/**
32+
* Constructor
33+
*
34+
* @param CollectorInterface $subject
35+
* @param ModuleManager $moduleManager
36+
*/
37+
public function __construct(
38+
CollectorInterface $subject,
39+
ModuleManager $moduleManager
40+
) {
41+
$this->subject = $subject;
42+
$this->moduleManager = $moduleManager;
43+
}
44+
45+
/**
46+
* Retrieve files
47+
*
48+
* Filter out theme files that belong to inactive modules or ones explicitly configured to not produce any output
49+
*
50+
* @param ThemeInterface $theme
51+
* @param string $filePath
52+
* @return File[]
53+
*/
54+
public function getFiles(ThemeInterface $theme, $filePath): array
55+
{
56+
$result = [];
57+
foreach ($this->subject->getFiles($theme, $filePath) as $file) {
58+
if ($this->moduleManager->isEnabled($file->getModule())) {
59+
$result[] = $file;
60+
}
61+
}
62+
return $result;
63+
}
64+
}

lib/internal/Magento/Framework/View/File/Collector/Decorator/ModuleOutput.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Framework\View\File\Collector\Decorator;
88

9-
use Magento\Framework\Module\Manager;
9+
use Magento\Framework\Module\Manager as ModuleManager;
1010
use Magento\Framework\View\Design\ThemeInterface;
1111
use Magento\Framework\View\File;
1212
use Magento\Framework\View\File\CollectorInterface;
@@ -34,11 +34,11 @@ class ModuleOutput implements CollectorInterface
3434
* Constructor
3535
*
3636
* @param CollectorInterface $subject
37-
* @param Manager $moduleManager
37+
* @param ModuleManager $moduleManager
3838
*/
3939
public function __construct(
4040
CollectorInterface $subject,
41-
Manager $moduleManager
41+
ModuleManager $moduleManager
4242
) {
4343
$this->subject = $subject;
4444
$this->moduleManager = $moduleManager;
@@ -51,7 +51,7 @@ public function __construct(
5151
*
5252
* @param ThemeInterface $theme
5353
* @param string $filePath
54-
* @return \Magento\Framework\View\File[]
54+
* @return File[]
5555
*/
5656
public function getFiles(ThemeInterface $theme, $filePath)
5757
{
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\View\Test\Unit\File\Collector\Decorator;
10+
11+
use Magento\Framework\Module\Manager as ModuleManager;
12+
use Magento\Framework\View\Design\ThemeInterface;
13+
use Magento\Framework\View\File;
14+
use Magento\Framework\View\File\Collector\Decorator\ModuleEnabled;
15+
use Magento\Framework\View\File\CollectorInterface;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class ModuleEnabledTest extends TestCase
20+
{
21+
/**
22+
* @var ModuleEnabled
23+
*/
24+
private $model;
25+
26+
/**
27+
* @var CollectorInterface|MockObject
28+
*/
29+
private $fileSourceMock;
30+
31+
/**
32+
* @var ModuleManager|MockObject
33+
*/
34+
private $moduleManagerMock;
35+
36+
protected function setUp(): void
37+
{
38+
$this->fileSourceMock = $this->getMockForAbstractClass(CollectorInterface::class);
39+
$this->moduleManagerMock = $this->createMock(ModuleManager::class);
40+
$this->moduleManagerMock
41+
->expects($this->any())
42+
->method('isEnabled')
43+
->will(
44+
$this->returnValueMap(
45+
[
46+
['Module_Enabled', true],
47+
['Module_Disabled', false],
48+
]
49+
)
50+
);
51+
$this->model = new ModuleEnabled(
52+
$this->fileSourceMock,
53+
$this->moduleManagerMock
54+
);
55+
}
56+
57+
public function testGetFiles(): void
58+
{
59+
$theme = $this->getMockForAbstractClass(ThemeInterface::class);
60+
$fileOne = new File('1.xml', 'Module_Enabled');
61+
$fileTwo = new File('2.xml', 'Module_Disabled');
62+
$fileThree = new File('3.xml', 'Module_Enabled', $theme);
63+
$this->fileSourceMock->expects($this->once())
64+
->method('getFiles')
65+
->with($theme, '*.xml')
66+
->willReturn([$fileOne, $fileTwo, $fileThree]);
67+
$this->assertSame([$fileOne, $fileThree], $this->model->getFiles($theme, '*.xml'));
68+
}
69+
}

0 commit comments

Comments
 (0)