View source
<?php
namespace Drupal\sitemap\Tests;
use Drupal\filter\Entity\FilterFormat;
class SitemapContentTest extends SitemapTestBase {
public static $modules = [
'sitemap',
'block',
'filter',
];
public $userEditor;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
$restricted_html_format = FilterFormat::create([
'format' => 'restricted_html',
'name' => 'Restricted HTML',
'filters' => [
'filter_html' => [
'status' => TRUE,
'weight' => -10,
'settings' => [
'allowed_html' => '<p> <br /> <strong> <a> <em> <h4>',
],
],
'filter_autop' => [
'status' => TRUE,
'weight' => 0,
],
'filter_url' => [
'status' => TRUE,
'weight' => 0,
],
'filter_htmlcorrector' => [
'status' => TRUE,
'weight' => 10,
],
],
]);
$restricted_html_format
->save();
$this->userEditor = $this
->drupalCreateUser([
'administer sitemap',
'access sitemap',
$restricted_html_format
->getPermissionName(),
]);
$this
->drupalLogin($this->userEditor);
}
public function testPageTitle() {
$this
->drupalGet('/sitemap');
$this
->assertSession()
->titleEquals('Sitemap | Drupal');
$new_title = $this
->randomMachineName();
$edit = [
'page_title' => $new_title,
];
$this
->saveSitemapForm($edit);
drupal_flush_all_caches();
$this
->drupalGet('/sitemap');
$this
->assertSession()
->titleEquals("{$new_title} | Drupal");
}
public function testSitemapMessage() {
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect('.sitemap-message');
$this
->assertEquals(count($elements), 0, 'Sitemap message is not included.');
$new_message = $this
->randomMachineName(16);
$edit = [
'message[value]' => $new_message,
];
$this
->saveSitemapForm($edit);
drupal_flush_all_caches();
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".sitemap-message:contains('" . $new_message . "')");
$this
->assertEquals(count($elements), 1, 'Sitemap message is included.');
}
}