Commit 725c8cea authored by Dave Reid's avatar Dave Reid
Browse files

#694152 by mitrpaka, Dave Reid: Fixed multiple sitemaps not submitted correctly.

parent 4b267dd3
......@@ -3,12 +3,15 @@
/**
* @file
* Unit tests for the xmlsitemap_engines module.
* Tests for the xmlsitemap_engines module.
*/
class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
protected $submit_url;
public static function getInfo() {
return array(
'name' => 'XML sitemap engines interface tests',
'name' => 'XML sitemap engines functional tests',
'description' => 'Functional tests for the XML sitemap engines module.',
'group' => 'XML sitemap',
);
......@@ -18,7 +21,33 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
parent::setUp('xmlsitemap_engines', 'xmlsitemap_engines_test');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
variable_set('xmlsitemap_generated_last', REQUEST_TIME);
$this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
function submitEngines() {
variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME - 10000);
variable_set('xmlsitemap_generated_last', REQUEST_TIME - 100);
variable_set('xmlsitemap_engines_minimum_lifetime', 0);
xmlsitemap_engines_cron();
$this->assertTrue(variable_get('xmlsitemap_engines_submit_last', 0) > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines.');
}
function testPrepareURL() {
$sitemap = 'http://example.com/sitemap.xml';
$input = 'http://example.com/ping?sitemap=[sitemap]&foo=bar';
$output = 'http://example.com/ping?sitemap=http://example.com/sitemap.xml&foo=bar';
$this->assertEqual(xmlsitemap_engines_prepare_url($input, $sitemap), $output);
}
function testSubmitSitemaps() {
$sitemaps = array(
'http://example.com/sitemap.xml',
'http://example.com/sitemap-2.xml',
);
xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps);
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap.xml')));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap-2.xml')));
}
function testPing() {
......@@ -26,7 +55,7 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
xmlsitemap_engines_cron();
$this->submitEngines();
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.'));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.'));
}
......@@ -37,17 +66,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertText(t('Invalid custom URL an-invalid-url.'));
$this->assertNoText(t('The configuration options have been saved.'));
$edit = array('xmlsitemap_engines_custom_urls' => url('ping', array('absolute' => TRUE)));
$url = url('ping', array('absolute' => TRUE));
$edit = array('xmlsitemap_engines_custom_urls' => $url);
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
xmlsitemap_engines_cron();
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.'));
$this->submitEngines();
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.', 'variables' => array('%url' => $url, '@code' => '404')));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
$this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));
$edit = array('xmlsitemap_engines_custom_urls' => url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => '[sitemap]'))));
$edit = array('xmlsitemap_engines_custom_urls' => $this->submit_url);
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$this->submitEngines();
$url = xmlsitemap_engines_prepare_url($this->submit_url, url('sitemap.xml', array('absolute' => TRUE)));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.', 'variables' => array('%url' => $url, '@code' => '200')));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => url('sitemap.xml', array('absolute' => TRUE)))));
}
}
......@@ -28,7 +28,7 @@ function xmlsitemap_engines_test_xmlsitemap_engine_info() {
* Implements hook_xmlsitemap_engine_info_alter().
*/
function xmlsitemap_engines_test_xmlsitemap_engine_info_alter(&$engines) {
$engines['simpletest']['url'] = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => '[sitemap]')));
$engines['simpletest']['url'] = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
function xmlsitemap_engines_test_pinged() {
......
......@@ -107,9 +107,9 @@ function xmlsitemap_engines_submit_engines() {
*/
function xmlsitemap_engines_submit_sitemaps($url, $sitemaps = array()) {
foreach ($sitemaps as $sitemap) {
$url = xmlsitemap_engines_prepare_url($url, $sitemap);
$request = drupal_http_request($url);
watchdog('xmlsitemap', 'Submitted the sitemap to %url and received response @code.', array('%url' => $url, '@code' => $request->code));
$submit_url = xmlsitemap_engines_prepare_url($url, $sitemap);
$request = drupal_http_request($submit_url);
watchdog('xmlsitemap', 'Submitted the sitemap to %url and received response @code.', array('%url' => $submit_url, '@code' => $request->code));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment