class ModuleRequiredByThemesUninstallValidatorTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php \Drupal\Tests\Core\Extension\ModuleRequiredByThemesUninstallValidatorTest
  2. 8.9.x core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php \Drupal\Tests\Core\Extension\ModuleRequiredByThemesUninstallValidatorTest
  3. 11.x core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php \Drupal\Tests\Core\Extension\ModuleRequiredByThemesUninstallValidatorTest

@coversDefaultClass \Drupal\Core\Extension\ModuleRequiredByThemesUninstallValidator @group Extension

Hierarchy

Expanded class hierarchy of ModuleRequiredByThemesUninstallValidatorTest

File

core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php, line 16

Namespace

Drupal\Tests\Core\Extension
View source
class ModuleRequiredByThemesUninstallValidatorTest extends UnitTestCase {
    
    /**
     * 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() : void {
        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() : void {
        $this->themeExtensionList
            ->getAllInstalledInfo()
            ->willReturn([
            'stable9' => [
                'name' => 'Stable 9',
                'dependencies' => [],
            ],
            'claro' => [
                'name' => 'Claro',
                'dependencies' => [],
            ],
        ]);
        $module = $this->randomMachineName();
        $expected = [];
        $reasons = $this->moduleRequiredByThemeUninstallValidator
            ->validate($module);
        $this->assertSame($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateOneThemeDependency() : void {
        $module = 'single_module';
        $module_name = 'Single Module';
        $theme = 'one_theme';
        $theme_name = 'One Theme';
        $this->themeExtensionList
            ->getAllInstalledInfo()
            ->willReturn([
            'stable9' => [
                'name' => 'Stable 9',
                '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->assertEquals($expected, $reasons);
    }
    
    /**
     * @covers ::validate
     */
    public function testValidateTwoThemeDependencies() : void {
        $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([
            'stable9' => [
                'name' => 'Stable 9',
                '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->assertEquals($expected, $reasons);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
ModuleRequiredByThemesUninstallValidatorTest::$moduleExtensionList protected property Mock of ModuleExtensionList.
ModuleRequiredByThemesUninstallValidatorTest::$moduleRequiredByThemeUninstallValidator protected property Instance of ModuleRequiredByThemesUninstallValidator.
ModuleRequiredByThemesUninstallValidatorTest::$themeExtensionList protected property Mock of ThemeExtensionList.
ModuleRequiredByThemesUninstallValidatorTest::setUp protected function Overrides UnitTestCase::setUp
ModuleRequiredByThemesUninstallValidatorTest::testValidateNoThemeDependency public function @covers ::validate
ModuleRequiredByThemesUninstallValidatorTest::testValidateOneThemeDependency public function @covers ::validate
ModuleRequiredByThemesUninstallValidatorTest::testValidateTwoThemeDependencies public function @covers ::validate
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.