function LocaleTranslationFunctionalTest::testJavaScriptTranslation in Drupal 7
File
- modules/locale/locale.test, line 458
- Tests for locale.module.
Class
- LocaleTranslationFunctionalTest
- Functional test for string translation and validation.
Code
function testJavaScriptTranslation() {
$user = $this
->drupalCreateUser(array(
'translate interface',
'administer languages',
'access administration pages',
));
$this
->drupalLogin($user);
$langcode = 'xx';
$name = $this
->randomName(16);
$native = $this
->randomName(16);
$prefix = $langcode;
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
$this
->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
drupal_static_reset('language_list');
$this
->drupalGet('admin/config/regional/translate/translate');
$query = db_select('locales_source', 'l');
$query
->addExpression('min(l.lid)', 'lid');
$result = $query
->condition('l.location', '%.js%', 'LIKE')
->condition('l.textgroup', 'default')
->execute();
$url = 'admin/config/regional/translate/edit/' . $result
->fetchObject()->lid;
$edit = array(
'translations[' . $langcode . ']' => $this
->randomName(),
);
$this
->drupalPost($url, $edit, t('Save translations'));
require_once DRUPAL_ROOT . '/includes/locale.inc';
_locale_rebuild_js($langcode);
$file = db_select('languages', 'l')
->fields('l', array(
'javascript',
))
->condition('language', $langcode)
->execute()
->fetchObject();
$js_file = 'public://' . variable_get('locale_js_directory', 'languages') . '/' . $langcode . '_' . $file->javascript . '.js';
$this
->assertTrue($result = file_exists($js_file), format_string('JavaScript file created: %file', array(
'%file' => $result ? $js_file : 'not found',
)));
file_unmanaged_delete($js_file);
$this
->assertTrue($result = !file_exists($js_file), format_string('JavaScript file deleted: %file', array(
'%file' => $result ? $js_file : 'found',
)));
cache_clear_all();
_locale_rebuild_js($langcode);
$this
->assertTrue($result = file_exists($js_file), format_string('JavaScript file rebuilt: %file', array(
'%file' => $result ? $js_file : 'not found',
)));
}