Projet

Général

Profil

Paste
Télécharger (3,41 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_sync / i18n_sync.test @ 76df55b7

1
<?php
2
/**
3
 * @file
4
 * Test field synchronization
5
 */
6

    
7
class i18nSyncTestCase extends Drupali18nTestCase {
8

    
9
  public static function getInfo() {
10
    return array(
11
      'name' => 'Synchronize translations',
12
      'group' => 'Internationalization',
13
      'description' => 'Internationalization Content Synchronization'
14
    );
15
  }
16

    
17
  function setUp() {
18
    parent::setUp('translation', 'i18n_string', 'i18n_sync', 'i18n_node', 'i18n_taxonomy');
19
    parent::setUpLanguages();
20
    parent::setUpContentTranslation();
21
  }
22

    
23
  function testIi18nSync() {
24
    drupal_static_reset('language_list');
25
    $language_list = language_list();
26
    $language_count = count($language_list);
27

    
28
    // Enable tags field for page content type.
29
    $edit = array(
30
      'fields[_add_existing_field][label]' => t('Tags'),
31
      'fields[_add_existing_field][field_name]' => 'field_tags',
32
      'fields[_add_existing_field][widget_type]' => 'taxonomy_autocomplete',
33
    );
34
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
35
    $this->drupalPost(NULL, array(), t('Save settings'));
36

    
37
    // Create some content and check selection modes
38
    $this->drupalLogin($this->content_editor);
39

    
40
    // variable_set('language_content_type_story', 1);
41
    $source = $this->createNode('page', $this->randomName(), $this->randomString(20), language_default('language'), array('field_tags[und]' => $tag_name = $this->randomName()));
42
    $this->drupalGet('node/' . $source->nid . '/translate');
43
    $translations = $this->createNodeTranslationSet($source);
44

    
45
    drupal_static_reset('translation_node_get_translations');
46
    $this->assertEqual(count(translation_node_get_translations($source->tnid)), $language_count, "Created $language_count $source->type translations.");
47

    
48
    // Set up fields for synchronization: promoted, field_tags
49
    $this->drupalLogin($this->admin_user);
50
    $edit = array(
51
      'i18n_sync_node_type[sticky]' => 1,
52
      'i18n_sync_node_type[promote]' => 1,
53
      'i18n_sync_node_type[field_tags]' => 1,
54
    );
55
    $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
56
    $this->drupalGet('admin/structure/types/manage/page');
57
    // Update source fields and check translations have been updated.
58
    $new_title = $this->randomName();
59
    $new_tag = $this->randomName();
60
    $edit = array(
61
      'promote' => 1,
62
      'sticky' => 1,
63
      'field_tags[und]' => $new_tag,
64
    );
65
    $this->drupalPost('node/' . $source->nid . '/edit', $edit, t('Save'));
66
    $terms = taxonomy_get_term_by_name($new_tag);
67
    $term = reset($terms);
68
    // Refresh cache and load translations again.
69
    drupal_static_reset('translation_node_get_translations');
70

    
71
    // For some reason the field cache for the node translation gets outdated values.
72
    // This only happens when running unit tests.
73
    // If we don't do this, we miss the field_tags value for the second node.
74
    field_cache_clear();
75

    
76
    $translations = translation_node_get_translations($source->tnid);
77
    foreach ($translations as $lang => $node) {
78
      $node = node_load($node->nid, NULL, TRUE);
79
      $this->assertTrue($node->promote && $node->sticky, "Translation for language $lang has been promoted an made sticky.");
80
      $this->assertEqual($node->field_tags['und'][0]['tid'], $term->tid, "Tag for translation $lang has been properly updated.");
81
      $this->drupalGet('node/' . $node->nid);
82
      $this->assertRaw($new_tag, "New tag for translation $lang is showing up.");
83
    }
84
  }
85
}