feeds_i18n_taxonomy.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @file
  4. * Contains Feedsi18nTaxonomyTestCase.
  5. */
  6. /**
  7. * Tests importing terms in a language.
  8. */
  9. class Feedsi18nTaxonomyTestCase extends Feedsi18nTestCase {
  10. /**
  11. * Name of created vocabulary.
  12. *
  13. * @var string
  14. */
  15. private $vocabulary;
  16. public static function getInfo() {
  17. return array(
  18. 'name' => 'Multilingual terms',
  19. 'description' => 'Tests Feeds multilingual support for taxonomy terms.',
  20. 'group' => 'Feeds',
  21. 'dependencies' => array('locale', 'i18n_taxonomy'),
  22. );
  23. }
  24. public function setUp($modules = array(), $permissions = array()) {
  25. $this->entityType = 'taxonomy_term';
  26. $this->processorName = 'FeedsTermProcessor';
  27. $modules = array_merge($modules, array(
  28. 'i18n_taxonomy',
  29. ));
  30. parent::setUp($modules, $permissions);
  31. // Create vocabulary.
  32. $this->vocabulary = strtolower($this->randomName(8));
  33. $edit = array(
  34. 'name' => $this->vocabulary,
  35. 'machine_name' => $this->vocabulary,
  36. );
  37. $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
  38. // Configure importer.
  39. $this->setSettings('i18n', $this->processorName, array(
  40. 'bundle' => $this->vocabulary,
  41. 'language' => 'de',
  42. 'update_existing' => FEEDS_UPDATE_EXISTING,
  43. 'skip_hash_check' => TRUE,
  44. ));
  45. $this->addMappings('i18n', array(
  46. 0 => array(
  47. 'source' => 'guid',
  48. 'target' => 'guid',
  49. 'unique' => '1',
  50. ),
  51. 1 => array(
  52. 'source' => 'title',
  53. 'target' => 'name',
  54. ),
  55. ));
  56. }
  57. /**
  58. * Tests if the language setting is available on the processor.
  59. */
  60. public function testAvailableProcessorLanguageSetting() {
  61. // Check if the language setting is available when the i18n_taxonomy module is enabled.
  62. $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsTermProcessor');
  63. $this->assertField('language', 'Language field is available on the term processor settings when the i18n_taxonomy module is enabled.');
  64. // Disable the i18n_taxonomy module and check if the language setting is no longer available.
  65. module_disable(array('i18n_taxonomy'));
  66. $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsTermProcessor');
  67. $this->assertNoField('language', 'Language field is not available on the term processor settings when the i18n_taxonomy module is disabled.');
  68. }
  69. /**
  70. * Tests if terms get imported in LANGUAGE_NONE when the i18n_taxonomy module gets disabled.
  71. */
  72. public function testDisabledi18nTaxonomyModule() {
  73. module_disable(array('i18n_taxonomy'));
  74. // Make sure that entity info is reset.
  75. drupal_flush_all_caches();
  76. drupal_static_reset();
  77. // Import content.
  78. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  79. // Assert that the terms have no language assigned.
  80. $entities = entity_load($this->entityType, array(1, 2));
  81. foreach ($entities as $entity) {
  82. // Terms shouldn't have a language property.
  83. $this->assertFalse(isset($entity->language), 'The term does not have a language.');
  84. }
  85. }
  86. /**
  87. * Tests if terms get imported in LANGUAGE_NONE when the i18n_taxonomy module gets uninstalled.
  88. */
  89. public function testUninstalledi18nTaxonomyModule() {
  90. module_disable(array('i18n_taxonomy'));
  91. drupal_uninstall_modules(array('i18n_taxonomy'));
  92. // Make sure that entity info is reset.
  93. drupal_flush_all_caches();
  94. drupal_static_reset();
  95. // Import content.
  96. $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
  97. // Assert that the terms have no language assigned.
  98. $entities = entity_load($this->entityType, array(1, 2));
  99. foreach ($entities as $entity) {
  100. $this->assertFalse(isset($entity->language), 'The term does not have a language.');
  101. }
  102. }
  103. }