b5025e8017789055388bd6f1c8c7c6e13cdd4e05
[yaffs-website] / web / core / modules / block / src / Tests / BlockSystemBrandingTest.php
1 <?php
2
3 namespace Drupal\block\Tests;
4
5 /**
6  * Tests branding block display.
7  *
8  * @group block
9  */
10 class BlockSystemBrandingTest extends BlockTestBase {
11
12   /**
13    * Modules to install.
14    *
15    * @var array
16    */
17   public static $modules = ['block', 'system'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24     // Set a site slogan.
25     $this->config('system.site')
26       ->set('slogan', 'Community plumbing')
27       ->save();
28     // Add the system branding block to the page.
29     $this->drupalPlaceBlock('system_branding_block', ['region' => 'header', 'id' => 'site-branding']);
30   }
31
32   /**
33    * Tests system branding block configuration.
34    */
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"]';
39
40     // Set default block settings.
41     $this->drupalGet('');
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');
50
51     // Be sure the slogan is XSS-filtered.
52     $this->config('system.site')
53       ->set('slogan', '<script>alert("Community carpentry");</script>')
54       ->save();
55     $this->drupalGet('');
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.');
58
59     // Turn just the logo off.
60     $this->config('block.block.site-branding')
61       ->set('settings.use_site_logo', 0)
62       ->save();
63     $this->drupalGet('');
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');
72
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)
77       ->save();
78     $this->drupalGet('');
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');
87
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)
92       ->save();
93     $this->drupalGet('');
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');
102
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)
107       ->save();
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');
117   }
118
119 }