xmlsitemap_custom.test 5.2 KB

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