View source
<?php
namespace Drupal\block\Tests;
class BlockSystemBrandingTest extends BlockTestBase {
public static $modules = array(
'block',
'system',
);
protected function setUp() {
parent::setUp();
$this
->config('system.site')
->set('slogan', 'Community plumbing')
->save();
$this
->drupalPlaceBlock('system_branding_block', array(
'region' => 'header',
'id' => 'site-branding',
));
}
public function testSystemBrandingSettings() {
$site_logo_xpath = '//div[@id="block-site-branding"]//a[@class="site-logo"]';
$site_name_xpath = '//div[@id="block-site-branding"]//div[@class="site-name"]';
$site_slogan_xpath = '//div[@id="block-site-branding"]//div[@class="site-slogan"]';
$this
->drupalGet('');
$site_logo_element = $this
->xpath($site_logo_xpath);
$site_name_element = $this
->xpath($site_name_xpath);
$site_slogan_element = $this
->xpath($site_slogan_xpath);
$this
->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
$this
->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
$this
->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
$this
->assertCacheTag('config:system.site');
$this
->config('system.site')
->set('slogan', '<script>alert("Community carpentry");</script>')
->save();
$this
->drupalGet('');
$site_slogan_element = $this
->xpath($site_slogan_xpath);
$this
->assertEqual($site_slogan_element[0], 'alert("Community carpentry");', 'The site slogan was XSS-filtered.');
$this
->config('block.block.site-branding')
->set('settings.use_site_logo', 0)
->save();
$this
->drupalGet('');
$site_logo_element = $this
->xpath($site_logo_xpath);
$site_name_element = $this
->xpath($site_name_xpath);
$site_slogan_element = $this
->xpath($site_slogan_xpath);
$this
->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.');
$this
->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
$this
->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
$this
->assertCacheTag('config:system.site');
$this
->config('block.block.site-branding')
->set('settings.use_site_logo', 1)
->set('settings.use_site_name', 0)
->save();
$this
->drupalGet('');
$site_logo_element = $this
->xpath($site_logo_xpath);
$site_name_element = $this
->xpath($site_name_xpath);
$site_slogan_element = $this
->xpath($site_slogan_xpath);
$this
->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
$this
->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
$this
->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
$this
->assertCacheTag('config:system.site');
$this
->config('block.block.site-branding')
->set('settings.use_site_name', 1)
->set('settings.use_site_slogan', 0)
->save();
$this
->drupalGet('');
$site_logo_element = $this
->xpath($site_logo_xpath);
$site_name_element = $this
->xpath($site_name_xpath);
$site_slogan_element = $this
->xpath($site_slogan_xpath);
$this
->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
$this
->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
$this
->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
$this
->assertCacheTag('config:system.site');
$this
->config('block.block.site-branding')
->set('settings.use_site_name', 0)
->set('settings.use_site_slogan', 0)
->save();
$this
->drupalGet('');
$site_logo_element = $this
->xpath($site_logo_xpath);
$site_name_element = $this
->xpath($site_name_xpath);
$site_slogan_element = $this
->xpath($site_slogan_xpath);
$this
->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
$this
->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
$this
->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
$this
->assertCacheTag('config:system.site');
}
}