From f23eef621a55b0ea7c7d12878fcd1cef6dae3f7f Mon Sep 17 00:00:00 2001 From: Riyas N R <riyas.nr@qed42.com> Date: Thu, 13 Feb 2025 16:46:13 +0530 Subject: [PATCH 1/2] Issue #3498036: Add test for Sitemap module enabled plugins --- .../Functional/ComponentValidationTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php b/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php index 4515f008f..c9a39dc10 100644 --- a/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php +++ b/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php @@ -6,6 +6,7 @@ namespace Drupal\Tests\drupal_cms_seo_tools\Functional; use Drupal\field\Entity\FieldConfig; use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait; +use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\Tests\BrowserTestBase; /** @@ -61,4 +62,44 @@ class ComponentValidationTest extends BrowserTestBase { $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'], + 'menu_name' => 'main', + 'weight' => 0, + ])->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'); + } + } -- GitLab From 82bec0de32b4d2066e0918d89641761d27967392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=A9na=20Proxima?= <adam@phenaproxima.net> Date: Tue, 18 Feb 2025 09:17:43 -0500 Subject: [PATCH 2/2] Make the test a little more direct --- .../Functional/ComponentValidationTest.php | 56 ++++++------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php b/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php index c9a39dc10..d7a732cbb 100644 --- a/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php +++ b/recipes/drupal_cms_seo_tools/tests/src/Functional/ComponentValidationTest.php @@ -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.'); } } -- GitLab