|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / vendor / magento / framework / Module / Test / Unit / |
Filename | /home/a/home/dev2.destoffenstraat.com/vendor/magento/framework/Module/Test/Unit/ManagerTest.php |
Size | 3.86 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 07-Jan-2021 21:08 |
Last accessed | 23-Aug-2025 10:56 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\Module\Test\Unit;
use Magento\Framework\Module\Manager;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Module\Output\ConfigInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class ManagerTest extends TestCase
{
/**
* XPath in the configuration of a module output flag
*/
const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled';
/**
* @var Manager
*/
private $_model;
/**
* @var MockObject
*/
private $_moduleList;
/**
* @var MockObject
*/
private $_outputConfig;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->_moduleList = $this->getMockForAbstractClass(ModuleListInterface::class);
$this->_moduleList->expects($this->any())
->method('getOne')
->willReturnMap(
[
['Module_One', ['name' => 'One_Module', 'setup_version' => '1']],
['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']],
['Module_Three', ['name' => 'Two_Three']],
]
);
$this->_outputConfig = $this->getMockForAbstractClass(ConfigInterface::class);
$this->_model = new Manager(
$this->_outputConfig,
$this->_moduleList,
[
'Module_Two' => self::XML_PATH_OUTPUT_ENABLED,
]
);
}
public function testIsEnabled()
{
$this->_moduleList->expects($this->exactly(2))->method('has')->willReturnMap(
[
['Module_Exists', true],
['Module_NotExists', false],
]
);
$this->assertTrue($this->_model->isEnabled('Module_Exists'));
$this->assertFalse($this->_model->isEnabled('Module_NotExists'));
}
public function testIsOutputEnabledReturnsFalseForDisabledModule()
{
$this->_outputConfig->expects($this->any())->method('isSetFlag')->willReturn(true);
$this->assertFalse($this->_model->isOutputEnabled('Disabled_Module'));
}
/**
* @param bool $configValue
* @param bool $expectedResult
* @dataProvider isOutputEnabledGenericConfigPathDataProvider
*/
public function testIsOutputEnabledGenericConfigPath($configValue, $expectedResult)
{
$this->_moduleList->expects($this->once())->method('has')->willReturn(true);
$this->_outputConfig->expects($this->once())
->method('isEnabled')
->with('Module_One')
->willReturn($configValue);
$this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_One'));
}
/**
* @return array
*/
public function isOutputEnabledGenericConfigPathDataProvider()
{
return ['output disabled' => [true, false], 'output enabled' => [false, true]];
}
/**
* @param bool $configValue
* @param bool $expectedResult
* @dataProvider isOutputEnabledCustomConfigPathDataProvider
*/
public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult)
{
$this->_moduleList->expects($this->once())->method('has')->willReturn(true);
$this->_outputConfig->expects($this->at(0))
->method('isSetFlag')
->with(self::XML_PATH_OUTPUT_ENABLED)
->willReturn($configValue);
$this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two'));
}
/**
* @return array
*/
public function isOutputEnabledCustomConfigPathDataProvider()
{
return [
'path literal, output disabled' => [false, false],
'path literal, output enabled' => [true, true],
];
}
}
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\Module\Test\Unit;
use Magento\Framework\Module\Manager;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Module\Output\ConfigInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class ManagerTest extends TestCase
{
/**
* XPath in the configuration of a module output flag
*/
const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled';
/**
* @var Manager
*/
private $_model;
/**
* @var MockObject
*/
private $_moduleList;
/**
* @var MockObject
*/
private $_outputConfig;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->_moduleList = $this->getMockForAbstractClass(ModuleListInterface::class);
$this->_moduleList->expects($this->any())
->method('getOne')
->willReturnMap(
[
['Module_One', ['name' => 'One_Module', 'setup_version' => '1']],
['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']],
['Module_Three', ['name' => 'Two_Three']],
]
);
$this->_outputConfig = $this->getMockForAbstractClass(ConfigInterface::class);
$this->_model = new Manager(
$this->_outputConfig,
$this->_moduleList,
[
'Module_Two' => self::XML_PATH_OUTPUT_ENABLED,
]
);
}
public function testIsEnabled()
{
$this->_moduleList->expects($this->exactly(2))->method('has')->willReturnMap(
[
['Module_Exists', true],
['Module_NotExists', false],
]
);
$this->assertTrue($this->_model->isEnabled('Module_Exists'));
$this->assertFalse($this->_model->isEnabled('Module_NotExists'));
}
public function testIsOutputEnabledReturnsFalseForDisabledModule()
{
$this->_outputConfig->expects($this->any())->method('isSetFlag')->willReturn(true);
$this->assertFalse($this->_model->isOutputEnabled('Disabled_Module'));
}
/**
* @param bool $configValue
* @param bool $expectedResult
* @dataProvider isOutputEnabledGenericConfigPathDataProvider
*/
public function testIsOutputEnabledGenericConfigPath($configValue, $expectedResult)
{
$this->_moduleList->expects($this->once())->method('has')->willReturn(true);
$this->_outputConfig->expects($this->once())
->method('isEnabled')
->with('Module_One')
->willReturn($configValue);
$this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_One'));
}
/**
* @return array
*/
public function isOutputEnabledGenericConfigPathDataProvider()
{
return ['output disabled' => [true, false], 'output enabled' => [false, true]];
}
/**
* @param bool $configValue
* @param bool $expectedResult
* @dataProvider isOutputEnabledCustomConfigPathDataProvider
*/
public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult)
{
$this->_moduleList->expects($this->once())->method('has')->willReturn(true);
$this->_outputConfig->expects($this->at(0))
->method('isSetFlag')
->with(self::XML_PATH_OUTPUT_ENABLED)
->willReturn($configValue);
$this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two'));
}
/**
* @return array
*/
public function isOutputEnabledCustomConfigPathDataProvider()
{
return [
'path literal, output disabled' => [false, false],
'path literal, output enabled' => [true, true],
];
}
}