public function XmlSitemapCustomFunctionalTest::testCustomLinks in XML sitemap 2.x
Same name and namespace in other branches
- 8 xmlsitemap_custom/tests/src/Functional/XmlSitemapCustomFunctionalTest.php \Drupal\Tests\xmlsitemap_custom\Functional\XmlSitemapCustomFunctionalTest::testCustomLinks()
Test adding custom links with wrong/private/correct paths.
File
- xmlsitemap_custom/
tests/ src/ Functional/ XmlSitemapCustomFunctionalTest.php, line 40
Class
- XmlSitemapCustomFunctionalTest
- Tests the functionality of xmlsitemap_custom module.
Namespace
Drupal\Tests\xmlsitemap_custom\FunctionalCode
public function testCustomLinks() {
$language = $this->languageManager
->getCurrentLanguage();
// Set a path alias for the node page.
$this->aliasStorage
->create([
'path' => '/system/files',
'alias' => '/public-files',
'langcode' => $language
->getId(),
])
->save();
$this
->drupalGet('admin/config/search/xmlsitemap/custom');
$this
->clickLink(t('Add custom link'));
// Test an invalid path.
$edit['loc'] = '/invalid-testing-path';
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertSession()
->pageTextContains(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', [
'@link' => $edit['loc'],
]));
$this
->assertNoSitemapLink([
'type' => 'custom',
'loc' => $edit['loc'],
]);
// Test a path not accessible to anonymous user.
$edit['loc'] = '/admin/people';
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertSession()
->pageTextContains(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', [
'@link' => $edit['loc'],
]));
$this
->assertNoSitemapLink([
'type' => 'custom',
'loc' => $edit['loc'],
]);
// Test that the current page, which should not give a false positive for
// $menu_item['access'] since the result has been cached already.
$edit['loc'] = '/admin/config/search/xmlsitemap/custom/add';
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertSession()
->pageTextContains(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', [
'@link' => $edit['loc'],
]));
$this
->assertNoSitemapLink([
'type' => 'custom',
'loc' => $edit['loc'],
]);
}