CurrentThemeConditionTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Drupal\KernelTests\Core\Plugin\Condition;
  3. use Drupal\Component\Utility\SafeMarkup;
  4. use Drupal\KernelTests\KernelTestBase;
  5. /**
  6. * Tests the CurrentThemeCondition plugin.
  7. *
  8. * @group Condition
  9. */
  10. class CurrentThemeConditionTest extends KernelTestBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public static $modules = ['system', 'theme_test'];
  15. /**
  16. * Tests the current theme condition.
  17. */
  18. public function testCurrentTheme() {
  19. \Drupal::service('theme_handler')->install(['test_theme']);
  20. $manager = \Drupal::service('plugin.manager.condition');
  21. /** @var $condition \Drupal\Core\Condition\ConditionInterface */
  22. $condition = $manager->createInstance('current_theme');
  23. $condition->setConfiguration(['theme' => 'test_theme']);
  24. /** @var $condition_negated \Drupal\Core\Condition\ConditionInterface */
  25. $condition_negated = $manager->createInstance('current_theme');
  26. $condition_negated->setConfiguration(['theme' => 'test_theme', 'negate' => TRUE]);
  27. $this->assertEqual($condition->summary(), SafeMarkup::format('The current theme is @theme', ['@theme' => 'test_theme']));
  28. $this->assertEqual($condition_negated->summary(), SafeMarkup::format('The current theme is not @theme', ['@theme' => 'test_theme']));
  29. // The expected theme has not been set up yet.
  30. $this->assertFalse($condition->execute());
  31. $this->assertTrue($condition_negated->execute());
  32. // Set the expected theme to be used.
  33. $this->config('system.theme')->set('default', 'test_theme')->save();
  34. \Drupal::theme()->resetActiveTheme();
  35. $this->assertTrue($condition->execute());
  36. $this->assertFalse($condition_negated->execute());
  37. }
  38. }