Skip to content

Commit 15eeba8

Browse files
author
Eric Bohanon
committed
MAGETWO-71257: Need to disable module output by configuration
1 parent bd65ca4 commit 15eeba8

File tree

3 files changed

+63
-70
lines changed

3 files changed

+63
-70
lines changed

lib/internal/Magento/Framework/Module/Manager.php

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
/**
8+
* Module statuses manager
9+
*/
710
namespace Magento\Framework\Module;
811

912
/**
@@ -17,84 +20,82 @@
1720
class Manager
1821
{
1922
/**
20-
* The checker of output modules.
21-
*
22-
* @var Output\ConfigInterface the config checker of output modules.
23+
* @var Output\ConfigInterface
2324
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version.
2425
* The property can be removed in a future major release
2526
*/
26-
private $outputConfig;
27+
private $_outputConfig;
2728

2829
/**
29-
* The list of all modules.
30-
*
31-
* @var ModuleListInterface the list of all modules.
30+
* @var ModuleListInterface
3231
*/
33-
private $moduleList;
32+
private $_moduleList;
3433

3534
/**
36-
* The list of config paths to ignore.
37-
*
38-
* @var array the list of config paths to ignore.
35+
* @var array
3936
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version.
4037
* The property can be removed in a future major release
4138
*/
42-
private $outputConfigPaths;
39+
private $_outputConfigPaths;
4340

4441
/**
45-
* Constructor.
46-
*
47-
* @param Output\ConfigInterface $outputConfig the checker of output modules
48-
* @param ModuleListInterface $moduleList the list of all modules
49-
* @param array $outputConfigPaths the list of config paths to ignore
42+
* @param Output\ConfigInterface $outputConfig
43+
* @param ModuleListInterface $moduleList
44+
* @param array $outputConfigPaths
5045
*/
5146
public function __construct(
5247
Output\ConfigInterface $outputConfig,
5348
ModuleListInterface $moduleList,
5449
array $outputConfigPaths = []
5550
) {
56-
$this->outputConfig = $outputConfig;
57-
$this->moduleList = $moduleList;
58-
$this->outputConfigPaths = $outputConfigPaths;
51+
$this->_outputConfig = $outputConfig;
52+
$this->_moduleList = $moduleList;
53+
$this->_outputConfigPaths = $outputConfigPaths;
5954
}
6055

6156
/**
62-
* Checks whether a module is enabled in the configuration or not.
57+
* Whether a module is enabled in the configuration or not
6358
*
64-
* @param string $moduleName the fully-qualified module name
65-
*
66-
* @return boolean true if module is enabled, false otherwise
59+
* @param string $moduleName Fully-qualified module name
60+
* @return boolean
6761
*/
6862
public function isEnabled($moduleName)
6963
{
70-
return $this->moduleList->has($moduleName);
64+
return $this->_moduleList->has($moduleName);
7165
}
7266

7367
/**
74-
* Checks whether a module output is permitted by the configuration or not.
75-
*
76-
* @param string $moduleName the fully-qualified module name.
68+
* Whether a module output is permitted by the configuration or not
7769
*
70+
* @param string $moduleName Fully-qualified module name
7871
* @return boolean
7972
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
8073
*/
8174
public function isOutputEnabled($moduleName)
8275
{
83-
return $this->isEnabled($moduleName);
76+
if (!$this->isEnabled($moduleName)) {
77+
return false;
78+
}
79+
80+
return true;
8481
}
8582

8683
/**
87-
* Checks whether a configuration switch for a module output permits output.
84+
* Whether a configuration switch for a module output permits output or not
8885
*
8986
* @param string $moduleName Fully-qualified module name
90-
*
9187
* @return boolean
92-
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version.
93-
* The method can be removed in a future major release
94-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
88+
* @deprecated
9589
*/
9690
protected function _isCustomOutputConfigEnabled($moduleName)
9791
{
92+
if (isset($this->_outputConfigPaths[$moduleName])) {
93+
$configPath = $this->_outputConfigPaths[$moduleName];
94+
if (defined($configPath)) {
95+
$configPath = constant($configPath);
96+
}
97+
return $this->_outputConfig->isSetFlag($configPath);
98+
}
9899
return true;
99100
}
100101
}

lib/internal/Magento/Framework/Module/Output/ConfigInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
*/
66
namespace Magento\Framework\Module\Output;
77

8-
/**
9-
* Checks whether the module is enabled in the configuration.
10-
*
11-
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
12-
*/
138
interface ConfigInterface
149
{
1510
/**

lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,60 @@
55
*/
66
namespace Magento\Framework\Module\Test\Unit;
77

8-
use Magento\Framework\Module\Manager;
9-
use Magento\Framework\Module\ModuleListInterface;
10-
use Magento\Framework\Module\Output\ConfigInterface;
11-
use \PHPUnit_Framework_MockObject_MockObject as Mock;
8+
use Magento\Framework\Module\Plugin\DbStatusValidator;
129

1310
class ManagerTest extends \PHPUnit\Framework\TestCase
1411
{
1512
/**
1613
* XPath in the configuration of a module output flag
17-
* @deprecated
1814
*/
1915
const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled';
2016

2117
/**
22-
* @var Manager
18+
* @var \Magento\Framework\Module\Manager
2319
*/
24-
private $model;
20+
private $_model;
2521

2622
/**
27-
* @var ModuleListInterface|Mock
23+
* @var \PHPUnit_Framework_MockObject_MockObject
2824
*/
29-
private $moduleList;
25+
private $_moduleList;
3026

3127
/**
32-
* @var ConfigInterface|Mock
33-
* @deprecated
28+
* @var \PHPUnit_Framework_MockObject_MockObject
3429
*/
35-
private $outputConfig;
30+
private $_outputConfig;
3631

3732
/**
3833
* @inheritdoc
3934
*/
4035
protected function setUp()
4136
{
42-
$this->moduleList = $this->getMockBuilder(ModuleListInterface::class)
43-
->getMockForAbstractClass();
44-
$this->outputConfig = $this->getMockBuilder(ConfigInterface::class)
45-
->getMockForAbstractClass();
46-
47-
$this->model = new Manager(
48-
$this->outputConfig,
49-
$this->moduleList
37+
$this->_moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class);
38+
$this->_moduleList->expects($this->any())
39+
->method('getOne')
40+
->will($this->returnValueMap([
41+
['Module_One', ['name' => 'One_Module', 'setup_version' => '1']],
42+
['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']],
43+
['Module_Three', ['name' => 'Two_Three']],
44+
]));
45+
$this->_outputConfig = $this->getMockForAbstractClass(\Magento\Framework\Module\Output\ConfigInterface::class);
46+
$this->_model = new \Magento\Framework\Module\Manager(
47+
$this->_outputConfig,
48+
$this->_moduleList,
49+
[
50+
'Module_Two' => self::XML_PATH_OUTPUT_ENABLED,
51+
]
5052
);
5153
}
5254

5355
public function testIsEnabled()
5456
{
55-
$this->moduleList->expects($this->exactly(2))
56-
->method('has')
57-
->willReturnMap(
58-
[
59-
['Module_Exists', true],
60-
['Module_NotExists', false],
61-
]
62-
);
63-
64-
$this->assertTrue($this->model->isEnabled('Module_Exists'));
65-
$this->assertFalse($this->model->isEnabled('Module_NotExists'));
57+
$this->_moduleList->expects($this->exactly(2))->method('has')->will($this->returnValueMap([
58+
['Module_Exists', true],
59+
['Module_NotExists', false],
60+
]));
61+
$this->assertTrue($this->_model->isEnabled('Module_Exists'));
62+
$this->assertFalse($this->_model->isEnabled('Module_NotExists'));
6663
}
6764
}

0 commit comments

Comments
 (0)