RequiredModuleUninstallValidatorTest.php in Drupal 9
File
core/tests/Drupal/Tests/Core/Extension/RequiredModuleUninstallValidatorTest.php
View source
<?php
namespace Drupal\Tests\Core\Extension;
use Drupal\Tests\UnitTestCase;
class RequiredModuleUninstallValidatorTest extends UnitTestCase {
protected $uninstallValidator;
protected function setUp() : void {
parent::setUp();
$this->uninstallValidator = $this
->getMockBuilder('Drupal\\Core\\Extension\\RequiredModuleUninstallValidator')
->disableOriginalConstructor()
->setMethods([
'getModuleInfoByModule',
])
->getMock();
$this->uninstallValidator
->setStringTranslation($this
->getStringTranslationStub());
}
public function testValidateNoModule() {
$this->uninstallValidator
->expects($this
->once())
->method('getModuleInfoByModule')
->willReturn([]);
$module = $this
->randomMachineName();
$expected = [];
$reasons = $this->uninstallValidator
->validate($module);
$this
->assertSame($expected, $reasons);
}
public function testValidateNotRequired() {
$module = $this
->randomMachineName();
$this->uninstallValidator
->expects($this
->once())
->method('getModuleInfoByModule')
->willReturn([
'required' => FALSE,
'name' => $module,
]);
$expected = [];
$reasons = $this->uninstallValidator
->validate($module);
$this
->assertSame($expected, $reasons);
}
public function testValidateRequired() {
$module = $this
->randomMachineName();
$this->uninstallValidator
->expects($this
->once())
->method('getModuleInfoByModule')
->willReturn([
'required' => TRUE,
'name' => $module,
]);
$expected = [
"The {$module} module is required",
];
$reasons = $this->uninstallValidator
->validate($module);
$this
->assertEquals($expected, $reasons);
}
}