View source
<?php
namespace Drupal\site_map\Tests;
class SiteMapContentTest extends SiteMapTestBase {
public function testPageTitle() {
$this
->drupalGet('/sitemap');
$this
->assertTitle('Site map | Drupal', 'The title on the site map page is "Site map | Drupal".');
$new_title = $this
->randomMachineName();
$edit = array(
'page_title' => $new_title,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$this
->assertTitle("{$new_title} | Drupal", 'The title on the site map page is "' . "{$new_title} | Drupal" . '".');
}
public function testSiteMapMessage() {
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect('.site-map-message');
$this
->assertEqual(count($elements), 0, 'Site map message is not included.');
$new_message = $this
->randomMachineName(16);
$edit = array(
'message[value]' => $new_message,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".site-map-message:contains('" . $new_message . "')");
$this
->assertEqual(count($elements), 1, 'Site map message is included.');
}
public function testFrontPage() {
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".site-map-box h2:contains('" . t('Front page') . "')");
$this
->assertEqual(count($elements), 1, 'Front page is included.');
$edit = array(
'show_front' => FALSE,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".site-map-box h2:contains('" . t('Front page') . "')");
$this
->assertEqual(count($elements), 0, 'Front page is not included.');
}
public function testTitles() {
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect('.site-map-box h2');
$this
->assertTrue(count($elements) > 0, 'Titles are included.');
$edit = array(
'show_titles' => FALSE,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect('.site-map-box h2');
$this
->assertEqual(count($elements), 0, 'Section titles are not included.');
}
public function testMenus() {
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".site-map-box h2:contains('" . t('Main navigation') . "')");
$this
->assertEqual(count($elements), 0, 'Main menu is not included.');
$edit = array(
'show_menus[main]' => 'main',
'show_menus_hidden' => FALSE,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$node_1_title = $this
->randomString();
$edit = array(
'title[0][value]' => $node_1_title,
'menu[enabled]' => TRUE,
'menu[title]' => $node_1_title,
'menu[menu_parent]' => 'main:',
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$node_2_title = $this
->randomString();
$edit = array(
'title[0][value]' => $node_2_title,
'menu[enabled]' => TRUE,
'menu[title]' => $node_2_title,
'menu[menu_parent]' => 'main:',
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$menu_links = entity_load_multiple_by_properties('menu_link_content', array(
'title' => $node_2_title,
));
$menu_link = reset($menu_links);
$mlid = $menu_link
->id();
$edit = array(
'enabled[value]' => FALSE,
);
$this
->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".site-map-box h2:contains('" . t('Main navigation') . "')");
$this
->assertEqual(count($elements), 1, 'Main menu is included.');
$this
->assertLink($node_1_title);
$this
->assertNoLink($node_2_title);
$edit = array(
'show_menus_hidden' => TRUE,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$this
->assertLink($node_1_title);
$this
->assertLink($node_2_title);
}
public function testCategories() {
$tags = $this
->getTags();
$vocabulary = $this
->createVocabulary();
$field_tags_name = $this
->createTaxonomyTermReferenceField($vocabulary);
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".site-map-box h2:contains('" . $vocabulary
->label() . "')");
$this
->assertEqual(count($elements), 0, 'Tags category is not included.');
foreach ($tags as $tag) {
$this
->assertNoLink($tag);
}
$vid = $vocabulary
->id();
$edit = array(
"show_vocabularies[{$vid}]" => $vid,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$title = $this
->randomString();
$edit = array(
'title[0][value]' => $title,
'menu[enabled]' => TRUE,
'menu[title]' => $title,
$field_tags_name => implode(',', $tags),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->drupalGet('sitemap');
$elements = $this
->cssSelect(".site-map-box h2:contains('" . $vocabulary
->label() . "')");
$this
->assertEqual(count($elements), 1, 'Tags category is included.');
foreach ($tags as $tag) {
$this
->assertLink($tag);
}
}
}