DomainCSSTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Drupal\Tests\domain\Functional;
  3. use Drupal\Component\Utility\Html;
  4. /**
  5. * Tests the domain CSS configuration.
  6. *
  7. * @group domain
  8. */
  9. class DomainCSSTest extends DomainTestBase {
  10. /**
  11. * Modules to enable.
  12. *
  13. * @var array
  14. */
  15. public static $modules = ['domain'];
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected function setUp() {
  20. parent::setUp();
  21. \Drupal::service('theme_handler')->install(['bartik']);
  22. }
  23. /**
  24. * Tests the handling of an inbound request.
  25. */
  26. public function testDomainNegotiator() {
  27. // No domains should exist.
  28. $this->domainTableIsEmpty();
  29. // Create four new domains programmatically.
  30. $this->domainCreateTestDomains(4);
  31. // The test runner doesn't use a theme that contains the preprocess hook,
  32. // so set to use Bartik.
  33. $config = $this->config('system.theme');
  34. $config->set('default', 'bartik')->save();
  35. // Test the response of the default home page.
  36. foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
  37. $this->drupalGet($domain->getPath());
  38. $text = '<body class="' . Html::getClass($domain->id() . '-class');
  39. $this->assertNoRaw($text, 'No custom CSS present.');
  40. }
  41. // Set the css classes.
  42. $config = $this->config('domain.settings');
  43. $config->set('css_classes', '[domain:machine-name]-class')->save();
  44. // Test the response of the default home page.
  45. foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
  46. // The render cache trips up this test. In production, it may be
  47. // necessary to add the url.site cache context. See README.md.
  48. drupal_flush_all_caches();
  49. $this->drupalGet($domain->getPath());
  50. $text = '<body class="' . Html::getClass($domain->id() . '-class');
  51. $this->assertRaw($text, 'Custom CSS present.' . $text);
  52. }
  53. // Set the css classes.
  54. $config = $this->config('domain.settings');
  55. $config->set('css_classes', '[domain:machine-name]-class [domain:name]-class')->save();
  56. // Test the response of the default home page.
  57. foreach (\Drupal::entityTypeManager()->getStorage('domain')->loadMultiple() as $domain) {
  58. // The render cache trips up this test. In production, it may be
  59. // necessary to add the url.site cache context. See README.md.
  60. drupal_flush_all_caches();
  61. $this->drupalGet($domain->getPath());
  62. $text = '<body class="' . Html::getClass($domain->id() . '-class') . ' ' . Html::getClass($domain->label() . '-class');
  63. $this->assertRaw($text, 'Custom CSS present.' . $text);
  64. }
  65. }
  66. }