Commit 6b46e5d3 authored by webchick's avatar webchick

Issue #2188991 by tim.plunkett: Use ThemeHandler instead of list_themes() in unit tests.

parent dca2d601
......@@ -9,6 +9,7 @@
use Drupal\Component\Plugin\Derivative\DerivativeBase;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -24,21 +25,34 @@ class ThemeLocalTask extends DerivativeBase implements ContainerDerivativeInterf
*/
protected $config;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* Constructs a new ThemeLocalTask.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The config factory.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
*/
public function __construct(ConfigFactory $config_factory) {
public function __construct(ConfigFactory $config_factory, ThemeHandlerInterface $theme_handler) {
$this->config = $config_factory->get('system.theme');
$this->themeHandler = $theme_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container->get('config.factory'));
return new static(
$container->get('config.factory'),
$container->get('theme_handler')
);
}
/**
......@@ -47,7 +61,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
public function getDerivativeDefinitions(array $base_plugin_definition) {
$default_theme = $this->config->get('default');
foreach (list_themes() as $theme_name => $theme) {
foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
if ($theme->status) {
$this->derivatives[$theme_name] = $base_plugin_definition;
$this->derivatives[$theme_name]['title'] = $theme->info['name'];
......
......@@ -5,9 +5,10 @@
* Contains \Drupal\block\Tests\Menu\BlockLocalTasksTest.
*/
namespace Drupal\block\Tests\Menu {
namespace Drupal\block\Tests\Menu;
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTest;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Tests existence of block local tasks.
......@@ -32,7 +33,32 @@ public function setUp() {
$config_factory = $this->getConfigFactoryStub(array('system.theme' => array(
'default' => 'test_c',
)));
\Drupal::getContainer()->set('config.factory', $config_factory);
$themes = array();
$themes['test_a'] = (object) array(
'status' => 0,
);
$themes['test_b'] = (object) array(
'status' => 1,
'info' => array(
'name' => 'test_b',
),
);
$themes['test_c'] = (object) array(
'status' => 1,
'info' => array(
'name' => 'test_c',
),
);
$theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
$theme_handler->expects($this->any())
->method('listInfo')
->will($this->returnValue($themes));
$container = new ContainerBuilder();
$container->set('config.factory', $config_factory);
$container->set('theme_handler', $theme_handler);
\Drupal::setContainer($container);
}
/**
......@@ -62,30 +88,3 @@ public function providerTestBlockAdminDisplay() {
}
}
}
namespace {
if (!function_exists('list_themes')) {
function list_themes() {
$themes = array();
$themes['test_a'] = (object) array(
'status' => 0,
);
$themes['test_b'] = (object) array(
'status' => 1,
'info' => array(
'name' => 'test_b',
),
);
$themes['test_c'] = (object) array(
'status' => 1,
'info' => array(
'name' => 'test_c',
),
);
return $themes;
}
}
}
......@@ -24,3 +24,4 @@ services:
- '@language_manager'
- '@module_handler'
- '@config.typed'
- '@theme_handler'
......@@ -13,6 +13,7 @@
use Drupal\Core\Config\Schema\ArrayElement;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\InfoHookDecorator;
......@@ -55,7 +56,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
* @param \Drupal\Core\Config\TypedConfigManager $typed_config_manager
* The typed config manager.
*/
public function __construct(CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedConfigManager $typed_config_manager) {
public function __construct(CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedConfigManager $typed_config_manager, ThemeHandlerInterface $theme_handler) {
$this->typedConfigManager = $typed_config_manager;
// Look at all themes and modules.
......@@ -63,8 +64,8 @@ public function __construct(CacheBackendInterface $cache_backend, LanguageManage
foreach ($module_handler->getModuleList() as $module => $filename) {
$directories[$module] = dirname($filename);
}
foreach ($this->getThemeList() as $theme) {
$directories[$theme->name] = drupal_get_path('theme', $theme->name);
foreach ($theme_handler->listInfo() as $theme) {
$directories[$theme->name] = dirname($theme->filename);
}
// Check for files named MODULE.config_translation.yml and
......@@ -80,23 +81,6 @@ public function __construct(CacheBackendInterface $cache_backend, LanguageManage
$this->setCacheBackend($cache_backend, $language_manager, 'config_translation_info_plugins');
}
/**
* Returns the list of themes on the site.
*
* @param bool $refresh
* Whether to refresh the cached theme list.
*
* @return array
* An associative array of the currently available themes. The keys are the
* themes' machine names and the values are objects. See list_themes() for
* documentation on those objects.
*
* @todo Remove this once https://drupal.org/node/2109287 is fixed in core.
*/
protected function getThemeList($refresh = FALSE) {
return list_themes($refresh);
}
/**
* {@inheritdoc}
*/
......
......@@ -5,7 +5,7 @@
* Contains \Drupal\config_translation\Tests\ConfigMapperManagerTest.
*/
namespace Drupal\config_translation\Tests {
namespace Drupal\config_translation\Tests;
use Drupal\config_translation\ConfigMapperManager;
use Drupal\Core\Language\Language;
......@@ -62,12 +62,17 @@ public function setUp() {
->method('getModuleList')
->with()
->will($this->returnValue(array()));
$theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
$theme_handler->expects($this->any())
->method('listInfo')
->will($this->returnValue(array()));
$this->configMapperManager = new TestConfigMapperManager(
$this->configMapperManager = new ConfigMapperManager(
$this->getMock('Drupal\Core\Cache\CacheBackendInterface'),
$language_manager,
$module_handler,
$this->typedConfigManager
$this->typedConfigManager,
$theme_handler
);
}
......@@ -187,27 +192,3 @@ protected function getNestedElement(array $elements) {
}
}
/**
* Subclass of the tested class to avoid global function calls.
*
* @todo Remove this once https://drupal.org/node/2109287 is fixed in core.
*/
class TestConfigMapperManager extends ConfigMapperManager {
/**
* {@inheritdoc}
*/
protected function getThemeList($refresh = FALSE) {
return array();
}
}
}
// @todo Remove this once https://drupal.org/node/2109287 is fixed in core.
namespace {
if (!function_exists('drupal_get_path')) {
function drupal_get_path() {}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment