View source
<?php
namespace Drupal\system\Tests\Extension;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ExtensionNameLengthException;
use Drupal\simpletest\KernelTestBase;
class ThemeInstallerTest extends KernelTestBase {
public static $modules = array(
'system',
);
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
$container
->register('router.dumper', 'Drupal\\Core\\Routing\\NullMatcherDumper');
}
protected function setUp() {
parent::setUp();
$this
->installConfig(array(
'system',
));
}
function testEmpty() {
$this
->assertFalse($this
->extensionConfig()
->get('theme'));
$this
->assertFalse(array_keys($this
->themeHandler()
->listInfo()));
$this
->assertFalse(array_keys(system_list('theme')));
$this
->assertTrue($this
->themeHandler()
->rebuildThemeData()['stark'], 'ThemeHandler::rebuildThemeData() yields all available themes.');
$this
->assertIdentical(theme_get_setting('features.favicon'), TRUE);
}
function testInstall() {
$name = 'test_basetheme';
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(isset($themes[$name]));
$this
->themeInstaller()
->install(array(
$name,
));
$this
->assertIdentical($this
->extensionConfig()
->get("theme.{$name}"), 0);
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertEqual($themes[$name]
->getName(), $name);
$this
->assertEqual(array_keys(system_list('theme')), array_keys($themes));
$this
->assertIdentical(theme_get_setting('features.favicon', $name), FALSE);
$this
->assertEqual(theme_get_setting('base', $name), 'only');
$this
->assertEqual(theme_get_setting('override', $name), 'base');
}
function testInstallSubTheme() {
$name = 'test_subtheme';
$base_name = 'test_basetheme';
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(array_keys($themes));
$this
->themeInstaller()
->install(array(
$name,
));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertTrue(isset($themes[$base_name]));
$this
->themeInstaller()
->uninstall(array(
$name,
));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(isset($themes[$name]));
$this
->assertTrue(isset($themes[$base_name]));
}
function testInstallNonExisting() {
$name = 'non_existing_theme';
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(array_keys($themes));
try {
$message = 'ThemeHandler::install() throws InvalidArgumentException upon installing a non-existing theme.';
$this
->themeInstaller()
->install(array(
$name,
));
$this
->fail($message);
} catch (\InvalidArgumentException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(array_keys($themes));
}
function testInstallNameTooLong() {
$name = 'test_theme_having_veery_long_name_which_is_too_long';
try {
$message = 'ThemeHandler::install() throws ExtensionNameLengthException upon installing a theme with a too long name.';
$this
->themeInstaller()
->install(array(
$name,
));
$this
->fail($message);
} catch (ExtensionNameLengthException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
}
function testUninstallDefault() {
$name = 'stark';
$other_name = 'bartik';
$this
->themeInstaller()
->install(array(
$name,
$other_name,
));
$this
->themeHandler()
->setDefault($name);
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertTrue(isset($themes[$other_name]));
try {
$message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon disabling default theme.';
$this
->themeHandler()
->uninstall(array(
$name,
));
$this
->fail($message);
} catch (\InvalidArgumentException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertTrue(isset($themes[$other_name]));
}
function testUninstallAdmin() {
$name = 'stark';
$other_name = 'bartik';
$this
->themeInstaller()
->install(array(
$name,
$other_name,
));
$this
->config('system.theme')
->set('admin', $name)
->save();
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertTrue(isset($themes[$other_name]));
try {
$message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon disabling admin theme.';
$this
->themeHandler()
->uninstall(array(
$name,
));
$this
->fail($message);
} catch (\InvalidArgumentException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertTrue(isset($themes[$other_name]));
}
function testUninstallSubTheme() {
$name = 'test_subtheme';
$base_name = 'test_basetheme';
$this
->themeInstaller()
->install(array(
$name,
));
$this
->themeInstaller()
->uninstall(array(
$name,
));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(isset($themes[$name]));
$this
->assertTrue(isset($themes[$base_name]));
}
function testUninstallBaseBeforeSubTheme() {
$name = 'test_basetheme';
$sub_name = 'test_subtheme';
$this
->themeInstaller()
->install(array(
$sub_name,
));
try {
$message = 'ThemeHandler::install() throws InvalidArgumentException upon uninstalling base theme before sub theme.';
$this
->themeInstaller()
->uninstall(array(
$name,
));
$this
->fail($message);
} catch (\InvalidArgumentException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertTrue(isset($themes[$sub_name]));
$this
->themeInstaller()
->uninstall(array(
$name,
$sub_name,
));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(isset($themes[$name]));
$this
->assertFalse(isset($themes[$sub_name]));
}
function testUninstallNonExisting() {
$name = 'non_existing_theme';
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(array_keys($themes));
try {
$message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon uninstalling a non-existing theme.';
$this
->themeInstaller()
->uninstall(array(
$name,
));
$this
->fail($message);
} catch (\InvalidArgumentException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(array_keys($themes));
}
function testUninstall() {
$name = 'test_basetheme';
$this
->themeInstaller()
->install(array(
$name,
));
$this
->assertTrue($this
->config("{$name}.settings")
->get());
$this
->themeInstaller()
->uninstall(array(
$name,
));
$this
->assertFalse(array_keys($this
->themeHandler()
->listInfo()));
$this
->assertFalse(array_keys(system_list('theme')));
$this
->assertFalse($this
->config("{$name}.settings")
->get());
$this
->themeInstaller()
->install(array(
$name,
));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]));
$this
->assertEqual($themes[$name]
->getName(), $name);
$this
->assertEqual(array_keys(system_list('theme')), array_keys($themes));
$this
->assertTrue($this
->config("{$name}.settings")
->get());
}
function testUninstallNotInstalled() {
$name = 'test_basetheme';
try {
$message = 'ThemeHandler::uninstall() throws InvalidArgumentException upon uninstalling a theme that is not installed.';
$this
->themeInstaller()
->uninstall(array(
$name,
));
$this
->fail($message);
} catch (\InvalidArgumentException $e) {
$this
->pass(get_class($e) . ': ' . $e
->getMessage());
}
}
function testThemeInfoAlter() {
$name = 'seven';
$this->container
->get('state')
->set('module_test.hook_system_info_alter', TRUE);
$this
->themeInstaller()
->install(array(
$name,
));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(isset($themes[$name]->info['regions']['test_region']));
system_rebuild_module_data();
$this
->moduleInstaller()
->install(array(
'module_test',
), FALSE);
$this
->assertTrue($this
->moduleHandler()
->moduleExists('module_test'));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertTrue(isset($themes[$name]->info['regions']['test_region']));
$info = system_get_info('theme', $name);
$this
->assertTrue(isset($info['regions']['test_region']));
$regions = system_region_list($name);
$this
->assertTrue(isset($regions['test_region']));
$system_list = system_list('theme');
$this
->assertTrue(isset($system_list[$name]->info['regions']['test_region']));
$this
->moduleInstaller()
->uninstall(array(
'module_test',
));
$this
->assertFalse($this
->moduleHandler()
->moduleExists('module_test'));
$themes = $this
->themeHandler()
->listInfo();
$this
->assertFalse(isset($themes[$name]->info['regions']['test_region']));
$info = system_get_info('theme', $name);
$this
->assertFalse(isset($info['regions']['test_region']));
$regions = system_region_list($name);
$this
->assertFalse(isset($regions['test_region']));
$system_list = system_list('theme');
$this
->assertFalse(isset($system_list[$name]->info['regions']['test_region']));
}
protected function themeHandler() {
return $this->container
->get('theme_handler');
}
protected function themeInstaller() {
return $this->container
->get('theme_installer');
}
protected function extensionConfig() {
return $this
->config('core.extension');
}
protected function moduleHandler() {
return $this->container
->get('module_handler');
}
protected function moduleInstaller() {
return $this->container
->get('module_installer');
}
}