public function XMLSitemapCustomFunctionalTest::testCustomLinks in XML sitemap 7.2
Same name and namespace in other branches
- 6.2 xmlsitemap_custom/xmlsitemap_custom.test \XMLSitemapCustomFunctionalTest::testCustomLinks()
Test Custom Links.
File
- xmlsitemap_custom/
xmlsitemap_custom.test, line 39 - Unit tests for the xmlsitemap_custom.
Class
- XMLSitemapCustomFunctionalTest
- Class with Functional Test for XML Sitemap Custom.
Code
public function testCustomLinks() {
// Set a path alias for the node page.
$alias = array(
'source' => 'system/files',
'alias' => 'public-files',
);
path_save($alias);
$this
->drupalGet('admin/config/search/xmlsitemap/custom');
$this
->clickLink(t('Add custom link'));
// Test an invalid path.
$edit['loc'] = 'invalid-testing-path';
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array(
'@link' => $edit['loc'],
)));
$this
->assertNoSitemapLink(array(
'type' => 'custom',
'loc' => $edit['loc'],
));
// Test a path not accessible to anonymous user.
$edit['loc'] = 'admin/people/people';
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array(
'@link' => $edit['loc'],
)));
$this
->assertNoSitemapLink(array(
'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
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array(
'@link' => $edit['loc'],
)));
$this
->assertNoSitemapLink(array(
'type' => 'custom',
'loc' => $edit['loc'],
));
// Add an aliased path with padded spaces.
$edit['loc'] = ' public-files ';
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText('The custom link for system/files was saved');
$links = xmlsitemap_link_load_multiple(array(
'type' => 'custom',
'loc' => 'system/files',
));
$this
->assertEqual(count($links), 1, t('Custom link saved in the database.'));
$link = reset($links);
$this
->assertSitemapLinkValues('custom', $link['id'], array(
'priority' => 0.5,
'changefreq' => 0,
'access' => 1,
'status' => 1,
));
$this
->clickLink('Edit');
$edit = array(
'priority' => 0.1,
'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText('The custom link for system/files was saved');
$this
->assertSitemapLinkValues('custom', $link['id'], array(
'priority' => 0.1,
'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
'access' => 1,
'status' => 1,
));
$this
->clickLink('Delete');
$this
->drupalPost(NULL, array(), t('Delete'));
$this
->assertText('The custom link for system/files has been deleted.');
$this
->assertNoSitemapLink(array(
'type' => 'custom',
'loc' => 'system/files',
));
}