i18n_node.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Contains test cases for the i18n_node module.
  5. */
  6. class I18nNodeTestCase extends Drupali18nTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Content translation',
  10. 'group' => 'Internationalization',
  11. 'description' => 'Content translation functions',
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('translation', 'i18n_node');
  16. parent::setUpLanguages(array('administer content translations', 'translate content'));
  17. parent::setUpContentTranslation();
  18. $this->addLanguage('pt-br');
  19. // Add a disabled language.
  20. $this->addLanguage('it');
  21. $edit = array('enabled[it]' => FALSE);
  22. $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
  23. }
  24. /**
  25. * Tests for adding content to an existing translation set.
  26. */
  27. function testAddContentToTranslationSet() {
  28. module_load_include('inc', 'i18n_node', 'i18n_node.pages');
  29. // Create 3 nodes in different languages.
  30. $en_title = $this->randomName(10);
  31. $en_body = $this->randomString(50);
  32. $en_node = $this->createNode('page', $en_title, $en_body, 'en');
  33. $es_title = $this->randomName(10);
  34. $es_body = $this->randomString(50);
  35. $es_node = $this->createNode('page', $es_title, $es_body, 'es');
  36. $ptbr_title = $this->randomName(10);
  37. $ptbr_body = $this->randomString(50);
  38. $ptbr_node = $this->createNode('page', $ptbr_title, $ptbr_body, 'pt-br');
  39. // Check the autocomplete suggestions.
  40. $this->drupalGet('i18n/node/autocomplete/page/es/' . substr($es_title, 0, 3));
  41. $this->assertText($es_title);
  42. $this->assertNoText($en_title);
  43. $this->assertNoText($ptbr_title);
  44. $this->drupalGet('i18n/node/autocomplete/page/es/' . substr($en_title, 0, 3));
  45. $this->assertNoText($es_title);
  46. $this->assertNoText($en_title);
  47. $this->assertNoText($ptbr_title);
  48. $this->drupalGet('i18n/node/autocomplete/page/pt-br/' . substr($ptbr_title, 0, 3));
  49. $this->assertNoText($es_title);
  50. $this->assertNoText($en_title);
  51. $this->assertText($ptbr_title);
  52. // Go to the translations tab.
  53. $this->drupalGet('node/' . $en_node->nid);
  54. $this->clickLink(t('Translate'));
  55. // Make sure that the disabled language doesn't show up.
  56. $this->assertNoText(t('Italian'));
  57. // Test validation.
  58. $edit = array(
  59. 'translations[node][es]' => $ptbr_title,
  60. );
  61. $this->drupalPost(NULL, $edit, t('Update translations'));
  62. $this->assertText(t('Found no valid post with that title: @title', array('@title' => $ptbr_title)));
  63. // Add two translated nodes.
  64. $edit = array(
  65. 'translations[node][pt-br]' => $ptbr_title,
  66. 'translations[node][es]' => $es_title,
  67. );
  68. $this->drupalPost(NULL, $edit, t('Update translations'));
  69. $this->assertText(t('Added @count nodes to the translation set.', array('@count' => 2)));
  70. $this->assertFieldByName('translations[node][es]', i18n_node_nid2autocomplete($es_node->nid));
  71. $this->assertFieldByName('translations[node][pt-br]', i18n_node_nid2autocomplete($ptbr_node->nid));
  72. // Remove a translation node again.
  73. $edit = array(
  74. 'translations[node][pt-br]' => '',
  75. );
  76. $this->drupalPost(NULL, $edit, t('Update translations'));
  77. $this->assertText(t('Removed a node from the translation set.'));
  78. $this->assertFieldByName('translations[node][es]', i18n_node_nid2autocomplete($es_node->nid));
  79. $this->assertFieldByName('translations[node][pt-br]', '');
  80. }
  81. }