function XMLSitemapCustomFunctionalTest::testCustomLinks in XML sitemap 6.2
Same name and namespace in other branches
- 7.2 xmlsitemap_custom/xmlsitemap_custom.test \XMLSitemapCustomFunctionalTest::testCustomLinks()
File
- xmlsitemap_custom/
xmlsitemap_custom.test, line 26 - Unit tests for the xmlsitemap_custom module.
Class
- XMLSitemapCustomFunctionalTest
- @file Unit tests for the xmlsitemap_custom module.
Code
function testCustomLinks() {
// Set a path alias for the node page.
path_set_alias('system/files', 'public-files');
$this
->drupalGet('admin/settings/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/user/user';
$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/settings/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',
));
}