View source
<?php
namespace Drupal\Tests\block\Functional;
class BlockSystemBrandingTest extends BlockTestBase {
protected static $modules = [
'block',
'system',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->config('system.site')
->set('slogan', 'Community plumbing')
->save();
$this
->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
'id' => 'site-branding',
]);
}
public function testSystemBrandingSettings() {
$site_logo_xpath = '//div[@id="block-site-branding"]/a/img';
$site_name_xpath = '//div[@id="block-site-branding"]/a[text() = "Drupal"]';
$site_slogan_xpath = '//div[@id="block-site-branding"]/descendant::text()[last()]';
$this
->drupalGet('');
$site_logo_element = $this
->xpath($site_logo_xpath);
$site_name_element = $this
->xpath($site_name_xpath);
$this
->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
$this
->assertNotEmpty($site_name_element, 'The branding block site name was found.');
$this
->assertSession()
->elementTextContains('xpath', $site_slogan_xpath, 'Community plumbing');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
$theme_path = \Drupal::service('extension.list.theme')
->getPath($this->defaultTheme);
$this
->assertSession()
->elementAttributeContains('xpath', $site_logo_xpath, 'src', $theme_path . '/logo.svg');
$this
->config('system.site')
->set('slogan', '<script>alert("Community carpentry");</script>')
->save();
$this
->drupalGet('');
$this
->assertSession()
->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
$this
->assertSession()
->responseNotContains('<script>alert("Community carpentry");</script>');
$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);
$this
->assertEmpty($site_logo_element, 'The branding block logo was disabled.');
$this
->assertNotEmpty($site_name_element, 'The branding block site name was found.');
$this
->assertSession()
->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
$this
->assertSession()
->responseNotContains('<script>alert("Community carpentry");</script>');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', '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);
$this
->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
$this
->assertEmpty($site_name_element, 'The branding block site name was disabled.');
$this
->assertSession()
->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
$this
->assertSession()
->responseNotContains('<script>alert("Community carpentry");</script>');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', '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);
$this
->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
$this
->assertNotEmpty($site_name_element, 'The branding block site name was found.');
$this
->assertSession()
->elementTextNotContains('xpath', $site_slogan_xpath, 'Community carpentry');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', '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);
$this
->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
$this
->assertEmpty($site_name_element, 'The branding block site name was disabled.');
$this
->assertSession()
->elementTextNotContains('xpath', $site_slogan_xpath, 'Community carpentry');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
}
}