You are here

public function SitemapBookTest::testBooks in Sitemap 8.2

Same name and namespace in other branches
  1. 8 src/Tests/SitemapBookTest.php \Drupal\sitemap\Tests\SitemapBookTest::testBooks()
  2. 2.0.x src/Tests/SitemapBookTest.php \Drupal\sitemap\Tests\SitemapBookTest::testBooks()

Tests books.

File

src/Tests/SitemapBookTest.php, line 57

Class

SitemapBookTest
Test the display of books based on sitemap settings.

Namespace

Drupal\sitemap\Tests

Code

public function testBooks() {

  // Assert that books are not included in the sitemap by default.
  $this
    ->drupalGet('/sitemap');
  $elements = $this
    ->cssSelect(".sitemap-plugin--book");
  $this
    ->assertEquals(count($elements), 0, 'Books are not included.');

  // Configure sitemap to show the test book.
  $bid = $this->book
    ->id();
  $nodes = $this->nodes;
  $edit = [
    'plugins[book:' . $bid . '][enabled]' => TRUE,
  ];
  $this
    ->saveSitemapForm($edit);

  // Assert that all book links are displayed by default.
  $this
    ->drupalGet('/sitemap');
  $this
    ->assertSession()
    ->linkExists($this->book
    ->getTitle());
  foreach ($nodes as $node) {
    $this
      ->assertSession()
      ->linkExists($node
      ->getTitle());
  }

  // Configure sitemap to not expand books.
  $edit = [
    'plugins[book:' . $bid . '][settings][show_expanded]' => FALSE,
  ];
  $this
    ->saveSitemapForm($edit);

  // Assert that the top-level book link is displayed, but that the others are
  // not.
  $this
    ->drupalGet('/sitemap');
  $this
    ->assertSession()
    ->linkExists($this->book
    ->getTitle());
  foreach ($nodes as $node) {
    $this
      ->assertSession()
      ->linkNotExists($node
      ->getTitle());
  }
}