diff --git a/feeds.info b/feeds.info index 11934e0..6cd1698 100644 --- a/feeds.info +++ b/feeds.info @@ -46,6 +46,7 @@ files[] = tests/feeds_mapper_config.test files[] = tests/feeds_fetcher_file.test files[] = tests/feeds_mapper_format_config.test files[] = tests/feeds_fetcher_http.test +files[] = tests/feeds_i18n.test files[] = tests/feeds_parser_sitemap.test files[] = tests/feeds_parser_syndication.test files[] = tests/feeds_processor_node.test diff --git a/tests/feeds/content_i18n.csv b/tests/feeds/content_i18n.csv new file mode 100644 index 0000000..1309358 --- /dev/null +++ b/tests/feeds/content_i18n.csv @@ -0,0 +1,3 @@ +"guid","title","created","alpha","beta","gamma","delta","body","language" +1,"Lorem ipsum",1251936720,"Lorem",42,"4.2",3.14159265,"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.","nl" +2,"Ut wisi enim ad minim veniam",1251932360,"Ut wisi",32,"1.2",5.62951413,"Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat." diff --git a/tests/feeds_i18n.test b/tests/feeds_i18n.test new file mode 100644 index 0000000..7a8d029 --- /dev/null +++ b/tests/feeds_i18n.test @@ -0,0 +1,227 @@ + 'Multilingual content', + 'description' => 'Tests Feeds multilingual support.', + 'group' => 'Feeds', + 'dependencies' => array('locale'), + ); + } + + public function setUp() { + $modules = array( + 'locale', + ); + $permissions = array( + 'administer languages', + ); + parent::setUp($modules, $permissions); + + // Setup other languages. + $edit = array( + 'langcode' => 'nl', + ); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + $this->assertText(t('The language Dutch has been created and can now be used.')); + $edit = array( + 'langcode' => 'de', + ); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + $this->assertText(t('The language German has been created and can now be used.')); + + // Create content type. + $this->contentType = $this->createContentType(); + + // Include FeedsProcessor.inc to make its constants available. + module_load_include('inc', 'feeds', 'plugins/FeedsProcessor'); + + // Create and configure importer. + $this->createImporterConfiguration('Multilingual importer', 'i18n'); + $this->setPlugin('i18n', 'FeedsFileFetcher'); + $this->setPlugin('i18n', 'FeedsCSVParser'); + $this->setSettings('i18n', 'FeedsNodeProcessor', array( + 'bundle' => $this->contentType, + 'language' => 'de', + 'update_existing' => FEEDS_UPDATE_EXISTING, + 'skip_hash_check' => TRUE + )); + $this->addMappings('i18n', array( + 0 => array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => '1', + ), + 1 => array( + 'source' => 'title', + 'target' => 'title', + ), + )); + } + + /** + * Tests if the language setting is available on the processor. + */ + public function testAvailableProcessorLanguageSetting() { + // Check if the language setting is available when the locale module is enabled. + $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor'); + $this->assertField('language', 'Language field is available on the node processor settings when locale module is enabled.'); + + // Disable the locale module and check if the language setting is no longer available. + module_disable(array('locale')); + $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor'); + $this->assertNoField('language', 'Language field is not available on the node processor settings when locale module is disabled.'); + } + + /** + * Tests if nodes get the language assigned that is set in the processor. + */ + public function testImport() { + // Import content in German. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Assert that the content's language is in German. + for ($i = 1; $i <= 2; $i++) { + $node = node_load($i); + $this->assertEqual('de', entity_language('node', $node)); + } + } + + /** + * Tests if nodes get a different language assigned when the processor's language + * is changed. + */ + public function testChangedLanguageImport() { + // Import content in German. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Change processor's language to Dutch. + $this->setSettings('i18n', 'FeedsNodeProcessor', array('language' => 'nl')); + + // Re-import content. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Assert that the content's language is now in Dutch. + for ($i = 1; $i <= 2; $i++) { + $node = node_load($i); + $this->assertEqual('nl', entity_language('node', $node)); + } + } + + /** + * Tests processor language setting in combination with language mapping target. + */ + public function testWithLanguageMappingTarget() { + $this->addMappings('i18n', array( + 2 => array( + 'source' => 'language', + 'target' => 'language', + ), + )); + + // Import csv file. The first item has a language specified (Dutch), the second + // one has no language specified and should be imported in the processor's language (German). + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content_i18n.csv'); + + // The first node should be Dutch. + $node = node_load(1); + $this->assertEqual('nl', entity_language('node', $node), 'Item 1 has the Dutch language assigned.'); + + // The second node should be German. + $node = node_load(2); + $this->assertEqual('de', entity_language('node', $node), 'Item 2 has the German language assigned.'); + } + + /** + * Tests if nodes get imported in LANGUAGE_NONE when the locale module gets disabled. + */ + public function testDisabledLocaleModule() { + module_disable(array('locale')); + + // Import content. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Assert that the content has no language assigned. + for ($i = 1; $i <= 2; $i++) { + $node = node_load($i); + $language = entity_language('node', $node); + $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language))); + } + } + + /** + * Tests if nodes get imported in LANGUAGE_NONE when the locale module gets uninstalled. + */ + public function testUninstalledLocaleModule() { + module_disable(array('locale')); + drupal_uninstall_modules(array('locale')); + + // Import content. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Assert that the content has no language assigned. + for ($i = 1; $i <= 2; $i++) { + $node = node_load($i); + $language = entity_language('node', $node); + $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language))); + } + } + + /** + * Tests if items are imported in LANGUAGE_NONE if the processor's language is disabled. + */ + public function testDisabledLanguage() { + // Disable the German language. + $path = 'admin/config/regional/language'; + $edit = array( + 'enabled[de]' => FALSE, + ); + $this->drupalPost($path, $edit, t('Save configuration')); + + // Import content. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Assert that the content has no language assigned. + for ($i = 1; $i <= 2; $i++) { + $node = node_load($i); + $language = entity_language('node', $node); + $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language))); + } + } + + /** + * Tests if items are imported in LANGUAGE_NONE if the processor's language is removed. + */ + public function testRemovedLanguage() { + // Remove the German language. + $path = 'admin/config/regional/language/delete/de'; + $this->drupalPost($path, array(), t('Delete')); + + // Import content. + $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Assert that the content has no language assigned. + for ($i = 1; $i <= 2; $i++) { + $node = node_load($i); + $language = entity_language('node', $node); + $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language))); + } + } +}