Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: locale.test,v 1.9 2008/04/01 23:33:54 boombatower Exp $
|
3 | |
|
4 | | class LocaleTestCase extends DrupalTestCase {
|
5 | | /**
|
6 | | * Implementation of getInfo() for information
|
7 | | */
|
8 | | function getInfo() {
|
9 | | return array(
|
10 | 1 | 'name' => t('String translate'),
|
11 | | 'description' => 'Adds a new locale and translates its name',
|
12 | | 'group' => 'Locale',
|
13 | | );
|
14 | | }
|
15 | |
|
16 | | function setUp() {
|
17 | | parent::setUp();
|
18 | |
|
19 | | $this->drupalModuleEnable('locale');
|
20 | | }
|
21 | |
|
22 | | function testlocaleModuleTest() {
|
23 | | global $base_url;
|
24 | |
|
25 | | // User to add and remove language.
|
26 | | $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
27 | | // User to translate and delete string.
|
28 | | $translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
|
29 | | // Code for the language.
|
30 | | $langcode = str_replace('simpletest_', 'si-', $this->randomName(6));
|
31 | | // The English name for the language. This will be translated.
|
32 | | $name = $this->randomName(16);
|
33 | | // The native name for the language.
|
34 | | $native = $this->randomName(16);
|
35 | | // The domain prefix. Not tested yet.
|
36 | | $prefix = strtolower(str_replace('si-', '', $langcode));
|
37 | | // This is the language indicator on the translation search screen for
|
38 | | // untranslated strings. Copied straight from locale.inc.
|
39 | | $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
|
40 | | // This will be the translation of $name.
|
41 | | $translation = $this->randomName(16);
|
42 | |
|
43 | | // Add language.
|
44 | | $this->drupalLogin($admin_user);
|
45 | | $edit = array (
|
46 | | 'langcode' => $langcode,
|
47 | | 'name' => $name,
|
48 | | 'native' => $native,
|
49 | | 'prefix' => $prefix,
|
50 | | 'direction' => '0',
|
51 | | );
|
52 | | $this->drupalPost('admin/settings/language/add', $edit, t('Add custom language'));
|
53 | | // Add string.
|
54 | | t($name, array(), $langcode);
|
55 | | // Reset locale cache.
|
56 | | locale(NULL, NULL, TRUE);
|
57 | | $this->assertText($langcode, 'Language code found');
|
58 | | $this->assertText($name, 'Name found');
|
59 | | $this->assertText($native, 'Native found');
|
60 | | // No t() here, we do not want to add this string to the database and it's
|
61 | | // surely not translated yet.
|
62 | | $this->assertText($native, 'Test language added');
|
63 | | $this->drupalGet('logout');
|
64 | |
|
65 | | // Search for the name and translate it.
|
66 | | $this->drupalLogin($translate_user);
|
67 | | $search = array (
|
68 | | 'string' => $name,
|
69 | | 'language' => 'all',
|
70 | | 'translation' => 'all',
|
71 | | 'group' => 'all',
|
72 | | );
|
73 | | $this->drupalPost('admin/build/translate/search', $search, t('Search'));
|
74 | | // assertText seems to remove the input field where $name always could be
|
75 | | // found, so this is not a false assert. See how assertNoText succeeds
|
76 | | // later.
|
77 | | $this->assertText($name, 'Search found the name');
|
78 | | $this->assertRaw($language_indicator, 'Name is untranslated');
|
79 | | // It's presumed that this is the only result. Given the random name, it's
|
80 | | // reasonable.
|
81 | | $this->clickLink(t('edit'));
|
82 | | // We save the lid from the path.
|
83 | | $lid = preg_replace('/\D/', '', substr($this->getUrl(), strlen($base_url)));
|
84 | | // No t() here, it's surely not translated yet.
|
85 | | $this->assertText($name, 'name found on edit screen');
|
86 | | $edit = array (
|
87 | | "translations[$langcode]" => $translation,
|
88 | | );
|
89 | | $this->drupalPost(NULL, $edit, t('Save translations'));
|
90 | | $this->assertText(t('The string has been saved.'), 'The string has been saved.');
|
91 | | $this->assertTrue($name != $translation && t($name, array(), $langcode) == $translation, 't() works');
|
92 | | $this->drupalPost('admin/build/translate/search', $search, t('Search'));
|
93 | | // The indicator should not be here.
|
94 | | $this->assertNoRaw($language_indicator, 'String is translated');
|
95 | | $this->drupalGet('logout');
|
96 | |
|
97 | | // Delete the language
|
98 | | $this->drupalLogin($admin_user);
|
99 | | $path = 'admin/settings/language/delete/'. $langcode;
|
100 | | // This a confirm form, we do not need any fields changed.
|
101 | | $this->drupalPost($path, array(), t('Delete'));
|
102 | | // We need raw here because %locale will add HTML.
|
103 | | $this->assertRaw(t('The language %locale has been removed.', array('%locale' => $name)), 'The test language has been removed.');
|
104 | | // Reload to remove $name.
|
105 | | $this->drupalGet($path);
|
106 | | $this->assertNoText($langcode, 'Language code not found');
|
107 | | $this->assertNoText($name, 'Name not found');
|
108 | | $this->assertNoText($native, 'Native not found');
|
109 | | $this->drupalGet('logout');
|
110 | |
|
111 | | // Delete the name string.
|
112 | | $this->drupalLogin($translate_user);
|
113 | | $this->drupalGet('admin/build/translate/delete/'. $lid);
|
114 | | $this->assertText(t('The string has been removed.'), 'The string has been removed message.');
|
115 | | $this->drupalPost('admin/build/translate/search', $search, t('Search'));
|
116 | | $this->assertNoText($name, 'Search now can not find the name');
|
117 | | }
|
118 | | }
|