1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Test case for multilingual fields.
|
5
|
*/
|
6
|
|
7
|
|
8
|
class i18nFieldTestCase extends Drupali18nTestCase {
|
9
|
|
10
|
public static function getInfo() {
|
11
|
return array(
|
12
|
'name' => 'Field translation',
|
13
|
'group' => 'Internationalization',
|
14
|
'description' => 'Field translation functions'
|
15
|
);
|
16
|
}
|
17
|
|
18
|
function setUp() {
|
19
|
parent::setUp('i18n_field', 'field_test');
|
20
|
parent::setUpLanguages(array('access field_test content', 'administer field_test content'));
|
21
|
$this->translator = $this->drupalCreateUser(array('translate interface', 'translate user-defined strings'));
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Test the translation of list fields, including allowed values.
|
26
|
*/
|
27
|
function testListFieldTranslation() {
|
28
|
$field_name = drupal_strtolower($this->randomName());
|
29
|
$label = $this->randomName();
|
30
|
$description = $this->randomName();
|
31
|
$value = $this->randomName();
|
32
|
|
33
|
$field = array(
|
34
|
'field_name' => $field_name,
|
35
|
'type' => 'list_integer',
|
36
|
'cardinality' => 1,
|
37
|
'settings' => array(
|
38
|
'allowed_values' => array(1 => $value),
|
39
|
),
|
40
|
);
|
41
|
$field = field_create_field($field);
|
42
|
|
43
|
$instance = array(
|
44
|
'field_name' => $field_name,
|
45
|
'entity_type' => 'test_entity',
|
46
|
'bundle' => 'test_bundle',
|
47
|
'label' => $label,
|
48
|
'description' => $description,
|
49
|
'widget' => array(
|
50
|
'type' => 'options_buttons',
|
51
|
),
|
52
|
);
|
53
|
$instance = field_create_instance($instance);
|
54
|
|
55
|
// Refresh i18n_strings.
|
56
|
$edit = array('groups[field]' => TRUE);
|
57
|
$this->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
|
58
|
|
59
|
// Save translations for each attribute.
|
60
|
$label_translation = $this->createStringTranslation('field', $label);
|
61
|
$description_translation = $this->createStringTranslation('field', $description);
|
62
|
$value_translation = $this->createStringTranslation('field', $value);
|
63
|
$this->drupalLogin($this->admin_user);
|
64
|
|
65
|
// Test untranslated values in default language.
|
66
|
$this->drupalGet('test-entity/add/test-bundle');
|
67
|
$this->assertText($label, 'Field label is not translated');
|
68
|
$this->assertText($description, 'Field description is not translated');
|
69
|
$this->assertText($value, 'Field allowed values are not translated');
|
70
|
|
71
|
// Test translated values in secondary language.
|
72
|
$this->drupalGet($this->secondary_language . '/test-entity/add/test-bundle');
|
73
|
$this->assertText($label_translation[$this->secondary_language], 'Field label is translated');
|
74
|
$this->assertText($description_translation[$this->secondary_language], 'Field description is translated');
|
75
|
$this->assertText($value_translation[$this->secondary_language], 'Field allowed values are translated');
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Test the translation of text fields, including default values.
|
80
|
*/
|
81
|
function testTextFieldTranslation() {
|
82
|
$field_name = drupal_strtolower($this->randomName());
|
83
|
$label = $this->randomName();
|
84
|
$description = $this->randomName();
|
85
|
$default_value = $this->randomName();
|
86
|
|
87
|
$field = array(
|
88
|
'field_name' => $field_name,
|
89
|
'type' => 'text',
|
90
|
'cardinality' => 1,
|
91
|
);
|
92
|
$field = field_create_field($field);
|
93
|
|
94
|
$instance = array(
|
95
|
'field_name' => $field_name,
|
96
|
'entity_type' => 'test_entity',
|
97
|
'bundle' => 'test_bundle',
|
98
|
'label' => $label,
|
99
|
'description' => $description,
|
100
|
'default_value' => array(0 => array('value' => $default_value)),
|
101
|
'widget' => array(
|
102
|
'type' => 'text_textfield',
|
103
|
),
|
104
|
);
|
105
|
$instance = field_create_instance($instance);
|
106
|
|
107
|
// Refresh i18n_strings.
|
108
|
$edit = array('groups[field]' => TRUE);
|
109
|
$this->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
|
110
|
|
111
|
// Save translations for each attribute.
|
112
|
$label_translation = $this->createStringTranslation('field', $label);
|
113
|
$description_translation = $this->createStringTranslation('field', $description);
|
114
|
$default_value_translation = $this->createStringTranslation('field', $default_value);
|
115
|
$this->drupalLogin($this->admin_user);
|
116
|
|
117
|
// Test untranslated values in default language.
|
118
|
$this->drupalGet('test-entity/add/test-bundle');
|
119
|
$this->assertText($label, 'Field label is not translated');
|
120
|
$this->assertText($description, 'Field description is not translated');
|
121
|
$this->assertRaw($default_value, 'Default value is not translated');
|
122
|
|
123
|
// Test translated values in secondary language.
|
124
|
$this->drupalGet($this->secondary_language . '/test-entity/add/test-bundle');
|
125
|
$this->assertText($label_translation[$this->secondary_language], 'Field label is translated');
|
126
|
$this->assertText($description_translation[$this->secondary_language], 'Field description is translated');
|
127
|
$this->assertRaw($default_value_translation[$this->secondary_language], 'Default value translated');
|
128
|
}
|
129
|
}
|