feeds_i18n_node.test 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @file
  4. * Contains Feedsi18nNodeTestCase.
  5. */
  6. /**
  7. * Tests importing nodes in a language.
  8. */
  9. class Feedsi18nNodeTestCase extends Feedsi18nTestCase {
  10. /**
  11. * Name of created content type.
  12. *
  13. * @var string
  14. */
  15. private $contentType;
  16. public static function getInfo() {
  17. return array(
  18. 'name' => 'Multilingual content',
  19. 'description' => 'Tests Feeds multilingual support for nodes.',
  20. 'group' => 'Feeds',
  21. 'dependencies' => array('locale'),
  22. );
  23. }
  24. public function setUp($modules = array(), $permissions = array()) {
  25. $this->entityType = 'node';
  26. $this->processorName = 'FeedsNodeProcessor';
  27. parent::setUp($modules, $permissions);
  28. // Create content type.
  29. $this->contentType = $this->createContentType();
  30. // Configure importer.
  31. $this->setSettings('i18n', $this->processorName, array(
  32. 'bundle' => $this->contentType,
  33. 'language' => 'de',
  34. 'update_existing' => FEEDS_UPDATE_EXISTING,
  35. 'skip_hash_check' => TRUE,
  36. ));
  37. $this->addMappings('i18n', array(
  38. 0 => array(
  39. 'source' => 'guid',
  40. 'target' => 'guid',
  41. 'unique' => '1',
  42. ),
  43. 1 => array(
  44. 'source' => 'title',
  45. 'target' => 'title',
  46. ),
  47. ));
  48. }
  49. /**
  50. * Tests if the language setting is available on the processor.
  51. */
  52. public function testAvailableProcessorLanguageSetting() {
  53. // Check if the language setting is available when the locale module is enabled.
  54. $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor');
  55. $this->assertField('language', 'Language field is available on the node processor settings when the locale module is enabled.');
  56. // Disable the locale module and check if the language setting is no longer available.
  57. module_disable(array('locale'));
  58. $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor');
  59. $this->assertNoField('language', 'Language field is not available on the node processor settings when the locale module is disabled.');
  60. }
  61. /**
  62. * Tests processor language setting in combination with language mapping target.
  63. */
  64. public function testWithLanguageMappingTarget() {
  65. $this->addMappings('i18n', array(
  66. 2 => array(
  67. 'source' => 'language',
  68. 'target' => 'language',
  69. ),
  70. ));
  71. // Import csv file. The first item has a language specified (Dutch), the second
  72. // one has no language specified and should be imported in the processor's language (German).
  73. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content_i18n.csv');
  74. // The first node should be Dutch.
  75. $node = node_load(1);
  76. $this->assertEqual('nl', entity_language('node', $node), 'Item 1 has the Dutch language assigned.');
  77. // The second node should be German.
  78. $node = node_load(2);
  79. $this->assertEqual('de', entity_language('node', $node), 'Item 2 has the German language assigned.');
  80. }
  81. /**
  82. * Tests if nodes get imported in LANGUAGE_NONE when the locale module gets disabled.
  83. */
  84. public function testDisabledLocaleModule() {
  85. module_disable(array('locale'));
  86. // Make sure that entity info is reset.
  87. drupal_flush_all_caches();
  88. drupal_static_reset();
  89. // Import content.
  90. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  91. // Assert that the content has no language assigned.
  92. for ($i = 1; $i <= 2; $i++) {
  93. $node = node_load($i);
  94. $language = entity_language('node', $node);
  95. $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language)));
  96. }
  97. }
  98. /**
  99. * Tests if nodes get imported in LANGUAGE_NONE when the locale module gets uninstalled.
  100. */
  101. public function testUninstalledLocaleModule() {
  102. module_disable(array('locale'));
  103. drupal_uninstall_modules(array('locale'));
  104. // Make sure that entity info is reset.
  105. drupal_flush_all_caches();
  106. drupal_static_reset();
  107. // Import content.
  108. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  109. // Assert that the content has no language assigned.
  110. for ($i = 1; $i <= 2; $i++) {
  111. $node = node_load($i);
  112. $language = entity_language('node', $node);
  113. $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language)));
  114. }
  115. }
  116. }