Commit 63985a31 authored by RenatoG's avatar RenatoG Committed by RenatoG

Issue #2906618 by RenatoG: Fix Drupal Coding Standards for XML sitemap i18n

parent 327ccba3
...@@ -4,5 +4,4 @@ package = XML sitemap ...@@ -4,5 +4,4 @@ package = XML sitemap
core = 7.x core = 7.x
dependencies[] = xmlsitemap dependencies[] = xmlsitemap
dependencies[] = i18n dependencies[] = i18n
files[] = xmlsitemap_i18n.module
files[] = xmlsitemap_i18n.test files[] = xmlsitemap_i18n.test
<?php <?php
/**
* @file
* Main file for XML sitemap i18n.
*/
/** /**
* Implements hook_xmlsitemap_context_info(). * Implements hook_xmlsitemap_context_info().
*/ */
...@@ -88,14 +93,18 @@ function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface ...@@ -88,14 +93,18 @@ function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface
// Current language and language neutral. // Current language and language neutral.
$query->condition('x.language', array($current, LANGUAGE_NONE)); $query->condition('x.language', array($current, LANGUAGE_NONE));
break; break;
case 'mixed': case 'mixed':
// Mixed current language (if available) or default language (if not) and language neutral. // Mixed current language (if available) or default language (if not) and
// language neutral.
$query->condition('x.language', array($current, $default, LANGUAGE_NONE)); $query->condition('x.language', array($current, $default, LANGUAGE_NONE));
break; break;
case 'default': case 'default':
// Only default language and language neutral. // Only default language and language neutral.
$query->condition('x.language', array($default, LANGUAGE_NONE)); $query->condition('x.language', array($default, LANGUAGE_NONE));
break; break;
case 'strict': case 'strict':
// Only current language (for nodes), simple for all other types. // Only current language (for nodes), simple for all other types.
$node_condition = db_and(); $node_condition = db_and();
...@@ -109,6 +118,7 @@ function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface ...@@ -109,6 +118,7 @@ function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface
$condition->condition($normal_condition); $condition->condition($normal_condition);
$query->condition($condition); $query->condition($condition);
break; break;
case 'off': case 'off':
// All content. No language conditions apply. // All content. No language conditions apply.
break; break;
......
...@@ -2,19 +2,29 @@ ...@@ -2,19 +2,29 @@
/** /**
* @file * @file
* Unit tests for the xmlsitemap_i18n module. * Unit tests for the xmlsitemap_i18n project.
*/ */
/** /**
* Common base test class for XML sitemap internationalization tests. * Common base test class for XML sitemap internationalization tests.
*/ */
class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper { class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
/**
* Admin User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $admin_user; protected $admin_user;
/** /**
* Set up an administrative user account and testing keys. * Set up an administrative user account and testing keys.
*
* @codingStandardsIgnoreEnd
*/ */
function setUp($modules = array()) { public function setUp($modules = array()) {
// Call parent::setUp() allowing test cases to pass further modules. // Call parent::setUp() allowing test cases to pass further modules.
$modules[] = 'locale'; $modules[] = 'locale';
$modules[] = 'translation'; $modules[] = 'translation';
...@@ -30,6 +40,7 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper { ...@@ -30,6 +40,7 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
// Create the two different language-context sitemaps. // Create the two different language-context sitemaps.
db_query("DELETE FROM {xmlsitemap_sitemap}"); db_query("DELETE FROM {xmlsitemap_sitemap}");
$sitemap = new stdClass(); $sitemap = new stdClass();
$sitemap->context = array('language' => 'en'); $sitemap->context = array('language' => 'en');
xmlsitemap_sitemap_save($sitemap); xmlsitemap_sitemap_save($sitemap);
...@@ -37,9 +48,17 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper { ...@@ -37,9 +48,17 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
$sitemap->context = array('language' => 'fr'); $sitemap->context = array('language' => 'fr');
xmlsitemap_sitemap_save($sitemap); xmlsitemap_sitemap_save($sitemap);
} }
} }
/**
* I18n Test.
*/
class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase { class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
/**
* Get Info.
*/
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'XML sitemap i18n tests', 'name' => 'XML sitemap i18n tests',
...@@ -49,7 +68,10 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase { ...@@ -49,7 +68,10 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
); );
} }
function testLanguageSelection() { /**
* Language Selection.
*/
public function testLanguageSelection() {
// Create our three different language nodes. // Create our three different language nodes.
$node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE)); $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
$node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en')); $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
...@@ -104,9 +126,17 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase { ...@@ -104,9 +126,17 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
$this->assertRawSitemapLinks($node_fr, $link, $link_fr); $this->assertRawSitemapLinks($node_fr, $link, $link_fr);
$this->assertNoRawSitemapLinks($node, $node_en, $link_en); $this->assertNoRawSitemapLinks($node, $node_en, $link_en);
} }
} }
/**
* Node Test.
*/
class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase { class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
/**
* Get Info.
*/
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'XML sitemap i18n node tests', 'name' => 'XML sitemap i18n node tests',
...@@ -116,7 +146,10 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase { ...@@ -116,7 +146,10 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
); );
} }
function setUp($modules = array()) { /**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_node'; $modules[] = 'xmlsitemap_node';
parent::setUp($modules); parent::setUp($modules);
...@@ -125,7 +158,10 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase { ...@@ -125,7 +158,10 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
} }
function testNodeLanguageData() { /**
* Node Language Data.
*/
public function testNodeLanguageData() {
$node = $this->drupalCreateNode(array()); $node = $this->drupalCreateNode(array());
$this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save')); $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
...@@ -136,4 +172,5 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase { ...@@ -136,4 +172,5 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
$link = $this->assertSitemapLink('node', $node->nid); $link = $this->assertSitemapLink('node', $node->nid);
$this->assertIdentical($link['language'], 'fr'); $this->assertIdentical($link['language'], 'fr');
} }
} }
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