xmlsitemap_custom.test 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // $Id: xmlsitemap_custom.test,v 1.6 2010/01/24 03:57:14 davereid Exp $
  3. /**
  4. * @file
  5. * Unit tests for the xmlsitemap_custom module.
  6. */
  7. class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
  8. protected $admin_user;
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'XML sitemap custom interface tests',
  12. 'description' => 'Functional tests for the XML sitemap custom module.',
  13. 'group' => 'XML sitemap',
  14. );
  15. }
  16. function setUp() {
  17. parent::setUp('xmlsitemap_custom', 'path');
  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/config/people/accounts';
  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. $link = $this->assertSitemapLink(array('type' => 'custom', 'loc' => 'system/files'));
  48. $this->assertSitemapLinkValues($link, array('priority' => 0.5, 'changefreq' => 0, 'access' => 1, 'status' => 1));
  49. $this->clickLink('Edit');
  50. $edit = array(
  51. 'priority' => 0.1,
  52. 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
  53. );
  54. $this->drupalPost(NULL, $edit, t('Save'));
  55. $this->assertText('The custom link for system/files was saved');
  56. $link = $this->assertSitemapLink(array('type' => 'custom', 'id' => $link['id']));
  57. $this->assertSitemapLinkValues($link, array('priority' => 0.1, 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS, 'access' => 1, 'status' => 1));
  58. $this->clickLink('Delete');
  59. $this->drupalPost(NULL, array(), t('Delete'));
  60. $this->assertText('The custom link for system/files has been deleted.');
  61. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => 'system/files'));
  62. }
  63. /**
  64. * Test adding files as custom links.
  65. */
  66. function testCustomFileLinks() {
  67. // Test an invalid file.
  68. $edit['loc'] = $this->randomName();
  69. $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  70. $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  71. $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  72. // Test an unaccessible file .
  73. //$edit['loc'] = '.htaccess';
  74. //$this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  75. //$this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
  76. //$this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  77. // Test a valid file.
  78. $edit['loc'] = 'misc/drupal.js';
  79. $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  80. $this->assertText('The custom link for ' . $edit['loc'] . ' was saved');
  81. $link = $this->assertSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  82. // Test a valid folder.
  83. $edit['loc'] = 'misc';
  84. $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
  85. $this->assertText('The custom link for ' . $edit['loc'] . ' was saved');
  86. $link = $this->assertSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
  87. }
  88. }