Skip to content

Fix 24666 disabled modules still included less files #27888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/code/Magento/Developer/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@
<argument name="fileSource" xsi:type="object">Magento\Framework\Css\PreProcessor\File\Collector\Aggregated</argument>
</arguments>
</type>

<type name="Magento\Framework\Css\PreProcessor\File\Collector\Aggregated">
<arguments>
<argument name="libraryFiles" xsi:type="object">Magento\Framework\Css\PreProcessor\File\Collector\Library</argument>
<argument name="baseFiles" xsi:type="object">cssSourceBaseFilesSorted</argument>
<argument name="overriddenBaseFiles" xsi:type="object">cssSourceOverriddenBaseFiles</argument>
<argument name="overriddenBaseFiles" xsi:type="object">cssSourceOverriddenBaseFilesSorted</argument>
</arguments>
</type>

Expand All @@ -215,17 +216,31 @@
<argument name="subject" xsi:type="object">cssSourceBaseFilesFiltered</argument>
</arguments>
</virtualType>

<virtualType name="cssSourceBaseFilesFiltered" type="Magento\Framework\View\File\Collector\Decorator\ModuleOutput">
<arguments>
<argument name="subject" xsi:type="object">cssSourceBaseFiles</argument>
</arguments>
</virtualType>

<virtualType name="cssSourceBaseFiles" type="Magento\Framework\View\File\Collector\Base">
<arguments>
<argument name="subDir" xsi:type="string">web</argument>
</arguments>
</virtualType>

<virtualType name="cssSourceOverriddenBaseFilesSorted" type="Magento\Framework\View\File\Collector\Decorator\ModuleDependency">
<arguments>
<argument name="subject" xsi:type="object">cssSourceOverriddenBaseFilesFiltered</argument>
</arguments>
</virtualType>

<virtualType name="cssSourceOverriddenBaseFilesFiltered" type="Magento\Framework\View\File\Collector\Decorator\ModuleEnabled">
<arguments>
<argument name="subject" xsi:type="object">cssSourceOverriddenBaseFiles</argument>
</arguments>
</virtualType>

<virtualType name="cssSourceOverriddenBaseFiles" type="Magento\Framework\View\File\Collector\Override\Base">
<arguments>
<argument name="subDir" xsi:type="string">web</argument>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

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

use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\View\Design\ThemeInterface;
use Magento\Framework\View\File;
use Magento\Framework\View\File\CollectorInterface;

class ModuleEnabled implements CollectorInterface
{
/**
* Subject
*
* @var CollectorInterface
*/
private $subject;

/**
* Module manager
*
* @var ModuleManager
*/
private $moduleManager;

/**
* Constructor
*
* @param CollectorInterface $subject
* @param ModuleManager $moduleManager
*/
public function __construct(
CollectorInterface $subject,
ModuleManager $moduleManager
) {
$this->subject = $subject;
$this->moduleManager = $moduleManager;
}

/**
* Retrieve files
*
* Filter out theme files that belong to inactive modules or ones explicitly configured to not produce any output
*
* @param ThemeInterface $theme
* @param string $filePath
* @return File[]
*/
public function getFiles(ThemeInterface $theme, $filePath): array
{
$result = [];
foreach ($this->subject->getFiles($theme, $filePath) as $file) {
if ($this->moduleManager->isEnabled($file->getModule())) {
$result[] = $file;
}
}
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

use Magento\Framework\Module\Manager;
use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\View\Design\ThemeInterface;
use Magento\Framework\View\File;
use Magento\Framework\View\File\CollectorInterface;
Expand Down Expand Up @@ -34,11 +34,11 @@ class ModuleOutput implements CollectorInterface
* Constructor
*
* @param CollectorInterface $subject
* @param Manager $moduleManager
* @param ModuleManager $moduleManager
*/
public function __construct(
CollectorInterface $subject,
Manager $moduleManager
ModuleManager $moduleManager
) {
$this->subject = $subject;
$this->moduleManager = $moduleManager;
Expand All @@ -51,7 +51,7 @@ public function __construct(
*
* @param ThemeInterface $theme
* @param string $filePath
* @return \Magento\Framework\View\File[]
* @return File[]
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\View\Test\Unit\File\Collector\Decorator;

use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\View\Design\ThemeInterface;
use Magento\Framework\View\File;
use Magento\Framework\View\File\Collector\Decorator\ModuleEnabled;
use Magento\Framework\View\File\CollectorInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ModuleEnabledTest extends TestCase
{
/**
* @var ModuleEnabled
*/
private $model;

/**
* @var CollectorInterface|MockObject
*/
private $fileSourceMock;

/**
* @var ModuleManager|MockObject
*/
private $moduleManagerMock;

protected function setUp(): void
{
$this->fileSourceMock = $this->getMockForAbstractClass(CollectorInterface::class);
$this->moduleManagerMock = $this->createMock(ModuleManager::class);
$this->moduleManagerMock
->expects($this->any())
->method('isEnabled')
->will(
$this->returnValueMap(
[
['Module_Enabled', true],
['Module_Disabled', false],
]
)
);
$this->model = new ModuleEnabled(
$this->fileSourceMock,
$this->moduleManagerMock
);
}

public function testGetFiles(): void
{
$theme = $this->getMockForAbstractClass(ThemeInterface::class);
$fileOne = new File('1.xml', 'Module_Enabled');
$fileTwo = new File('2.xml', 'Module_Disabled');
$fileThree = new File('3.xml', 'Module_Enabled', $theme);
$this->fileSourceMock->expects($this->once())
->method('getFiles')
->with($theme, '*.xml')
->willReturn([$fileOne, $fileTwo, $fileThree]);
$this->assertSame([$fileOne, $fileThree], $this->model->getFiles($theme, '*.xml'));
}
}