Newer
Older
<?php
/**
* @file
* Contains \Drupal\system\Tests\Condition\CurrentThemeConditionTest.
*/
namespace Drupal\system\Tests\Condition;
use Drupal\Component\Utility\String;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the CurrentThemeCondition plugin.
*
* @group Condition
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
*/
class CurrentThemeConditionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('system', 'theme_test');
/**
* Tests the current theme condition.
*/
public function testCurrentTheme() {
\Drupal::service('theme_handler')->enable(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(), String::format('The current theme is @theme', array('@theme' => 'test_theme')));
$this->assertEqual($condition_negated->summary(), String::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.
\Drupal::config('system.theme')->set('default', 'test_theme')->save();
$this->assertTrue($condition->execute());
$this->assertFalse($condition_negated->execute());
}
}