public function SitemapBookTest::testBooks in Sitemap 8
Same name and namespace in other branches
- 8.2 src/Tests/SitemapBookTest.php \Drupal\sitemap\Tests\SitemapBookTest::testBooks()
- 2.0.x src/Tests/SitemapBookTest.php \Drupal\sitemap\Tests\SitemapBookTest::testBooks()
Tests books.
File
- src/
Tests/ SitemapBookTest.php, line 48
Class
- SitemapBookTest
- Test the display of books based on sitemap settings.
Namespace
Drupal\sitemap\TestsCode
public function testBooks() {
// Assert that books are not included in the sitemap by default.
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".sitemap-box h2:contains('Books')");
$this
->assertEqual(count($elements), 0, 'Books are not included.');
// Create new book.
$nodes = $this
->createBook();
$book = $this->book;
// Configure sitemap to show the test book.
$bid = $book
->id();
$edit = [
'show_books[' . $bid . ']' => $bid,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that all book links are displayed by default.
$this
->drupalGet('/sitemap');
$this
->assertLink($this->book
->getTitle());
foreach ($nodes as $node) {
$this
->assertLink($node
->getTitle());
}
// Configure sitemap to not expand books.
$edit = [
'books_expanded' => FALSE,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that the top-level book link is displayed, but that the others are
// not.
$this
->drupalGet('/sitemap');
$this
->assertLink($this->book
->getTitle());
foreach ($nodes as $node) {
$this
->assertNoLink($node
->getTitle());
}
}