View source
<?php
class LocaleModuleTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('String translate'),
'desc' => 'Adds a new locale and translates its name',
'group' => 'Locale',
);
}
function setUp() {
parent::setUp();
$this
->drupalModuleEnable('locale');
}
function testlocaleModuleTest() {
global $base_url;
$admin_user = $this
->drupalCreateUserRolePerm(array(
'administer languages',
'access administration pages',
));
$translate_user = $this
->drupalCreateUserRolePerm(array(
'translate interface',
'access administration pages',
));
$langcode = str_replace('simpletest_', 'si-', $this
->randomName(6));
$name = $this
->randomName(16);
$native = $this
->randomName(16);
$prefix = strtolower(str_replace('si-', '', $langcode));
$language_indicator = "<em class=\"locale-untranslated\">{$langcode}</em> ";
$translation = $this
->randomName(16);
$this
->drupalLoginUser($admin_user);
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
$this
->drupalPost('admin/settings/language/add', $edit, 'Add custom language');
t($name, array(), $langcode);
locale(NULL, NULL, TRUE);
$this
->assertText($langcode, 'Language code found');
$this
->assertText($name, 'Name found');
$this
->assertText($native, 'Native found');
$this
->assertText($native, 'Test language added');
$this
->drupalGet('logout');
$this
->drupalLoginUser($translate_user);
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'all',
'group' => 'all',
);
$this
->drupalPost('admin/build/translate/search', $search, 'Search');
$this
->assertText($name, 'Search found the name');
$this
->assertWantedRaw($language_indicator, 'Name is untranslated');
$this
->clickLink('edit');
$lid = preg_replace('/\\D/', '', substr($this
->getUrl(), strlen($base_url)));
$this
->assertText($name, 'name found on edit screen');
$edit = array(
"translations[{$langcode}]" => $translation,
);
$this
->drupalPost(NULL, $edit, 'Save translations');
$this
->assertText(t('The string has been saved.'), 'The string has been saved.');
$this
->assertTrue($name != $translation && t($name, array(), $langcode) == $translation, 't() works');
$this
->drupalPost('admin/build/translate/search', $search, 'Search');
$this
->assertNoUnwantedRaw($language_indicator, 'String is translated');
$this
->drupalGet('logout');
$this
->drupalLoginUser($admin_user);
$path = 'admin/settings/language/delete/' . $langcode;
$this
->drupalPost($path, array(), 'Delete');
$this
->assertWantedRaw(t('The language %locale has been removed.', array(
'%locale' => $name,
)), 'The test language has been removed.');
$this
->drupalGet($path);
$this
->assertNoText($langcode, 'Language code not found');
$this
->assertNoText($name, 'Name not found');
$this
->assertNoText($native, 'Native not found');
$this
->drupalGet('logout');
$this
->drupalLoginUser($translate_user);
$this
->drupalGet('admin/build/translate/delete/' . $lid);
$this
->assertText(t('The string has been removed.'), 'The string has been removed message.');
$this
->drupalPost('admin/build/translate/search', $search, 'Search');
$this
->assertNoText($name, 'Search now can not find the name');
}
}