CurrentThemeConditionTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Plugin/Condition/CurrentThemeConditionTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Plugin\Condition;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\KernelTests\KernelTestBase;
class CurrentThemeConditionTest extends KernelTestBase {
protected static $modules = [
'system',
'theme_test',
];
public function testCurrentTheme() {
\Drupal::service('theme_installer')
->install([
'test_theme',
]);
$manager = \Drupal::service('plugin.manager.condition');
$condition = $manager
->createInstance('current_theme');
$condition
->setConfiguration([
'theme' => 'test_theme',
]);
$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());
$this
->assertFalse($condition
->execute());
$this
->assertTrue($condition_negated
->execute());
$this
->config('system.theme')
->set('default', 'test_theme')
->save();
\Drupal::theme()
->resetActiveTheme();
$this
->assertTrue($condition
->execute());
$this
->assertFalse($condition_negated
->execute());
}
}