xmlsitemap_custom.test 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * Unit tests for the xmlsitemap_custom module.
  5. */
  6. class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'XML sitemap custom interface tests',
  10. 'description' => 'Functional tests for the XML sitemap custom module.',
  11. 'group' => 'XML sitemap',
  12. );
  13. }
  14. function setUp($modules = array()) {
  15. $modules[] = 'xmlsitemap_custom';
  16. $modules[] = 'path';
  17. parent::setUp($modules);
  18. $this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
  19. $this->drupalLogin($this->admin_user);
  20. }
  21. function testCustomLinks() {
  22. // Set a path alias for the node page.
  23. $alias = array('source' => 'system/files', 'alias' => 'public-files');
  24. path_save($alias);
  25. $this->drupalGet('admin/config/search/xmlsitemap/custom');
  26. $this->clickLink(t('Add custom link'));
  27. // Test an invalid path.
  28. $edit['loc'] = 'invalid-testing-path';
  29. $this->drupalPost(NULL, $edit, t('Save'));
  30. $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  31. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  32. // Test a path not accessible to anonymous user.
  33. $edit['loc'] = 'admin/people/people';
  34. $this->drupalPost(NULL, $edit, t('Save'));
  35. $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  36. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  37. // Test that the current page, which should not give a false positive for
  38. // $menu_item['access'] since the result has been cached already.
  39. $edit['loc'] = 'admin/config/search/xmlsitemap/custom/add';
  40. $this->drupalPost(NULL, $edit, t('Save'));
  41. $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  42. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  43. // Add an aliased path with padded spaces.
  44. $edit['loc'] = ' public-files ';
  45. $this->drupalPost(NULL, $edit, t('Save'));
  46. $this->assertText('The custom link for system/files was saved');
  47. $links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => 'system/files'));
  48. $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
  49. $link = reset($links);
  50. $this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.5, 'changefreq' => 0, 'access' => 1, 'status' => 1));
  51. $this->clickLink('Edit');
  52. $edit = array(
  53. 'priority' => 0.1,
  54. 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
  55. );
  56. $this->drupalPost(NULL, $edit, t('Save'));
  57. $this->assertText('The custom link for system/files was saved');
  58. $this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.1, 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS, 'access' => 1, 'status' => 1));
  59. $this->clickLink('Delete');
  60. $this->drupalPost(NULL, array(), t('Delete'));
  61. $this->assertText('The custom link for system/files has been deleted.');
  62. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => 'system/files'));
  63. }
  64. /**
  65. * Test adding files as custom links.
  66. */
  67. function testCustomFileLinks() {
  68. // Test an invalid file.
  69. $edit['loc'] = $this->randomName();
  70. $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  71. $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  72. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  73. // Test an unaccessible file .
  74. //$edit['loc'] = '.htaccess';
  75. //$this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  76. //$this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  77. //$this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  78. // Test a valid file.
  79. $edit['loc'] = 'misc/drupal.js';
  80. $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  81. $this->assertText('The custom link for ' . $edit['loc'] . ' was saved');
  82. $links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => $edit['loc']));
  83. $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
  84. // Test a valid folder.
  85. $edit['loc'] = 'misc';
  86. $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  87. $this->assertText('The custom link for ' . $edit['loc'] . ' was saved');
  88. $links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => $edit['loc']));
  89. $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
  90. }
  91. }