ManagerTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Module\Test\Unit;
  7. class ManagerTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * XPath in the configuration of a module output flag
  11. */
  12. const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled';
  13. /**
  14. * @var \Magento\Framework\Module\Manager
  15. */
  16. private $_model;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $_moduleList;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $_outputConfig;
  25. /**
  26. * @inheritdoc
  27. */
  28. protected function setUp()
  29. {
  30. $this->_moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class);
  31. $this->_moduleList->expects($this->any())
  32. ->method('getOne')
  33. ->will($this->returnValueMap([
  34. ['Module_One', ['name' => 'One_Module', 'setup_version' => '1']],
  35. ['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']],
  36. ['Module_Three', ['name' => 'Two_Three']],
  37. ]));
  38. $this->_outputConfig = $this->getMockForAbstractClass(\Magento\Framework\Module\Output\ConfigInterface::class);
  39. $this->_model = new \Magento\Framework\Module\Manager(
  40. $this->_outputConfig,
  41. $this->_moduleList,
  42. [
  43. 'Module_Two' => self::XML_PATH_OUTPUT_ENABLED,
  44. ]
  45. );
  46. }
  47. public function testIsEnabled()
  48. {
  49. $this->_moduleList->expects($this->exactly(2))->method('has')->will($this->returnValueMap([
  50. ['Module_Exists', true],
  51. ['Module_NotExists', false],
  52. ]));
  53. $this->assertTrue($this->_model->isEnabled('Module_Exists'));
  54. $this->assertFalse($this->_model->isEnabled('Module_NotExists'));
  55. }
  56. public function testIsOutputEnabledReturnsFalseForDisabledModule()
  57. {
  58. $this->_outputConfig->expects($this->any())->method('isSetFlag')->will($this->returnValue(true));
  59. $this->assertFalse($this->_model->isOutputEnabled('Disabled_Module'));
  60. }
  61. /**
  62. * @param bool $configValue
  63. * @param bool $expectedResult
  64. * @dataProvider isOutputEnabledGenericConfigPathDataProvider
  65. */
  66. public function testIsOutputEnabledGenericConfigPath($configValue, $expectedResult)
  67. {
  68. $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true));
  69. $this->_outputConfig->expects($this->once())
  70. ->method('isEnabled')
  71. ->with('Module_One')
  72. ->will($this->returnValue($configValue));
  73. $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_One'));
  74. }
  75. /**
  76. * @return array
  77. */
  78. public function isOutputEnabledGenericConfigPathDataProvider()
  79. {
  80. return ['output disabled' => [true, false], 'output enabled' => [false, true]];
  81. }
  82. /**
  83. * @param bool $configValue
  84. * @param bool $expectedResult
  85. * @dataProvider isOutputEnabledCustomConfigPathDataProvider
  86. */
  87. public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult)
  88. {
  89. $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true));
  90. $this->_outputConfig->expects($this->at(0))
  91. ->method('isSetFlag')
  92. ->with(self::XML_PATH_OUTPUT_ENABLED)
  93. ->will($this->returnValue($configValue));
  94. $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two'));
  95. }
  96. /**
  97. * @return array
  98. */
  99. public function isOutputEnabledCustomConfigPathDataProvider()
  100. {
  101. return [
  102. 'path literal, output disabled' => [false, false],
  103. 'path literal, output enabled' => [true, true],
  104. ];
  105. }
  106. }