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