You are here

class RegistryTest in Zircon Profile 8

Same name in this branch
  1. 8 core/tests/Drupal/Tests/Core/Theme/RegistryTest.php \Drupal\Tests\Core\Theme\RegistryTest
  2. 8 core/modules/system/src/Tests/Theme/RegistryTest.php \Drupal\system\Tests\Theme\RegistryTest
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Theme/RegistryTest.php \Drupal\Tests\Core\Theme\RegistryTest

@coversDefaultClass \Drupal\Core\Theme\Registry @group Theme

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of RegistryTest

File

core/tests/Drupal/Tests/Core/Theme/RegistryTest.php, line 18
Contains \Drupal\Tests\Core\Theme\RegistryTest.

Namespace

Drupal\Tests\Core\Theme
View source
class RegistryTest extends UnitTestCase {

  /**
   * The tested theme registry.
   *
   * @var \Drupal\Tests\Core\Theme\TestRegistry
   */
  protected $registry;

  /**
   * The mocked cache backend.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $cache;

  /**
   * The mocked lock backend.
   *
   * @var \Drupal\Core\Lock\LockBackendInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $lock;

  /**
   * The mocked module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $moduleHandler;

  /**
   * The mocked theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $themeHandler;

  /**
   * The mocked theme initialization.
   *
   * @var \Drupal\Core\Theme\ThemeInitializationInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $themeInitialization;

  /**
   * The theme manager.
   *
   * @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $themeManager;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->cache = $this
      ->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    $this->lock = $this
      ->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
    $this->moduleHandler = $this
      ->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $this->themeHandler = $this
      ->getMock('Drupal\\Core\\Extension\\ThemeHandlerInterface');
    $this->themeInitialization = $this
      ->getMock('Drupal\\Core\\Theme\\ThemeInitializationInterface');
    $this->themeManager = $this
      ->getMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
    $this
      ->setupTheme();
  }

  /**
   * Tests getting the theme registry defined by a module.
   */
  public function testGetRegistryForModule() {
    $this
      ->setupTheme('test_theme');
    $this->registry
      ->setTheme(new ActiveTheme([
      'name' => 'test_theme',
      'path' => 'core/modules/system/tests/themes/test_theme/test_theme.info.yml',
      'engine' => 'twig',
      'owner' => 'twig',
      'stylesheets_remove' => [],
      'libraries_override' => [],
      'libraries_extend' => [],
      'libraries' => [],
      'extension' => '.twig',
      'base_themes' => [],
    ]));

    // Include the module so that hook_theme can be called.
    include_once $this->root . '/core/modules/system/tests/modules/theme_test/theme_test.module';
    $this->moduleHandler
      ->expects($this
      ->once())
      ->method('getImplementations')
      ->with('theme')
      ->will($this
      ->returnValue(array(
      'theme_test',
    )));
    $this->moduleHandler
      ->expects($this
      ->atLeastOnce())
      ->method('getModuleList')
      ->willReturn([]);
    $registry = $this->registry
      ->get();

    // Ensure that the registry entries from the module are found.
    $this
      ->assertArrayHasKey('theme_test', $registry);
    $this
      ->assertArrayHasKey('theme_test_template_test', $registry);
    $this
      ->assertArrayHasKey('theme_test_template_test_2', $registry);
    $this
      ->assertArrayHasKey('theme_test_suggestion_provided', $registry);
    $this
      ->assertArrayHasKey('theme_test_specific_suggestions', $registry);
    $this
      ->assertArrayHasKey('theme_test_suggestions', $registry);
    $this
      ->assertArrayHasKey('theme_test_function_suggestions', $registry);
    $this
      ->assertArrayHasKey('theme_test_foo', $registry);
    $this
      ->assertArrayHasKey('theme_test_render_element', $registry);
    $this
      ->assertArrayHasKey('theme_test_render_element_children', $registry);
    $this
      ->assertArrayHasKey('theme_test_function_template_override', $registry);
    $this
      ->assertArrayNotHasKey('test_theme_not_existing_function', $registry);
    $info = $registry['theme_test_function_suggestions'];
    $this
      ->assertEquals('module', $info['type']);
    $this
      ->assertEquals('core/modules/system/tests/modules/theme_test', $info['theme path']);
    $this
      ->assertEquals('theme_theme_test_function_suggestions', $info['function']);
    $this
      ->assertEquals(array(), $info['variables']);
  }
  protected function setupTheme($theme_name = NULL) {
    $this->registry = new TestRegistry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization, $theme_name);
    $this->registry
      ->setThemeManager($this->themeManager);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RegistryTest::$cache protected property The mocked cache backend.
RegistryTest::$lock protected property The mocked lock backend.
RegistryTest::$moduleHandler protected property The mocked module handler.
RegistryTest::$registry protected property The tested theme registry.
RegistryTest::$themeHandler protected property The mocked theme handler.
RegistryTest::$themeInitialization protected property The mocked theme initialization.
RegistryTest::$themeManager protected property The theme manager.
RegistryTest::setUp protected function Overrides UnitTestCase::setUp
RegistryTest::setupTheme protected function
RegistryTest::testGetRegistryForModule public function Tests getting the theme registry defined by a module.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.