feeds_i18n.test 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @file
  4. * Contains Feedsi18nTestCase.
  5. */
  6. /**
  7. * Tests importing data in a language.
  8. */
  9. class Feedsi18nTestCase extends FeedsMapperTestCase {
  10. /**
  11. * The entity type to be tested.
  12. *
  13. * @var string
  14. */
  15. protected $entityType;
  16. /**
  17. * The processor being used.
  18. *
  19. * @var string
  20. */
  21. protected $processorName;
  22. public function setUp($modules = array(), $permissions = array()) {
  23. $modules = array_merge($modules, array(
  24. 'locale',
  25. ));
  26. $permissions = array_merge(array(
  27. 'administer languages',
  28. ));
  29. parent::setUp($modules, $permissions);
  30. // Setup other languages.
  31. $edit = array(
  32. 'langcode' => 'nl',
  33. );
  34. $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
  35. $this->assertText(t('The language Dutch has been created and can now be used.'));
  36. $edit = array(
  37. 'langcode' => 'de',
  38. );
  39. $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
  40. $this->assertText(t('The language German has been created and can now be used.'));
  41. // Include FeedsProcessor.inc to make its constants available.
  42. module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
  43. // Create and configure importer.
  44. $this->createImporterConfiguration('Multilingual term importer', 'i18n');
  45. $this->setPlugin('i18n', 'FeedsFileFetcher');
  46. $this->setPlugin('i18n', 'FeedsCSVParser');
  47. $this->setPlugin('i18n', $this->processorName);
  48. }
  49. /**
  50. * Tests if entities get the language assigned that is set in the processor.
  51. */
  52. public function testImport() {
  53. // Import content in German.
  54. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  55. // Assert that the entity's language is in German.
  56. $entities = entity_load($this->entityType, array(1, 2));
  57. foreach ($entities as $entity) {
  58. $this->assertEqual('de', entity_language($this->entityType, $entity));
  59. }
  60. }
  61. /**
  62. * Tests if entities get a different language assigned when the processor's language
  63. * is changed.
  64. */
  65. public function testChangedLanguageImport() {
  66. // Import content in German.
  67. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  68. // Change processor's language to Dutch.
  69. $this->setSettings('i18n', $this->processorName, array('language' => 'nl'));
  70. // Re-import content.
  71. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  72. // Assert that the entity's language is now in Dutch.
  73. $entities = entity_load($this->entityType, array(1, 2));
  74. foreach ($entities as $entity) {
  75. $this->assertEqual('nl', entity_language($this->entityType, $entity));
  76. }
  77. }
  78. /**
  79. * Tests if items are imported in LANGUAGE_NONE if the processor's language is disabled.
  80. */
  81. public function testDisabledLanguage() {
  82. // Disable the German language.
  83. $path = 'admin/config/regional/language';
  84. $edit = array(
  85. 'enabled[de]' => FALSE,
  86. );
  87. $this->drupalPost($path, $edit, t('Save configuration'));
  88. // Import content.
  89. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  90. // Assert that the entities have no language assigned.
  91. $entities = entity_load($this->entityType, array(1, 2));
  92. foreach ($entities as $entity) {
  93. $language = entity_language($this->entityType, $entity);
  94. $this->assertEqual(LANGUAGE_NONE, $language, format_string('The entity is language neutral (actual: !language).', array('!language' => $language)));
  95. }
  96. }
  97. /**
  98. * Tests if items are imported in LANGUAGE_NONE if the processor's language is removed.
  99. */
  100. public function testRemovedLanguage() {
  101. // Remove the German language.
  102. $path = 'admin/config/regional/language/delete/de';
  103. $this->drupalPost($path, array(), t('Delete'));
  104. // Import content.
  105. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  106. // Assert that the entities have no language assigned.
  107. $entities = entity_load($this->entityType, array(1, 2));
  108. foreach ($entities as $entity) {
  109. $language = entity_language($this->entityType, $entity);
  110. $this->assertEqual(LANGUAGE_NONE, $language, format_string('The entity is language neutral (actual: !language).', array('!language' => $language)));
  111. }
  112. }
  113. }