3 namespace Drupal\block\Tests;
6 * Tests branding block display.
10 class BlockSystemBrandingTest extends BlockTestBase {
17 public static $modules = ['block', 'system'];
22 protected function setUp() {
25 $this->config('system.site')
26 ->set('slogan', 'Community plumbing')
28 // Add the system branding block to the page.
29 $this->drupalPlaceBlock('system_branding_block', ['region' => 'header', 'id' => 'site-branding']);
33 * Tests system branding block configuration.
35 public function testSystemBrandingSettings() {
36 $site_logo_xpath = '//div[@id="block-site-branding"]//a[@class="site-logo"]';
37 $site_name_xpath = '//div[@id="block-site-branding"]//div[@class="site-name"]';
38 $site_slogan_xpath = '//div[@id="block-site-branding"]//div[@class="site-slogan"]';
40 // Set default block settings.
42 $site_logo_element = $this->xpath($site_logo_xpath);
43 $site_name_element = $this->xpath($site_name_xpath);
44 $site_slogan_element = $this->xpath($site_slogan_xpath);
45 // Test that all branding elements are displayed.
46 $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
47 $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
48 $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
49 $this->assertCacheTag('config:system.site');
51 // Be sure the slogan is XSS-filtered.
52 $this->config('system.site')
53 ->set('slogan', '<script>alert("Community carpentry");</script>')
56 $site_slogan_element = $this->xpath($site_slogan_xpath);
57 $this->assertEqual($site_slogan_element[0], 'alert("Community carpentry");', 'The site slogan was XSS-filtered.');
59 // Turn just the logo off.
60 $this->config('block.block.site-branding')
61 ->set('settings.use_site_logo', 0)
64 $site_logo_element = $this->xpath($site_logo_xpath);
65 $site_name_element = $this->xpath($site_name_xpath);
66 $site_slogan_element = $this->xpath($site_slogan_xpath);
67 // Re-test all branding elements.
68 $this->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.');
69 $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
70 $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
71 $this->assertCacheTag('config:system.site');
73 // Turn just the site name off.
74 $this->config('block.block.site-branding')
75 ->set('settings.use_site_logo', 1)
76 ->set('settings.use_site_name', 0)
79 $site_logo_element = $this->xpath($site_logo_xpath);
80 $site_name_element = $this->xpath($site_name_xpath);
81 $site_slogan_element = $this->xpath($site_slogan_xpath);
82 // Re-test all branding elements.
83 $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
84 $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
85 $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
86 $this->assertCacheTag('config:system.site');
88 // Turn just the site slogan off.
89 $this->config('block.block.site-branding')
90 ->set('settings.use_site_name', 1)
91 ->set('settings.use_site_slogan', 0)
94 $site_logo_element = $this->xpath($site_logo_xpath);
95 $site_name_element = $this->xpath($site_name_xpath);
96 $site_slogan_element = $this->xpath($site_slogan_xpath);
97 // Re-test all branding elements.
98 $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
99 $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
100 $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
101 $this->assertCacheTag('config:system.site');
103 // Turn the site name and the site slogan off.
104 $this->config('block.block.site-branding')
105 ->set('settings.use_site_name', 0)
106 ->set('settings.use_site_slogan', 0)
108 $this->drupalGet('');
109 $site_logo_element = $this->xpath($site_logo_xpath);
110 $site_name_element = $this->xpath($site_name_xpath);
111 $site_slogan_element = $this->xpath($site_slogan_xpath);
112 // Re-test all branding elements.
113 $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
114 $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
115 $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
116 $this->assertCacheTag('config:system.site');