7a69d2eb04a13d6cbca910d1b7c4ec9abd767366
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Plugin / Condition / CurrentThemeConditionTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Plugin\Condition;
4
5 use Drupal\Component\Utility\SafeMarkup;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests the CurrentThemeCondition plugin.
10  *
11  * @group Condition
12  */
13 class CurrentThemeConditionTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['system', 'theme_test'];
19
20   /**
21    * Tests the current theme condition.
22    */
23   public function testCurrentTheme() {
24     \Drupal::service('theme_handler')->install(['test_theme']);
25
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]);
33
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']));
36
37     // The expected theme has not been set up yet.
38     $this->assertFalse($condition->execute());
39     $this->assertTrue($condition_negated->execute());
40
41     // Set the expected theme to be used.
42     $this->config('system.theme')->set('default', 'test_theme')->save();
43     \Drupal::theme()->resetActiveTheme();
44
45     $this->assertTrue($condition->execute());
46     $this->assertFalse($condition_negated->execute());
47   }
48
49 }