class CurrentThemeConditionTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Plugin/Condition/CurrentThemeConditionTest.php \Drupal\KernelTests\Core\Plugin\Condition\CurrentThemeConditionTest
- 10 core/tests/Drupal/KernelTests/Core/Plugin/Condition/CurrentThemeConditionTest.php \Drupal\KernelTests\Core\Plugin\Condition\CurrentThemeConditionTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/Condition/CurrentThemeConditionTest.php \Drupal\KernelTests\Core\Plugin\Condition\CurrentThemeConditionTest
Tests the CurrentThemeCondition plugin.
@group Condition
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Plugin\Condition\CurrentThemeConditionTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of CurrentThemeConditionTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Plugin/ Condition/ CurrentThemeConditionTest.php, line 13
Namespace
Drupal\KernelTests\Core\Plugin\ConditionView source
class CurrentThemeConditionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'theme_test',
];
/**
* Tests the current theme condition.
*/
public function testCurrentTheme() {
\Drupal::service('theme_installer')->install([
'test_theme',
]);
$manager = \Drupal::service('plugin.manager.condition');
/** @var \Drupal\Core\Condition\ConditionInterface $condition */
$condition = $manager->createInstance('current_theme');
$condition->setConfiguration([
'theme' => 'test_theme',
]);
/** @var \Drupal\Core\Condition\ConditionInterface $condition_negated */
$condition_negated = $manager->createInstance('current_theme');
$condition_negated->setConfiguration([
'theme' => 'test_theme',
'negate' => TRUE,
]);
$this->assertEquals(new FormattableMarkup('The current theme is @theme', [
'@theme' => 'test_theme',
]), $condition->summary());
$this->assertEquals(new FormattableMarkup('The current theme is not @theme', [
'@theme' => 'test_theme',
]), $condition_negated->summary());
// 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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.