i18n_sync.test 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @file
  4. * Test field synchronization
  5. */
  6. class i18nSyncTestCase extends Drupali18nTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Synchronize translations',
  10. 'group' => 'Internationalization',
  11. 'description' => 'Internationalization Content Synchronization'
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('translation', 'i18n_string', 'i18n_sync', 'i18n_node', 'i18n_taxonomy');
  16. parent::setUpLanguages();
  17. parent::setUpContentTranslation();
  18. }
  19. function testIi18nSync() {
  20. drupal_static_reset('language_list');
  21. $language_list = language_list();
  22. $language_count = count($language_list);
  23. // Enable tags field for page content type.
  24. $edit = array(
  25. 'fields[_add_existing_field][label]' => t('Tags'),
  26. 'fields[_add_existing_field][field_name]' => 'field_tags',
  27. 'fields[_add_existing_field][widget_type]' => 'taxonomy_autocomplete',
  28. );
  29. $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  30. $this->drupalPost(NULL, array(), t('Save settings'));
  31. // Create some content and check selection modes
  32. $this->drupalLogin($this->content_editor);
  33. // variable_set('language_content_type_story', 1);
  34. $source = $this->createNode('page', $this->randomName(), $this->randomString(20), language_default('language'), array('field_tags[und]' => $tag_name = $this->randomName()));
  35. $this->drupalGet('node/' . $source->nid . '/translate');
  36. $translations = $this->createNodeTranslationSet($source);
  37. drupal_static_reset('translation_node_get_translations');
  38. $this->assertEqual(count(translation_node_get_translations($source->tnid)), $language_count, "Created $language_count $source->type translations.");
  39. // Set up fields for synchronization: promoted, field_tags
  40. $this->drupalLogin($this->admin_user);
  41. $edit = array(
  42. 'i18n_sync_node_type[sticky]' => 1,
  43. 'i18n_sync_node_type[promote]' => 1,
  44. 'i18n_sync_node_type[field_tags]' => 1,
  45. );
  46. $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  47. $this->drupalGet('admin/structure/types/manage/page');
  48. // Update source fields and check translations have been updated.
  49. $new_title = $this->randomName();
  50. $new_tag = $this->randomName();
  51. $edit = array(
  52. 'promote' => 1,
  53. 'sticky' => 1,
  54. 'field_tags[und]' => $new_tag,
  55. );
  56. $this->drupalPost('node/' . $source->nid . '/edit', $edit, t('Save'));
  57. $terms = taxonomy_get_term_by_name($new_tag);
  58. $term = reset($terms);
  59. // Refresh cache and load translations again.
  60. drupal_static_reset('translation_node_get_translations');
  61. // For some reason the field cache for the node translation gets outdated values.
  62. // This only happens when running unit tests.
  63. // If we don't do this, we miss the field_tags value for the second node.
  64. field_cache_clear();
  65. $translations = translation_node_get_translations($source->tnid);
  66. foreach ($translations as $lang => $node) {
  67. $node = node_load($node->nid, NULL, TRUE);
  68. $this->assertTrue($node->promote && $node->sticky, "Translation for language $lang has been promoted an made sticky.");
  69. $this->assertEqual($node->field_tags['und'][0]['tid'], $term->tid, "Tag for translation $lang has been properly updated.");
  70. $this->drupalGet('node/' . $node->nid);
  71. $this->assertRaw($new_tag, "New tag for translation $lang is showing up.");
  72. }
  73. }
  74. }