You are here

public function SitemapTestTrait::titleTest in Sitemap 8.2

Same name and namespace in other branches
  1. 2.0.x src/Tests/SitemapTestTrait.php \Drupal\sitemap\Tests\SitemapTestTrait::titleTest()

Common test for the plugin title field.

Parameters

string $title:

string $plugin_id:

string $derivative_id:

boolean $clear_cache: Some elements do not yet have proper cache tags configured (looking at you, vocabulary), so cache must be flushed when plugin configuration changes.

Throws

\Exception

4 calls to SitemapTestTrait::titleTest()
SitemapBookTest::testBooksCustomTitle in src/Tests/SitemapBookTest.php
Tests a custom title setting for books.
SitemapFrontpageTest::testTitle in src/Tests/SitemapFrontpageTest.php
Tests the custom title setting.
SitemapMenuTest::testMenuTitle in src/Tests/SitemapMenuTest.php
Tests the menu title.
SitemapTaxonomyTest::testVocabularyTitle in src/Tests/SitemapTaxonomyTest.php
Tests vocabulary title.

File

src/Tests/SitemapTestTrait.php, line 20

Class

SitemapTestTrait

Namespace

Drupal\sitemap\Tests

Code

public function titleTest($title, $plugin_id, $derivative_id = '', $clear_cache = FALSE) {
  $field = $derivative_id ? $plugin_id . ':' . $derivative_id : $plugin_id;

  // Assert that title is found.

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $this
    ->drupalGet('/sitemap');
  $assert
    ->elementExists('css', ".sitemap-plugin--{$plugin_id}");
  $assert
    ->elementTextContains('css', ".sitemap-plugin--{$plugin_id} h2", $title);

  // Remove the title.
  $this
    ->saveSitemapForm([
    "plugins[{$field}][settings][title]" => '',
  ]);
  if ($clear_cache) {
    drupal_flush_all_caches();
  }

  // Check that a title does not appear on sitemap.
  $this
    ->drupalGet('/sitemap');
  $assert
    ->elementNotExists('css', ".sitemap-plugin--{$plugin_id} h2");

  // Set a custom title for the main menu display.
  $custom_title = $this
    ->randomString();
  $this
    ->saveSitemapForm([
    "plugins[{$field}][settings][title]" => $custom_title,
  ]);
  if ($clear_cache) {
    drupal_flush_all_caches();
  }

  // Check that the custom title appears on the sitemap.
  $this
    ->drupalGet('/sitemap');
  $assert
    ->elementExists('css', ".sitemap-plugin--{$plugin_id}");
  $assert
    ->elementTextContains('css', ".sitemap-plugin--{$plugin_id} h2", $custom_title);
}