tmgmt_entity.source.none.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Entity source LANGUAGE_NONE tests.
  4. *
  5. * Splitted into a separate test because of https://www.drupal.org/node/2675230.
  6. */
  7. class TMGMTEntitySourceLanguageNoneTestCase extends TMGMTEntityTestCaseUtility {
  8. public $vocabulary;
  9. static function getInfo() {
  10. return array(
  11. 'name' => 'Entity Source Neutral tests',
  12. 'description' => 'Tests that LANGUAGE_NONE entities can not be translated',
  13. 'group' => 'Translation Management',
  14. 'dependencies' => array('entity_translation'),
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp(array('tmgmt_entity', 'taxonomy', 'entity_translation'));
  19. // Admin user to perform settings on setup.
  20. $this->loginAsAdmin(array('administer entity translation'));
  21. $this->vocabulary = $this->createTaxonomyVocab(strtolower($this->randomName()), $this->randomName(), array(FALSE, TRUE, TRUE, TRUE));
  22. // Enable entity translations for taxonomy.
  23. $edit['entity_translation_entity_types[taxonomy_term]'] = 1;
  24. $this->drupalPost('admin/config/regional/entity_translation', $edit, t('Save configuration'));
  25. }
  26. /**
  27. * Test if language neutral entities are not allowed for translation.
  28. *
  29. * That behaviour is described in the entity_translation documentation:
  30. * https://www.drupal.org/node/1280934
  31. */
  32. function testLanguageNeutral() {
  33. $this->setEnvironment('de');
  34. // Structure: array({entity-type} => array({source-langcode} => {entity}))
  35. $test_data = array();
  36. $this->createNodeType('article', 'Article', ENTITY_TRANSLATION_ENABLED);
  37. $test_data['node'][LANGUAGE_NONE] = $this->createNode('article', LANGUAGE_NONE);
  38. $test_data['node']['en'] = $this->createNode('article', 'en');
  39. $test_data['node']['de'] = $this->createNode('article', 'de');
  40. $test_data['taxonomy_term'][LANGUAGE_NONE] = $this->createTaxonomyTerm($this->vocabulary, LANGUAGE_NONE);
  41. $test_data['taxonomy_term']['en'] = $this->createTaxonomyTerm($this->vocabulary, 'en');
  42. $test_data['taxonomy_term']['de'] = $this->createTaxonomyTerm($this->vocabulary, 'de');
  43. // Test if tmgmt_entity_get_translatable_entities() function excludes
  44. // language neutral entities.
  45. foreach ($test_data as $entity_type => $entities) {
  46. $translatable_entities = tmgmt_entity_get_translatable_entities($entity_type);
  47. foreach ($entities as $langcode => $entity) {
  48. list($id, , ) = entity_extract_ids($entity_type, $entity);
  49. if ($langcode == LANGUAGE_NONE) {
  50. $this->assert(!isset($translatable_entities[$id]), "Language neutral $entity_type entity does not exist in the translatable entities list.");
  51. }
  52. else {
  53. $this->assert(isset($translatable_entities[$id]), "$langcode $entity_type entity exists in the translatable entities list.");
  54. }
  55. }
  56. }
  57. // Test if language neutral entities can't be added to a translation job.
  58. $job = $this->createJob();
  59. $job->translator = $this->default_translator->name;
  60. $job->settings = array();
  61. $job->save();
  62. foreach ($test_data as $entity_type => $entities) {
  63. foreach ($entities as $langcode => $entity) {
  64. list($id, , ) = entity_extract_ids($entity_type, $entity);
  65. try {
  66. $job->addItem('entity', $entity_type, $id);
  67. if ($langcode == LANGUAGE_NONE) {
  68. $this->fail("Adding of language neutral $entity_type entity to a translation job did not fail.");
  69. }
  70. else {
  71. $this->pass("Adding of $langcode $entity_type entity node to a translation job did not fail.");
  72. }
  73. }
  74. catch (TMGMTException $e) {
  75. if ($langcode == LANGUAGE_NONE) {
  76. $this->pass("Adding of language neutral $entity_type entity to a translation job did fail.");
  77. }
  78. else {
  79. $this->fail("Adding of $langcode $entity_type entity node to a translation job did fail.");
  80. }
  81. }
  82. }
  83. }
  84. $GLOBALS['TMGMT_DEBUG'] = FALSE;
  85. }
  86. }