xmlsitemap_engines.test 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the xmlsitemap_engines module.
  5. */
  6. /**
  7. * Functional Test.
  8. *
  9. * @codingStandardsIgnoreStart
  10. */
  11. class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
  12. /**
  13. * Submit URL.
  14. *
  15. * @var string
  16. */
  17. protected $submit_url;
  18. /**
  19. * Get Info.
  20. *
  21. * @codingStandardsIgnoreEnd
  22. */
  23. public static function getInfo() {
  24. return array(
  25. 'name' => 'XML sitemap engines functional tests',
  26. 'description' => 'Functional tests for the XML sitemap engines module.',
  27. 'group' => 'XML sitemap',
  28. );
  29. }
  30. /**
  31. * Setup.
  32. */
  33. public function setUp($modules = array()) {
  34. $modules[] = 'xmlsitemap_engines';
  35. $modules[] = 'xmlsitemap_engines_test';
  36. parent::setUp($modules);
  37. $this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
  38. $this->drupalLogin($this->admin_user);
  39. // @todo For some reason the test client does not have clean URLs while
  40. // the test runner does, so it causes mismatches in watchdog assertions
  41. // later.
  42. variable_set('clean_url', 0);
  43. $this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
  44. }
  45. /**
  46. * Submit Engines.
  47. */
  48. public function submitEngines() {
  49. variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME - 10000);
  50. variable_set('xmlsitemap_generated_last', REQUEST_TIME - 100);
  51. variable_set('xmlsitemap_engines_minimum_lifetime', 0);
  52. xmlsitemap_engines_cron();
  53. $this->assertTrue(variable_get('xmlsitemap_engines_submit_last', 0) > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines.');
  54. }
  55. /**
  56. * Test Prepare URL.
  57. *
  58. * @codingStandardsIgnoreStart
  59. */
  60. public function testPrepareURL() {
  61. // @codingStandardsIgnoreEnd
  62. $sitemap = 'http://example.com/sitemap.xml';
  63. $input = 'http://example.com/ping?sitemap=[sitemap]&foo=bar';
  64. $output = 'http://example.com/ping?sitemap=http://example.com/sitemap.xml&foo=bar';
  65. $this->assertEqual(xmlsitemap_engines_prepare_url($input, $sitemap), $output);
  66. }
  67. /**
  68. * Test Submit Sitemaps.
  69. */
  70. public function testSubmitSitemaps() {
  71. $sitemaps = array();
  72. $sitemap = new stdClass();
  73. $sitemap->uri = array(
  74. 'path' => 'http://example.com/sitemap.xml',
  75. 'options' => array(),
  76. );
  77. $sitemaps[] = $sitemap;
  78. $sitemap = new stdClass();
  79. $sitemap->uri = array(
  80. 'path' => 'http://example.com/sitemap-2.xml',
  81. 'options' => array(),
  82. );
  83. $sitemaps[] = $sitemap;
  84. xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps);
  85. $this->assertWatchdogMessage(array(
  86. 'type' => 'xmlsitemap',
  87. 'message' => 'Recieved ping for @sitemap.',
  88. 'variables' => array(
  89. '@sitemap' => 'http://example.com/sitemap.xml',
  90. ),
  91. ));
  92. $this->assertWatchdogMessage(array(
  93. 'type' => 'xmlsitemap',
  94. 'message' => 'Recieved ping for @sitemap.',
  95. 'variables' => array(
  96. '@sitemap' => 'http://example.com/sitemap-2.xml',
  97. ),
  98. ));
  99. }
  100. /**
  101. * Test Ping.
  102. */
  103. public function testPing() {
  104. $edit = array('xmlsitemap_engines_engines[simpletest]' => TRUE);
  105. $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
  106. $this->assertText(t('The configuration options have been saved.'));
  107. $this->submitEngines();
  108. $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.'));
  109. $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.'));
  110. }
  111. /**
  112. * Test Custom URL.
  113. *
  114. * @codingStandardsIgnoreStart
  115. */
  116. public function testCustomURL() {
  117. // @codingStandardsIgnoreEnd
  118. $edit = array('xmlsitemap_engines_custom_urls' => 'an-invalid-url');
  119. $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
  120. $this->assertText('Invalid URL an-invalid-url.');
  121. $this->assertNoText('The configuration options have been saved.');
  122. $url = url('ping', array('absolute' => TRUE));
  123. $edit = array('xmlsitemap_engines_custom_urls' => $url);
  124. $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
  125. $this->assertText(t('The configuration options have been saved.'));
  126. $this->submitEngines();
  127. $this->assertWatchdogMessage(array(
  128. 'type' => 'xmlsitemap',
  129. 'message' => 'Submitted the sitemap to %url and received response @code.',
  130. 'variables' => array(
  131. '%url' => $url,
  132. '@code' => '404',
  133. ),
  134. ));
  135. $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
  136. $this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));
  137. $edit = array('xmlsitemap_engines_custom_urls' => $this->submit_url);
  138. $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
  139. $this->assertText(t('The configuration options have been saved.'));
  140. $this->submitEngines();
  141. $url = xmlsitemap_engines_prepare_url($this->submit_url, url('sitemap.xml', array('absolute' => TRUE)));
  142. $this->assertWatchdogMessage(array(
  143. 'type' => 'xmlsitemap',
  144. 'message' => 'Submitted the sitemap to %url and received response @code.',
  145. 'variables' => array(
  146. '%url' => $url,
  147. '@code' => '200',
  148. ),
  149. ));
  150. $this->assertWatchdogMessage(array(
  151. 'type' => 'xmlsitemap',
  152. 'message' => 'Recieved ping for @sitemap.',
  153. 'variables' => array(
  154. '@sitemap' => url('sitemap.xml', array(
  155. 'absolute' => TRUE,
  156. )),
  157. ),
  158. ));
  159. }
  160. }