3 namespace Drupal\KernelTests\Core\Plugin\Condition;
5 use Drupal\Component\Utility\SafeMarkup;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests the CurrentThemeCondition plugin.
13 class CurrentThemeConditionTest extends KernelTestBase {
18 public static $modules = ['system', 'theme_test'];
21 * Tests the current theme condition.
23 public function testCurrentTheme() {
24 \Drupal::service('theme_handler')->install(['test_theme']);
26 $manager = \Drupal::service('plugin.manager.condition');
27 /** @var $condition \Drupal\Core\Condition\ConditionInterface */
28 $condition = $manager->createInstance('current_theme');
29 $condition->setConfiguration(['theme' => 'test_theme']);
30 /** @var $condition_negated \Drupal\Core\Condition\ConditionInterface */
31 $condition_negated = $manager->createInstance('current_theme');
32 $condition_negated->setConfiguration(['theme' => 'test_theme', 'negate' => TRUE]);
34 $this->assertEqual($condition->summary(), SafeMarkup::format('The current theme is @theme', ['@theme' => 'test_theme']));
35 $this->assertEqual($condition_negated->summary(), SafeMarkup::format('The current theme is not @theme', ['@theme' => 'test_theme']));
37 // The expected theme has not been set up yet.
38 $this->assertFalse($condition->execute());
39 $this->assertTrue($condition_negated->execute());
41 // Set the expected theme to be used.
42 $this->config('system.theme')->set('default', 'test_theme')->save();
43 \Drupal::theme()->resetActiveTheme();
45 $this->assertTrue($condition->execute());
46 $this->assertFalse($condition_negated->execute());