Commit 9c531a62 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Fixing failed tests.

parent ef8f4711
......@@ -275,8 +275,8 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
// Add the XML header and XSL if desired.
xmlsitemap_generate_chunk_header('urlset', $handle, $status, $language);
foreach ($links->fetchAssoc() as $link) {
$url_options['language'] = $link['language'] != LANGUAGE_NONE ? $languages[$link['language']] : $language;
while ($link = $links->fetchAssoc()) {
$url_options['language'] = ($link['language'] != LANGUAGE_NONE ? $languages[$link['language']] : $language);
$link['alias'] = xmlsitemap_get_path_alias($link['loc'], $url_options['language']->language);
$link_url = url($link['alias'], $url_options);
......
......@@ -127,7 +127,7 @@ function xmlsitemap_install() {
// Insert the homepage link into the {xmlsitemap} table so we do not show an
// empty sitemap after install.
db_query("INSERT INTO {xmlsitemap} (type, id, loc, priority, changefreq) VALUES ('frontpage', 0, '', :priority, :changefreq)", array(':priority' => xmlsitemap_var('frontpage_priority'), 'changefreq' => xmlsitemap_var('frontpage_changefreq')));
db_query("INSERT INTO {xmlsitemap} (type, id, loc, priority, changefreq, language) VALUES ('frontpage', 0, '', :priority, :changefreq, :language)", array(':priority' => xmlsitemap_var('frontpage_priority'), 'changefreq' => xmlsitemap_var('frontpage_changefreq'), ':language' => LANGUAGE_NONE));
// @todo Does the sitemap show up on first install or is it a 404 page?
}
......
......@@ -69,8 +69,12 @@ function xmlsitemap_help($path, $arg) {
/**
* Implements hook_perm().
*/
function xmlsitemap_perm() {
return array('administer xmlsitemap');
function xmlsitemap_permission() {
return array(
'administer xmlsitemap' => array(
'title' => t('Administer XML sitemap settings.'),
),
);
}
/**
......
......@@ -172,17 +172,16 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
private function getWatchdogMessage(array $conditions) {
static $watchdog_schema;
if (!isset($watchdog_schema)) {
$watchdog_schema = drupal_get_schema('watchdog');
}
$args = array();
$query = db_select('watchdog');
$query->fields('watchdog');
foreach ($conditions as $field => $value) {
$conditions[$field] = $field . ' = ' . db_type_placeholder($watchdog_schema['fields'][$field]['type']);
$args[] = ($field == 'variables' && is_array($value)) ? serialize($value) : $value;
if ($field == 'variables' && is_array($value)) {
$value = serialize($value);
}
$query->conditions($field, $value);
}
return db_query_range("SELECT 1 FROM {watchdog} WHERE " . implode(' AND ', $conditions), 0, 1, $args)->fetchField();
return $query->execute()->fetchAll();
}
protected function assertWatchdogMessage(array $conditions, $message = 'Watchdog message found.') {
......@@ -226,14 +225,14 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return;
}
$sql = "SELECT wid, type, severity, message, variables, timestamp FROM {watchdog}";
$query = db_select('watchdog');
$query->fields('watchdog', array('wid', 'type', 'severity', 'message', 'variables', 'timestamp'));
if ($seen_ids) {
$sql .= " WHERE wid NOT IN (" . db_placeholders($seen_ids) . ")";
$query->condition('wid', $seen_ids);
}
$sql .= " ORDER BY timestamp ASC";
$query = db_query($sql, $seen_ids);
$query->orderBy('timestamp', 'ASC');
$messages = $query->execute()->fetchAllAssoc('wid');
$messages = $query->fetchAllAssoc('wid');
foreach ($messages as &$message) {
$message->text = $message->timestamp . ' ' . t($message->message, unserialize($message->variables));
}
......@@ -597,17 +596,16 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
}
function setUp() {
parent::setUp('xmlsitemap', 'path');
parent::setUp('path');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
$this->checkFilesDirectory();
$this->regenerateSitemap();
}
/**
* Test the sitemap file caching.
*/
function testSitemapCaching() {
$this->regenerateSitemap();
$this->drupalGet('sitemap.xml');
$this->assertResponse(200);
$etag = $this->drupalGetHeader('etag');
......@@ -693,10 +691,9 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
$this->assertNoXMLSitemapProblems();
// Test anonymous users access to sitemap.xml.
$anon_permissions = db_query("SELECT perm FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID)->fetchField();
db_query("UPDATE {permission} SET perm = '' WHERE rid = %d", DRUPAL_ANONYMOUS_RID);
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));
$this->assertXMLSitemapProblems(t('In order to allow search engines to view the XML sitemap and content on your site, the anonymous user role must have the access content permission.'));
db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $anon_permissions, DRUPAL_ANONYMOUS_RID);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));
$this->assertNoXMLSitemapProblems();
// Test chunk count > 1000.
......@@ -709,7 +706,7 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
function testDuplicatePaths() {
$link1 = $this->addSitemapLink(array('loc' => 'duplicate'));
$link2 = $this->addSitemapLink(array('loc' => 'duplicate'));
$this->drupalGetSitemap('', TRUE);
$this->drupalGetSitemap(LANGUAGE_NONE, TRUE);
$this->assertUniqueText('duplicate');
}
}
......
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