Commit 7e2bf93b authored by Dave Reid's avatar Dave Reid

#793472 by Dave Reid: Hide the 'Rebuild links' page if there are no link types...

#793472 by Dave Reid: Hide the 'Rebuild links' page if there are no link types that are rebuildable.
parent 544c120d
......@@ -84,7 +84,7 @@ function xmlsitemap_requirements($phase) {
'value' => $generated_last ? $t('Last generated on !date (!interval ago).', array('!date' => format_date($generated_last, 'small'), '!interval' => format_interval($generated_ago))) : $t('Cached files have not been generated yet.'),
'severity' => REQUIREMENT_OK,
);
if (variable_get('xmlsitemap_rebuild_needed', FALSE)) {
if (variable_get('xmlsitemap_rebuild_needed', FALSE) && _xmlsitemap_rebuild_form_access()) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
$requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt<a>.', array('@link-rebuild' => url('admin/config/search/xmlsitemap/rebuild')));
}
......
......@@ -184,7 +184,7 @@ function xmlsitemap_menu() {
'description' => 'Rebuild the site map.',
'page callback' => 'drupal_get_form',
'page arguments' => array('xmlsitemap_rebuild_form'),
'access arguments' => array('administer xmlsitemap'),
'access callback' => '_xmlsitemap_rebuild_form_access',
'type' => MENU_LOCAL_TASK,
'file' => 'xmlsitemap.admin.inc',
'weight' => 20,
......@@ -217,6 +217,15 @@ function xmlsitemap_menu() {
return $items;
}
/**
* Menu access callback; determines if the user can use the rebuild links page.
*/
function _xmlsitemap_rebuild_form_access() {
module_load_include('generate.inc', 'xmlsitemap');
$rebuild_types = xmlsitemap_get_rebuildable_link_types();
return !empty($rebuild_types) && user_access('administer xmlsitemap');
}
/**
* Implements hook_cron().
*
......
......@@ -620,6 +620,35 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
$this->drupalGetSitemap();
$this->assertUniqueText('duplicate');
}
/**
* Test that the sitemap will not be genereated before the lifetime expires.
*/
function testMinimumLifetime() {
variable_set('xmlsitemap_minimum_lifetime', 300);
$this->regenerateSitemap();
$link = $this->addSitemapLink(array('loc' => 'lifetime-test'));
$this->cronRun();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
variable_set('xmlsitemap_generated_last', REQUEST_TIME - 400);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
xmlsitemap_link_delete($link['type'], $link['id']);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
$this->regenerateSitemap();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
}
}
class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
......@@ -653,38 +682,6 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
$this->assertResponse(304);
}
/**
* Test that the sitemap will not be genereated before the lifetime expires.
*/
function testMinimumLifetime() {
$this->regenerateSitemap();
$edit = array('xmlsitemap_minimum_lifetime' => 300);
$this->drupalPost('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$link = $this->addSitemapLink(array('loc' => 'lifetime-test'));
$this->cronRun();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
variable_set('xmlsitemap_generated_last', REQUEST_TIME - 150);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
xmlsitemap_link_delete($link['type'], $link['id']);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
$this->regenerateSitemap();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
}
/**
* Test base URL functionality.
*/
......@@ -715,13 +712,14 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
*/
function testStatusReport() {
// Test the rebuild flag.
variable_set('xmlsitemap_generated_last', REQUEST_TIME);
variable_set('xmlsitemap_rebuild_needed', TRUE);
$this->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
$this->clickLink(t('completely rebuilt'));
$this->assertResponse(200);
variable_set('xmlsitemap_rebuild_needed', FALSE);
$this->assertNoXMLSitemapProblems();
// @todo Re-enable these tests once we get a xmlsitemap_test.module.
//variable_set('xmlsitemap_generated_last', REQUEST_TIME);
//variable_set('xmlsitemap_rebuild_needed', TRUE);
//$this->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
//$this->clickLink(t('completely rebuilt'));
//$this->assertResponse(200);
//variable_set('xmlsitemap_rebuild_needed', FALSE);
//$this->assertNoXMLSitemapProblems();
// Test the regenerate flag (and cron hasn't run in a while).
variable_set('xmlsitemap_regenerate_needed', TRUE);
......
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