Commit e605f69d authored by RenatoG's avatar RenatoG Committed by RenatoG

Issue #2906627 by RenatoG: Resolve items of XML sitemap engines

parent 63985a31
...@@ -5,9 +5,25 @@ ...@@ -5,9 +5,25 @@
* Tests for the xmlsitemap_engines module. * Tests for the xmlsitemap_engines module.
*/ */
/**
* Functional Test.
*
* @codingStandardsIgnoreStart
*/
class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
/**
* Submit URL.
*
* @var string
*/
protected $submit_url; protected $submit_url;
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'XML sitemap engines functional tests', 'name' => 'XML sitemap engines functional tests',
...@@ -16,7 +32,10 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -16,7 +32,10 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
); );
} }
function setUp($modules = array()) { /**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_engines'; $modules[] = 'xmlsitemap_engines';
$modules[] = 'xmlsitemap_engines_test'; $modules[] = 'xmlsitemap_engines_test';
parent::setUp($modules); parent::setUp($modules);
...@@ -32,7 +51,10 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -32,7 +51,10 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]'; $this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
} }
function submitEngines() { /**
* Submit Engines.
*/
public function submitEngines() {
variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME - 10000); variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME - 10000);
variable_set('xmlsitemap_generated_last', REQUEST_TIME - 100); variable_set('xmlsitemap_generated_last', REQUEST_TIME - 100);
variable_set('xmlsitemap_engines_minimum_lifetime', 0); variable_set('xmlsitemap_engines_minimum_lifetime', 0);
...@@ -40,14 +62,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -40,14 +62,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertTrue(variable_get('xmlsitemap_engines_submit_last', 0) > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines.'); $this->assertTrue(variable_get('xmlsitemap_engines_submit_last', 0) > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines.');
} }
function testPrepareURL() { /**
* Test Prepare URL.
*
* @codingStandardsIgnoreStart
*/
public function testPrepareURL() {
// @codingStandardsIgnoreEnd
$sitemap = 'http://example.com/sitemap.xml'; $sitemap = 'http://example.com/sitemap.xml';
$input = 'http://example.com/ping?sitemap=[sitemap]&foo=bar'; $input = 'http://example.com/ping?sitemap=[sitemap]&foo=bar';
$output = 'http://example.com/ping?sitemap=http://example.com/sitemap.xml&foo=bar'; $output = 'http://example.com/ping?sitemap=http://example.com/sitemap.xml&foo=bar';
$this->assertEqual(xmlsitemap_engines_prepare_url($input, $sitemap), $output); $this->assertEqual(xmlsitemap_engines_prepare_url($input, $sitemap), $output);
} }
function testSubmitSitemaps() { /**
* Test Submit Sitemaps.
*/
public function testSubmitSitemaps() {
$sitemaps = array(); $sitemaps = array();
$sitemap = new stdClass(); $sitemap = new stdClass();
$sitemap->uri = array( $sitemap->uri = array(
...@@ -63,11 +94,26 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -63,11 +94,26 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$sitemaps[] = $sitemap; $sitemaps[] = $sitemap;
xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps); 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(
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap-2.xml'))); '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() { /**
* Test Ping.
*/
public function testPing() {
$edit = array('xmlsitemap_engines_engines[simpletest]' => TRUE); $edit = array('xmlsitemap_engines_engines[simpletest]' => TRUE);
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration')); $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.')); $this->assertText(t('The configuration options have been saved.'));
...@@ -77,7 +123,13 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -77,7 +123,13 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.')); $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.'));
} }
function testCustomURL() { /**
* Test Custom URL.
*
* @codingStandardsIgnoreStart
*/
public function testCustomURL() {
// @codingStandardsIgnoreEnd
$edit = array('xmlsitemap_engines_custom_urls' => 'an-invalid-url'); $edit = array('xmlsitemap_engines_custom_urls' => 'an-invalid-url');
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration')); $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText('Invalid URL an-invalid-url.'); $this->assertText('Invalid URL an-invalid-url.');
...@@ -89,7 +141,14 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -89,7 +141,14 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertText(t('The configuration options have been saved.')); $this->assertText(t('The configuration options have been saved.'));
$this->submitEngines(); $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' => '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' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
$this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping')); $this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));
...@@ -99,7 +158,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper { ...@@ -99,7 +158,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->submitEngines(); $this->submitEngines();
$url = xmlsitemap_engines_prepare_url($this->submit_url, url('sitemap.xml', array('absolute' => TRUE))); $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(
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => url('sitemap.xml', array('absolute' => TRUE))))); '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,
)),
),
));
} }
} }
...@@ -2,5 +2,4 @@ name = XML sitemap engines test ...@@ -2,5 +2,4 @@ name = XML sitemap engines test
description = Support module for XML sitemap engines testing. description = Support module for XML sitemap engines testing.
package = Testing package = Testing
core = 7.x core = 7.x
files[] = xmlsitemap_engines_test.module
hidden = TRUE hidden = TRUE
<?php <?php
/**
* @file
* Unit tests for the XML sitemap engines project.
*/
/** /**
* Implements hook_menu(). * Implements hook_menu().
*/ */
function xmlsitemap_engines_test_menu() { function xmlsitemap_engines_test_menu() {
$items['ping'] = array( $items['ping'] = array(
'page callback' => 'xmlsitemap_engines_test_pinged', 'page callback' => 'xmlsitemap_engines_test_pinged',
// @codingStandardsIgnoreLine
'access callback' => TRUE, 'access callback' => TRUE,
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
...@@ -30,6 +36,9 @@ function xmlsitemap_engines_test_xmlsitemap_engine_info_alter(&$engines) { ...@@ -30,6 +36,9 @@ 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]';
} }
/**
* Test pinged.
*/
function xmlsitemap_engines_test_pinged() { function xmlsitemap_engines_test_pinged() {
if (empty($_GET['sitemap']) || !valid_url($_GET['sitemap'])) { if (empty($_GET['sitemap']) || !valid_url($_GET['sitemap'])) {
watchdog('xmlsitemap', 'No valid sitemap parameter provided.', array(), WATCHDOG_WARNING); watchdog('xmlsitemap', 'No valid sitemap parameter provided.', array(), WATCHDOG_WARNING);
......
...@@ -26,7 +26,19 @@ function xmlsitemap_engines_settings_form() { ...@@ -26,7 +26,19 @@ function xmlsitemap_engines_settings_form() {
$form['xmlsitemap_engines_minimum_lifetime'] = array( $form['xmlsitemap_engines_minimum_lifetime'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Do not submit more often than every'), '#title' => t('Do not submit more often than every'),
'#options' => drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 604800 * 2, 604800 * 4), 'format_interval'), '#options' => drupal_map_assoc(array(
3600,
10800,
21600,
32400,
43200,
86400,
172800,
259200,
604800,
604800 * 2,
604800 * 4,
), 'format_interval'),
'#default_value' => variable_get('xmlsitemap_engines_minimum_lifetime', 86400), '#default_value' => variable_get('xmlsitemap_engines_minimum_lifetime', 86400),
); );
$form['xmlsitemap_engines_submit_updated'] = array( $form['xmlsitemap_engines_submit_updated'] = array(
...@@ -37,7 +49,12 @@ function xmlsitemap_engines_settings_form() { ...@@ -37,7 +49,12 @@ function xmlsitemap_engines_settings_form() {
$form['xmlsitemap_engines_custom_urls'] = array( $form['xmlsitemap_engines_custom_urls'] = array(
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Custom submission URLs'), '#title' => t('Custom submission URLs'),
'#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array('%example-before' => 'http://example.com/ping?[sitemap]', '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array('absolute' => TRUE))))), '#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array(
'%example-before' => 'http://example.com/ping?[sitemap]',
'%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array(
'absolute' => TRUE,
))),
)),
'#default_value' => variable_get('xmlsitemap_engines_custom_urls', ''), '#default_value' => variable_get('xmlsitemap_engines_custom_urls', ''),
'#rows' => 2, '#rows' => 2,
'#wysiwyg' => FALSE, '#wysiwyg' => FALSE,
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
function hook_xmlsitemap_engine_info() { function hook_xmlsitemap_engine_info() {
$engines['example'] = array( $engines['example'] = array(
'name' => t('Example search engine'), 'name' => t('Example search engine'),
'url' => 'http://example.com/ping?sitemap=[sitemap]' 'url' => 'http://example.com/ping?sitemap=[sitemap]',
); );
return $engines; return $engines;
} }
......
...@@ -3,9 +3,6 @@ description = Submit the sitemap to search engines. ...@@ -3,9 +3,6 @@ description = Submit the sitemap to search engines.
package = XML sitemap package = XML sitemap
core = 7.x core = 7.x
dependencies[] = xmlsitemap dependencies[] = xmlsitemap
files[] = xmlsitemap_engines.module
files[] = xmlsitemap_engines.admin.inc
files[] = xmlsitemap_engines.install
files[] = tests/xmlsitemap_engines.test files[] = tests/xmlsitemap_engines.test
recommends[] = site_verify recommends[] = site_verify
configure = admin/config/search/xmlsitemap/engines configure = admin/config/search/xmlsitemap/engines
<?php <?php
/**
* @file
* Main file for XML sitemap engines.
*/
/** /**
* Implements hook_hook_info(). * Implements hook_hook_info().
*/ */
...@@ -41,12 +46,13 @@ function xmlsitemap_engines_menu() { ...@@ -41,12 +46,13 @@ function xmlsitemap_engines_menu() {
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'file' => 'xmlsitemap_engines.admin.inc', 'file' => 'xmlsitemap_engines.admin.inc',
); );
//$items['admin/config/search/xmlsitemap/engines/submit'] = array( // @code
// 'page callback' => 'xmlsitemap_engines_submit', // $items['admin/config/search/xmlsitemap/engines/submit'] = array(
// 'access callback' => 'xmlsitemap_engines_submit_access', // 'page callback' => 'xmlsitemap_engines_submit',
// 'type' => MENU_CALLBACK, // 'access callback' => 'xmlsitemap_engines_submit_access',
//); // 'type' => MENU_CALLBACK,
// );
// @endcode
return $items; return $items;
} }
...@@ -59,6 +65,9 @@ function xmlsitemap_engines_cron() { ...@@ -59,6 +65,9 @@ function xmlsitemap_engines_cron() {
} }
} }
/**
* Check if can submit.
*/
function xmlsitemap_engines_can_submit() { function xmlsitemap_engines_can_submit() {
// Skip if the site is offline since search engines will not be able to // Skip if the site is offline since search engines will not be able to
// access the site's content. // access the site's content.
...@@ -73,16 +82,21 @@ function xmlsitemap_engines_can_submit() { ...@@ -73,16 +82,21 @@ function xmlsitemap_engines_can_submit() {
return TRUE; return TRUE;
} }
/**
* Submit access.
*/
function xmlsitemap_engines_submit_access() { function xmlsitemap_engines_submit_access() {
if (!xmlsitemap_engines_can_submit()) { if (!xmlsitemap_engines_can_submit()) {
return FALSE; return FALSE;
} }
// Allow manual submissions to run. // Allow manual submissions to run.
//if ($_GET['q'] == 'admin/config/search/xmlsitemap/engines/submit' && user_access('administer xmlsitemap')) { // @code
// return TRUE; // @codingStandardsIgnoreLine
//} // if ($_GET['q'] == 'admin/config/search/xmlsitemap/engines/submit' && user_access('administer xmlsitemap')) {
// return TRUE;
// }
// @endcode
$submit_updated = variable_get('xmlsitemap_engines_submit_updated', TRUE); $submit_updated = variable_get('xmlsitemap_engines_submit_updated', TRUE);
$submitted_last = variable_get('xmlsitemap_engines_submit_last', 0); $submitted_last = variable_get('xmlsitemap_engines_submit_last', 0);
$minimum_lifetime = variable_get('xmlsitemap_engines_minimum_lifetime', 86400); $minimum_lifetime = variable_get('xmlsitemap_engines_minimum_lifetime', 86400);
...@@ -103,7 +117,7 @@ function xmlsitemap_engines_submit_access() { ...@@ -103,7 +117,7 @@ function xmlsitemap_engines_submit_access() {
/** /**
* Submit the sitemaps to all the specified search engines. * Submit the sitemaps to all the specified search engines.
* *
* @param $smids * @param array $smids
* An optional array of XML sitemap IDs. If not provided, it will load all * An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps. * existing XML sitemaps.
*/ */
...@@ -134,9 +148,9 @@ function xmlsitemap_engines_submit_engines(array $smids = array()) { ...@@ -134,9 +148,9 @@ function xmlsitemap_engines_submit_engines(array $smids = array()) {
/** /**
* Submit the sitemaps to a specific URL. * Submit the sitemaps to a specific URL.
* *
* @param $url * @param string $url
* The URL for sitemap submission. * The URL for sitemap submission.
* @param $sitemaps * @param array $sitemaps
* An array of URLs of the sitemaps to submit. * An array of URLs of the sitemaps to submit.
*/ */
function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) { function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
...@@ -151,9 +165,10 @@ function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) { ...@@ -151,9 +165,10 @@ function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
/** /**
* Replace valid tokens in the URL with their appropriate values. * Replace valid tokens in the URL with their appropriate values.
* *
* @param $url * @param string $url
* An un-tokenized URL. * An un-tokenized URL.
* @return *
* @return string
* A tokenized URL. * A tokenized URL.
*/ */
function xmlsitemap_engines_prepare_url($url, $sitemap) { function xmlsitemap_engines_prepare_url($url, $sitemap) {
...@@ -163,12 +178,9 @@ function xmlsitemap_engines_prepare_url($url, $sitemap) { ...@@ -163,12 +178,9 @@ function xmlsitemap_engines_prepare_url($url, $sitemap) {
/** /**
* Returns information about supported search engines. * Returns information about supported search engines.
* *
* @param $engine * @param string $engine
* (optional) The engine to return information for. If omitted, information * (optional) The engine to return information for. If omitted, information
* for all engines is returned. * for all engines is returned.
* @param $reset
* (optional) Boolean whether to reset the static cache and do nothing. Only
* used for tests.
* *
* @see hook_xmlsitemap_engines_info() * @see hook_xmlsitemap_engines_info()
* @see hook_xmlsitemap_engines_info_alter() * @see hook_xmlsitemap_engines_info_alter()
......
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