Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ManagerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ManagerTest extends \PHPUnit\Framework\TestCase
9 {
13  const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled';
14 
18  private $_model;
19 
23  private $_moduleList;
24 
28  private $_outputConfig;
29 
33  protected function setUp()
34  {
35  $this->_moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class);
36  $this->_moduleList->expects($this->any())
37  ->method('getOne')
38  ->will($this->returnValueMap([
39  ['Module_One', ['name' => 'One_Module', 'setup_version' => '1']],
40  ['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']],
41  ['Module_Three', ['name' => 'Two_Three']],
42  ]));
43  $this->_outputConfig = $this->getMockForAbstractClass(\Magento\Framework\Module\Output\ConfigInterface::class);
44  $this->_model = new \Magento\Framework\Module\Manager(
45  $this->_outputConfig,
46  $this->_moduleList,
47  [
48  'Module_Two' => self::XML_PATH_OUTPUT_ENABLED,
49  ]
50  );
51  }
52 
53  public function testIsEnabled()
54  {
55  $this->_moduleList->expects($this->exactly(2))->method('has')->will($this->returnValueMap([
56  ['Module_Exists', true],
57  ['Module_NotExists', false],
58  ]));
59  $this->assertTrue($this->_model->isEnabled('Module_Exists'));
60  $this->assertFalse($this->_model->isEnabled('Module_NotExists'));
61  }
62 
64  {
65  $this->_outputConfig->expects($this->any())->method('isSetFlag')->will($this->returnValue(true));
66  $this->assertFalse($this->_model->isOutputEnabled('Disabled_Module'));
67  }
68 
74  public function testIsOutputEnabledGenericConfigPath($configValue, $expectedResult)
75  {
76  $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true));
77  $this->_outputConfig->expects($this->once())
78  ->method('isEnabled')
79  ->with('Module_One')
80  ->will($this->returnValue($configValue));
81  $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_One'));
82  }
83 
88  {
89  return ['output disabled' => [true, false], 'output enabled' => [false, true]];
90  }
91 
97  public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult)
98  {
99  $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true));
100  $this->_outputConfig->expects($this->at(0))
101  ->method('isSetFlag')
102  ->with(self::XML_PATH_OUTPUT_ENABLED)
103  ->will($this->returnValue($configValue));
104  $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two'));
105  }
106 
111  {
112  return [
113  'path literal, output disabled' => [false, false],
114  'path literal, output enabled' => [true, true],
115  ];
116  }
117 }
testIsOutputEnabledGenericConfigPath($configValue, $expectedResult)
Definition: ManagerTest.php:74
testIsOutputEnabledCustomConfigPath($configValue, $expectedResult)
Definition: ManagerTest.php:97