first import
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
name = XML sitemap internationalization
|
||||
description = Enables multilingual XML sitemaps.
|
||||
package = XML sitemap
|
||||
core = 7.x
|
||||
dependencies[] = xmlsitemap
|
||||
dependencies[] = i18n
|
||||
files[] = xmlsitemap_i18n.module
|
||||
files[] = xmlsitemap_i18n.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-12-08
|
||||
version = "7.x-2.0-rc2+0-dev"
|
||||
core = "7.x"
|
||||
project = "xmlsitemap"
|
||||
datestamp = "1354931808"
|
||||
|
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_xmlsitemap_context_info().
|
||||
*/
|
||||
function xmlsitemap_i18n_xmlsitemap_context_info() {
|
||||
$context['language'] = array(
|
||||
'label' => t('Language'),
|
||||
'summary callback' => 'locale_language_name',
|
||||
'default' => language_default('language'),
|
||||
);
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_xmlsitemap_context().
|
||||
*/
|
||||
function xmlsitemap_i18n_xmlsitemap_context() {
|
||||
$context['language'] = $GLOBALS['language']->language;
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements xmlsitemap_context_url_options().
|
||||
*/
|
||||
function xmlsitemap_i18n_xmlsitemap_context_url_options(array $context) {
|
||||
$options = array();
|
||||
if (isset($context['language'])) {
|
||||
$options['language'] = xmlsitemap_language_load($context['language']);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function xmlsitemap_i18n_form_xmlsitemap_sitemap_edit_form_alter(&$form, $form_state) {
|
||||
$form['context']['language'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Language'),
|
||||
'#options' => locale_language_list(),
|
||||
'#default_value' => isset($form['#sitemap']->context['language']) ? $form['#sitemap']->context['language'] : LANGUAGE_NONE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*
|
||||
* Set the regeneration needed flag if settings are changed.
|
||||
*/
|
||||
function xmlsitemap_form_locale_languages_overview_form_alter(&$form, $form_state) {
|
||||
array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*
|
||||
* Set the regeneration needed flag if multilingual settings are changed.
|
||||
*/
|
||||
function xmlsitemap_i18n_form_i18n_admin_settings_alter(&$form, $form_state) {
|
||||
array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter().
|
||||
*
|
||||
* @see i18n_db_rewrite_where()
|
||||
*/
|
||||
function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface $query) {
|
||||
$mode = variable_get('i18n_selection_mode', 'simple');
|
||||
$sitemap = $query->getMetaData('sitemap');
|
||||
|
||||
if (!isset($sitemap->context['language']) || $mode == 'off') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get languages to simplify query building.
|
||||
$current = $sitemap->context['language'];
|
||||
$default = language_default();
|
||||
|
||||
if ($mode == 'mixed' && $current == $default) {
|
||||
// If mode is mixed but current = default, is the same as 'simple'.
|
||||
$mode = 'simple';
|
||||
}
|
||||
|
||||
switch ($mode) {
|
||||
case 'simple':
|
||||
// Current language and language neutral.
|
||||
$query->condition('language', array($current, LANGUAGE_NONE));
|
||||
break;
|
||||
case 'mixed':
|
||||
// Mixed current language (if available) or default language (if not) and language neutral.
|
||||
$query->condition('language', array($current, $default, LANGUAGE_NONE));
|
||||
break;
|
||||
case 'default':
|
||||
// Only default language and language neutral.
|
||||
$query->condition('language', array($default, LANGUAGE_NONE));
|
||||
break;
|
||||
case 'strict':
|
||||
// Only current language (for nodes), simple for all other types.
|
||||
$node_condition = db_and();
|
||||
$node_condition->condition('type', 'node');
|
||||
$node_condition->condition('language', $current);
|
||||
$normal_condition = db_and();
|
||||
$normal_condition->condition('type', 'node', '<>');
|
||||
$normal_condition->condition('language', array($current, LANGUAGE_NONE));
|
||||
$condition = db_or();
|
||||
$condition->condition($node_condition);
|
||||
$condition->condition($normal_condition);
|
||||
$query->condition($condition);
|
||||
break;
|
||||
case 'off':
|
||||
// All content. No language conditions apply.
|
||||
break;
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Unit tests for the xmlsitemap_i18n module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Common base test class for XML sitemap internationalization tests.
|
||||
*/
|
||||
class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
|
||||
protected $admin_user;
|
||||
|
||||
/**
|
||||
* Set up an administrative user account and testing keys.
|
||||
*/
|
||||
function setUp($modules = array()) {
|
||||
// Call parent::setUp() allowing test cases to pass further modules.
|
||||
$modules[] = 'locale';
|
||||
$modules[] = 'translation';
|
||||
$modules[] = 'i18n';
|
||||
$modules[] = 'xmlsitemap_i18n';
|
||||
parent::setUp($modules);
|
||||
|
||||
// Add predefined language and reset the locale cache.
|
||||
require_once DRUPAL_ROOT . '/includes/locale.inc';
|
||||
locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
|
||||
drupal_language_initialize();
|
||||
variable_set('language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
|
||||
|
||||
// Create the two different language-context sitemaps.
|
||||
db_query("DELETE FROM {xmlsitemap_sitemap}");
|
||||
$sitemap = new stdClass();
|
||||
$sitemap->context = array('language' => 'en');
|
||||
xmlsitemap_sitemap_save($sitemap);
|
||||
$sitemap = new stdClass();
|
||||
$sitemap->context = array('language' => 'fr');
|
||||
xmlsitemap_sitemap_save($sitemap);
|
||||
}
|
||||
}
|
||||
|
||||
class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'XML sitemap i18n tests',
|
||||
'description' => 'Functional and integration tests for the XML sitemap and internationalization modules.',
|
||||
'group' => 'XML sitemap',
|
||||
'dependencies' => array('i18n', 'disable-this-test-for-now'),
|
||||
);
|
||||
}
|
||||
|
||||
function testLanguageSelection() {
|
||||
// Create our three different language nodes.
|
||||
$node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
|
||||
$node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
|
||||
$node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));
|
||||
|
||||
// Create three non-node language nodes.
|
||||
$link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
|
||||
$link_en = $this->addSitemapLink(array('language' => 'en'));
|
||||
$link_fr = $this->addSitemapLink(array('language' => 'fr'));
|
||||
|
||||
variable_set('i18n_selection_mode', 'off');
|
||||
$this->regenerateSitemap();
|
||||
$this->drupalGetSitemap(array('language' => 'en'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
|
||||
$this->drupalGetSitemap(array('language' => 'fr'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
|
||||
|
||||
variable_set('i18n_selection_mode', 'simple');
|
||||
$this->regenerateSitemap();
|
||||
$this->drupalGetSitemap(array('language' => 'en'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
|
||||
$this->assertNoRawSitemapLinks($node_fr, $link_fr);
|
||||
$this->drupalGetSitemap(array('language' => 'fr'));
|
||||
$this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
|
||||
$this->assertNoRawSitemapLinks($node_en, $link_en);
|
||||
|
||||
variable_set('i18n_selection_mode', 'mixed');
|
||||
$this->regenerateSitemap();
|
||||
$this->drupalGetSitemap(array('language' => 'en'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
|
||||
$this->assertNoRawSitemapLinks($node_fr, $link_fr);
|
||||
$this->drupalGetSitemap(array('language' => 'fr'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
|
||||
|
||||
variable_set('i18n_selection_mode', 'default');
|
||||
$this->regenerateSitemap();
|
||||
$this->drupalGetSitemap(array('language' => 'en'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
|
||||
$this->assertNoRawSitemapLinks($node_fr, $link_fr);
|
||||
$this->drupalGetSitemap(array('language' => 'fr'));
|
||||
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
|
||||
$this->assertNoRawSitemapLinks($node_fr, $link_fr);
|
||||
|
||||
// With strict mode, the language neutral node should not be found, but the
|
||||
// language neutral non-node should be.
|
||||
variable_set('i18n_selection_mode', 'strict');
|
||||
$this->regenerateSitemap();
|
||||
$this->drupalGetSitemap(array('language' => 'en'));
|
||||
$this->assertRawSitemapLinks($node_en, $link, $link_en);
|
||||
$this->assertNoRawSitemapLinks($node, $node_fr, $link_fr);
|
||||
$this->drupalGetSitemap(array('language' => 'fr'));
|
||||
$this->assertRawSitemapLinks($node_fr, $link, $link_fr);
|
||||
$this->assertNoRawSitemapLinks($node, $node_en, $link_en);
|
||||
}
|
||||
}
|
||||
|
||||
class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'XML sitemap i18n node tests',
|
||||
'description' => 'Functional and integration tests for the XML sitemap node and internationalization modules.',
|
||||
'group' => 'XML sitemap',
|
||||
'dependencies' => array('i18n', 'disable-this-test-for-now'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($modules = array()) {
|
||||
$modules[] = 'xmlsitemap_node';
|
||||
parent::setUp($modules);
|
||||
|
||||
variable_set('language_content_type_page', 1);
|
||||
$this->admin_user = $this->drupalCreateUser(array('administer nodes'));
|
||||
$this->drupalLogin($this->admin_user);
|
||||
}
|
||||
|
||||
function testNodeLanguageData() {
|
||||
$node = $this->drupalCreateNode(array());
|
||||
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
|
||||
$link = $this->assertSitemapLink('node', $node->nid);
|
||||
$this->assertIdentical($link['language'], 'en');
|
||||
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'fr'), t('Save'));
|
||||
$link = $this->assertSitemapLink('node', $node->nid);
|
||||
$this->assertIdentical($link['language'], 'fr');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user