BlockSystemBrandingTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace Drupal\Tests\block\Functional;
  3. /**
  4. * Tests branding block display.
  5. *
  6. * @group block
  7. */
  8. class BlockSystemBrandingTest extends BlockTestBase {
  9. /**
  10. * Modules to install.
  11. *
  12. * @var array
  13. */
  14. public static $modules = ['block', 'system'];
  15. /**
  16. * {@inheritdoc}
  17. */
  18. protected function setUp() {
  19. parent::setUp();
  20. // Set a site slogan.
  21. $this->config('system.site')
  22. ->set('slogan', 'Community plumbing')
  23. ->save();
  24. // Add the system branding block to the page.
  25. $this->drupalPlaceBlock('system_branding_block', ['region' => 'header', 'id' => 'site-branding']);
  26. }
  27. /**
  28. * Tests system branding block configuration.
  29. */
  30. public function testSystemBrandingSettings() {
  31. $site_logo_xpath = '//div[@id="block-site-branding"]//a[@class="site-logo"]';
  32. $site_name_xpath = '//div[@id="block-site-branding"]//div[@class="site-name"]';
  33. $site_slogan_xpath = '//div[@id="block-site-branding"]//div[@class="site-slogan"]';
  34. // Set default block settings.
  35. $this->drupalGet('');
  36. $site_logo_element = $this->xpath($site_logo_xpath);
  37. $site_name_element = $this->xpath($site_name_xpath);
  38. $site_slogan_element = $this->xpath($site_slogan_xpath);
  39. // Test that all branding elements are displayed.
  40. $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
  41. $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
  42. $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
  43. $this->assertCacheTag('config:system.site');
  44. // Be sure the slogan is XSS-filtered.
  45. $this->config('system.site')
  46. ->set('slogan', '<script>alert("Community carpentry");</script>')
  47. ->save();
  48. $this->drupalGet('');
  49. $site_slogan_element = $this->xpath($site_slogan_xpath);
  50. $this->assertEqual($site_slogan_element[0]->getText(), 'alert("Community carpentry");', 'The site slogan was XSS-filtered.');
  51. // Turn just the logo off.
  52. $this->config('block.block.site-branding')
  53. ->set('settings.use_site_logo', 0)
  54. ->save();
  55. $this->drupalGet('');
  56. $site_logo_element = $this->xpath($site_logo_xpath);
  57. $site_name_element = $this->xpath($site_name_xpath);
  58. $site_slogan_element = $this->xpath($site_slogan_xpath);
  59. // Re-test all branding elements.
  60. $this->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.');
  61. $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
  62. $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
  63. $this->assertCacheTag('config:system.site');
  64. // Turn just the site name off.
  65. $this->config('block.block.site-branding')
  66. ->set('settings.use_site_logo', 1)
  67. ->set('settings.use_site_name', 0)
  68. ->save();
  69. $this->drupalGet('');
  70. $site_logo_element = $this->xpath($site_logo_xpath);
  71. $site_name_element = $this->xpath($site_name_xpath);
  72. $site_slogan_element = $this->xpath($site_slogan_xpath);
  73. // Re-test all branding elements.
  74. $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
  75. $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
  76. $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
  77. $this->assertCacheTag('config:system.site');
  78. // Turn just the site slogan off.
  79. $this->config('block.block.site-branding')
  80. ->set('settings.use_site_name', 1)
  81. ->set('settings.use_site_slogan', 0)
  82. ->save();
  83. $this->drupalGet('');
  84. $site_logo_element = $this->xpath($site_logo_xpath);
  85. $site_name_element = $this->xpath($site_name_xpath);
  86. $site_slogan_element = $this->xpath($site_slogan_xpath);
  87. // Re-test all branding elements.
  88. $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
  89. $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
  90. $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
  91. $this->assertCacheTag('config:system.site');
  92. // Turn the site name and the site slogan off.
  93. $this->config('block.block.site-branding')
  94. ->set('settings.use_site_name', 0)
  95. ->set('settings.use_site_slogan', 0)
  96. ->save();
  97. $this->drupalGet('');
  98. $site_logo_element = $this->xpath($site_logo_xpath);
  99. $site_name_element = $this->xpath($site_name_xpath);
  100. $site_slogan_element = $this->xpath($site_slogan_xpath);
  101. // Re-test all branding elements.
  102. $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
  103. $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
  104. $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
  105. $this->assertCacheTag('config:system.site');
  106. }
  107. }