/[drupal]/drupal/modules/translation/translation.test
ViewVC logotype

Contents of /drupal/modules/translation/translation.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.20 - (show annotations) (download) (as text)
Fri Oct 16 02:04:44 2009 UTC (5 weeks, 6 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.19: +8 -8 lines
File MIME type: text/x-php
#565480 by plach and peximo: TF #2: Multilingual field handling. Integration between field API and locale module + translatable node bodies.
1 <?php
2 // $Id: translation.test,v 1.19 2009/10/11 03:07:21 webchick Exp $
3
4 class TranslationTestCase extends DrupalWebTestCase {
5 protected $book;
6
7 public static function getInfo() {
8 return array(
9 'name' => 'Translation functionality',
10 'description' => 'Create a page with translation, modify the page outdating translation, and update translation.',
11 'group' => 'Translation'
12 );
13 }
14
15 function setUp() {
16 parent::setUp('locale', 'translation');
17 }
18
19 /**
20 * Create a page with translation, modify the page outdating translation, and update translation.
21 */
22 function testContentTranslation() {
23 // Setup users.
24 $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
25 $translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content'));
26
27 $this->drupalLogin($admin_user);
28
29 // Add languages.
30 $this->addLanguage('en');
31 $this->addLanguage('es');
32
33 // Set page content type to use multilingual support with translation.
34 $this->drupalGet('admin/structure/types/manage/page');
35 $edit = array();
36 $edit['language_content_type'] = 2;
37 $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
38 $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Page')), t('Page content type has been updated.'));
39
40 $this->drupalLogout();
41 $this->drupalLogin($translator);
42
43 // Create page in English.
44 $node_title = $this->randomName();
45 $node_body = $this->randomName();
46 $node = $this->createPage($node_title, $node_body, 'en');
47
48 // Submit translation in Spanish.
49 $node_translation_title = $this->randomName();
50 $node_translation_body = $this->randomName();
51 $node_translation = $this->createTranslation($node->nid, $node_translation_title, $node_translation_body, 'es');
52
53 // Attempt to submit a duplicate translation by visiting the node/add page
54 // with identical query string.
55 $languages = language_list();
56 $this->drupalGet('node/add/page', array('query' => array('translation' => $node->nid, 'language' => 'es')));
57 $this->assertRaw(t('A translation of %title in %language already exists', array('%title' => $node_title, '%language' => $languages['es']->name)), t('Message regarding attempted duplicate translation is displayed.'));
58
59 // Attempt a resubmission of the form - this emulates using the back button
60 // to return to the page then resubmitting the form without a refresh.
61 $edit = array();
62 $langcode = FIELD_LANGUAGE_NONE;
63 $edit["title[$langcode][0][value]"] = $this->randomName();
64 $edit["body[$langcode][0][value]"] = $this->randomName();
65 $this->drupalPost('node/add/page', $edit, t('Save'), array('query' => array('translation' => $node->nid, 'language' => 'es')));
66 $duplicate = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
67 $this->assertEqual($duplicate->tnid, 0, t('The node does not have a tnid.'));
68
69 // Update original and mark translation as outdated.
70 $edit = array();
71 $edit["body[$node->language][0][value]"] = $this->randomName();
72 $edit['translation[retranslate]'] = TRUE;
73 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
74 $this->assertRaw(t('Page %title has been updated.', array('%title' => $node_title)), t('Original node updated.'));
75
76 // Check to make sure that interface shows translation as outdated
77 $this->drupalGet('node/' . $node->nid . '/translate');
78 $this->assertRaw('<span class="marker">' . t('outdated') . '</span>', t('Translation marked as outdated.'));
79
80 // Update translation and mark as updated.
81 $edit = array();
82 $edit["body[$node_translation->language][0][value]"] = $this->randomName();
83 $edit['translation[status]'] = FALSE;
84 $this->drupalPost('node/' . $node_translation->nid . '/edit', $edit, t('Save'));
85 $this->assertRaw(t('Page %title has been updated.', array('%title' => $node_translation_title)), t('Translated node updated.'));
86 }
87
88 /**
89 * Install a the specified language if it has not been already. Otherwise make sure that
90 * the language is enabled.
91 *
92 * @param string $language_code The language code the check.
93 */
94 function addLanguage($language_code) {
95 // Check to make sure that language has not already been installed.
96 $this->drupalGet('admin/config/regional/language');
97
98 if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {
99 // Doesn't have language installed so add it.
100 $edit = array();
101 $edit['langcode'] = $language_code;
102 $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
103
104 // Make sure we're not using a stale list.
105 drupal_static_reset('language_list');
106 $languages = language_list('language');
107 $this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
108
109 if (array_key_exists($language_code, $languages)) {
110 $this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), t('Language has been created.'));
111 }
112 }
113 else {
114 // Ensure that it is enabled.
115 $this->assertTrue(true, 'Language [' . $language_code . '] already installed.');
116 $this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
117
118 $this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
119 }
120 }
121
122 /**
123 * Create a page in the specified language.
124 *
125 * @param string $title Title of page in specified language.
126 * @param string $body Body of page in specified language.
127 * @param string $language Language code.
128 */
129 function createPage($title, $body, $language) {
130 $edit = array();
131 $langcode = FIELD_LANGUAGE_NONE;
132 $edit["title[$langcode][0][value]"] = $title;
133 $edit["body[$langcode][0][value]"] = $body;
134 $edit['language'] = $language;
135 $this->drupalPost('node/add/page', $edit, t('Save'));
136 $this->assertRaw(t('Page %title has been created.', array('%title' => $title)), t('Page created.'));
137
138 // Check to make sure the node was created.
139 $node = $this->drupalGetNodeByTitle($title);
140 $this->assertTrue($node, t('Node found in database.'));
141
142 return $node;
143 }
144
145 /**
146 * Create a translation for the specified page in the specified language.
147 *
148 * @param integer $nid Node id of page to create translation for.
149 * @param string $title Title of page in specified language.
150 * @param string $body Body of page in specified language.
151 * @param string $language Language code.
152 */
153 function createTranslation($nid, $title, $body, $language) {
154 $this->drupalGet('node/add/page', array('query' => array('translation' => $nid, 'language' => $language)));
155
156 $edit = array();
157 $langcode = FIELD_LANGUAGE_NONE;
158 $edit["title[$langcode][0][value]"] = $title;
159 $edit["body[$language][0][value]"] = $body;
160 $this->drupalPost(NULL, $edit, t('Save'));
161 $this->assertRaw(t('Page %title has been created.', array('%title' => $title)), t('Translation created.'));
162
163 // Check to make sure that translation was successful.
164 $node = $this->drupalGetNodeByTitle($title);
165 $this->assertTrue($node, t('Node found in database.'));
166
167 return $node;
168 }
169 }

  ViewVC Help
Powered by ViewVC 1.1.2