You are here

public function CurrentThemeConditionTest::testCurrentTheme in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php \Drupal\system\Tests\Condition\CurrentThemeConditionTest::testCurrentTheme()

Tests the current theme condition.

File

core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php, line 36
Contains \Drupal\system\Tests\Condition\CurrentThemeConditionTest.

Class

CurrentThemeConditionTest
Tests the CurrentThemeCondition plugin.

Namespace

Drupal\system\Tests\Condition

Code

public function testCurrentTheme() {
  \Drupal::service('theme_handler')
    ->install(array(
    'test_theme',
  ));
  $manager = \Drupal::service('plugin.manager.condition');

  /** @var $condition \Drupal\Core\Condition\ConditionInterface */
  $condition = $manager
    ->createInstance('current_theme');
  $condition
    ->setConfiguration(array(
    'theme' => 'test_theme',
  ));

  /** @var $condition_negated \Drupal\Core\Condition\ConditionInterface */
  $condition_negated = $manager
    ->createInstance('current_theme');
  $condition_negated
    ->setConfiguration(array(
    'theme' => 'test_theme',
    'negate' => TRUE,
  ));
  $this
    ->assertEqual($condition
    ->summary(), SafeMarkup::format('The current theme is @theme', array(
    '@theme' => 'test_theme',
  )));
  $this
    ->assertEqual($condition_negated
    ->summary(), SafeMarkup::format('The current theme is not @theme', array(
    '@theme' => 'test_theme',
  )));

  // The expected theme has not been set up yet.
  $this
    ->assertFalse($condition
    ->execute());
  $this
    ->assertTrue($condition_negated
    ->execute());

  // Set the expected theme to be used.
  $this
    ->config('system.theme')
    ->set('default', 'test_theme')
    ->save();
  \Drupal::theme()
    ->resetActiveTheme();
  $this
    ->assertTrue($condition
    ->execute());
  $this
    ->assertFalse($condition_negated
    ->execute());
}