Skip to content
Snippets Groups Projects

Issue #3498036: Add test for Sitemap module enabled plugins

@@ -6,6 +6,7 @@ namespace Drupal\Tests\drupal_cms_seo_tools\Functional;
@@ -6,6 +6,7 @@ namespace Drupal\Tests\drupal_cms_seo_tools\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait;
use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait;
 
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\BrowserTestBase;
/**
/**
@@ -53,12 +54,28 @@ class ComponentValidationTest extends BrowserTestBase {
@@ -53,12 +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 {
private function checkSitemap(): void {
 
// 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',
 
]);
 
$menu_link->save();
 
$this->drupalGet('/sitemap');
$this->drupalGet('/sitemap');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkByHrefNotExists('/rss.xml');
$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.');
}
}
}
}
Loading