Skip to content
Snippets Groups Projects
Commit e2a6e4af authored by Adam G-H's avatar Adam G-H
Browse files

Make the test a little more direct

parent 375c3dec
No related branches found
No related tags found
No related merge requests found
Checking pipeline status
......@@ -54,52 +54,28 @@ class ComponentValidationTest extends BrowserTestBase {
}
/**
* Checks the sitemap is accessible.
* Checks that the sitemap is accessible and contains the expected links.
*/
private function checkSitemap(): void {
$this->drupalGet('/sitemap');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkByHrefNotExists('/rss.xml');
}
/**
* Tests sitemap plugins enabled by default.
*/
public function testSitemapPluginsEnabledByDefault(): void {
$dir = realpath(__DIR__ . '/../../..');
// The recipe should apply cleanly.
$this->applyRecipe($dir);
// Visit the sitemap configuration page.
// Grant permission to access sitemap configuration page.
$admin_user = $this->drupalCreateUser(['administer sitemap']);
$this->drupalLogin($admin_user);
// Visit the sitemap configuration page.
$this->drupalGet('/admin/config/search/sitemap');
// Check that the Menu: Main navigation plugin is enabled.
$this->assertSession()->checkboxChecked('edit-plugins-menumain-enabled');
// Check that the Frontpage plugin is enabled.
$this->assertSession()->checkboxChecked('edit-plugins-frontpage-enabled');
// Add a menu link to the Main navigation menu.
MenuLinkContent::create([
'title' => 'Test Link',
'link' => ['uri' => 'internal:/node/1'],
// Create a main menu link to ensure it shows up in the site map.
$node = $this->drupalCreateNode(['type' => 'test']);
$menu_link = MenuLinkContent::create([
'title' => $node->getTitle(),
'link' => 'internal:' . $node->toUrl()->toString(),
'menu_name' => 'main',
'weight' => 0,
])->save();
]);
$menu_link->save();
// Visit the sitemap page.
$this->drupalGet('/sitemap');
// Check that both plugins' items are present in the sitemap.
$this->assertSession()->elementExists('css', '.sitemap-item.sitemap-plugin--menu');
$this->assertSession()->elementExists('css', '.sitemap-item.sitemap-plugin--frontpage');
$assert_session = $this->assertSession();
$assert_session->statusCodeEquals(200);
$assert_session->linkByHrefNotExists('/rss.xml');
$site_map = $assert_session->elementExists('css', '.sitemap');
$site_name = $this->config('system.site')->get('name');
$this->assertTrue($site_map->hasLink("Front page of $site_name"), 'Front page link does not appear in the site map.');
$this->assertTrue($site_map->hasLink($menu_link->label()), 'Main menu links do not appear in the site map.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment