class ModuleRequiredByThemesUninstallValidatorTest in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php \Drupal\Tests\Core\Extension\ModuleRequiredByThemesUninstallValidatorTest
- 10 core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php \Drupal\Tests\Core\Extension\ModuleRequiredByThemesUninstallValidatorTest
@coversDefaultClass \Drupal\Core\Extension\ModuleRequiredByThemesUninstallValidator @group Extension
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Extension\ModuleRequiredByThemesUninstallValidatorTest uses AssertHelperTrait
Expanded class hierarchy of ModuleRequiredByThemesUninstallValidatorTest
File
- core/
tests/ Drupal/ Tests/ Core/ Extension/ ModuleRequiredByThemesUninstallValidatorTest.php, line 15
Namespace
Drupal\Tests\Core\ExtensionView source
class ModuleRequiredByThemesUninstallValidatorTest extends UnitTestCase {
use AssertHelperTrait;
/**
* Instance of ModuleRequiredByThemesUninstallValidator.
*
* @var \Drupal\Core\Extension\ModuleRequiredByThemesUninstallValidator
*/
protected $moduleRequiredByThemeUninstallValidator;
/**
* Mock of ModuleExtensionList.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* Mock of ThemeExtensionList.
*
* @var \Drupal\Core\Extension\ThemeExtensionList
*/
protected $themeExtensionList;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->moduleExtensionList = $this
->prophesize(ModuleExtensionList::class);
$this->themeExtensionList = $this
->prophesize(ThemeExtensionList::class);
$this->moduleRequiredByThemeUninstallValidator = new ModuleRequiredByThemesUninstallValidator($this
->getStringTranslationStub(), $this->moduleExtensionList
->reveal(), $this->themeExtensionList
->reveal());
}
/**
* @covers ::validate
*/
public function testValidateNoThemeDependency() {
$this->themeExtensionList
->getAllInstalledInfo()
->willReturn([
'stable' => [
'name' => 'Stable',
'dependencies' => [],
],
'claro' => [
'name' => 'Claro',
'dependencies' => [],
],
]);
$module = $this
->randomMachineName();
$expected = [];
$reasons = $this->moduleRequiredByThemeUninstallValidator
->validate($module);
$this
->assertSame($expected, $reasons);
}
/**
* @covers ::validate
*/
public function testValidateOneThemeDependency() {
$module = 'single_module';
$module_name = 'Single Module';
$theme = 'one_theme';
$theme_name = 'One Theme';
$this->themeExtensionList
->getAllInstalledInfo()
->willReturn([
'stable' => [
'name' => 'Stable',
'dependencies' => [],
],
'claro' => [
'name' => 'Claro',
'dependencies' => [],
],
$theme => [
'name' => $theme_name,
'dependencies' => [
$module,
],
],
]);
$this->moduleExtensionList
->get($module)
->willReturn((object) [
'info' => [
'name' => $module_name,
],
]);
$expected = [
"Required by the theme: {$theme_name}",
];
$reasons = $this->moduleRequiredByThemeUninstallValidator
->validate($module);
$this
->assertSame($expected, $this
->castSafeStrings($reasons));
}
/**
* @covers ::validate
*/
public function testValidateTwoThemeDependencies() {
$module = 'popular_module';
$module_name = 'Popular Module';
$theme1 = 'first_theme';
$theme2 = 'second_theme';
$theme_name_1 = 'First Theme';
$theme_name_2 = 'Second Theme';
$this->themeExtensionList
->getAllInstalledInfo()
->willReturn([
'stable' => [
'name' => 'Stable',
'dependencies' => [],
],
'claro' => [
'name' => 'Claro',
'dependencies' => [],
],
$theme1 => [
'name' => $theme_name_1,
'dependencies' => [
$module,
],
],
$theme2 => [
'name' => $theme_name_2,
'dependencies' => [
$module,
],
],
]);
$this->moduleExtensionList
->get($module)
->willReturn((object) [
'info' => [
'name' => $module_name,
],
]);
$expected = [
"Required by the themes: {$theme_name_1}, {$theme_name_2}",
];
$reasons = $this->moduleRequiredByThemeUninstallValidator
->validate($module);
$this
->assertSame($expected, $this
->castSafeStrings($reasons));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertHelperTrait:: |
protected static | function | Casts MarkupInterface objects into strings. | |
ModuleRequiredByThemesUninstallValidatorTest:: |
protected | property | Mock of ModuleExtensionList. | |
ModuleRequiredByThemesUninstallValidatorTest:: |
protected | property | Instance of ModuleRequiredByThemesUninstallValidator. | |
ModuleRequiredByThemesUninstallValidatorTest:: |
protected | property | Mock of ThemeExtensionList. | |
ModuleRequiredByThemesUninstallValidatorTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ModuleRequiredByThemesUninstallValidatorTest:: |
public | function | @covers ::validate | |
ModuleRequiredByThemesUninstallValidatorTest:: |
public | function | @covers ::validate | |
ModuleRequiredByThemesUninstallValidatorTest:: |
public | function | @covers ::validate | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |