function i18nBlocksTestCase::testBlockTranslation in Internationalization 7
File
- i18n_block/i18n_block.test, line 27
- Test case for multilingual blocks
Class
- i18nBlocksTestCase
- @file
Test case for multilingual blocks
Code
function testBlockTranslation() {
$block_translater = $this
->drupalCreateUser(array(
'administer blocks',
'translate interface',
'translate user-defined strings',
));
$switcher = array(
'module' => 'locale',
'delta' => 'language',
'title' => t('Languages'),
);
$this
->moveBlockToRegion($switcher);
$title = $this
->randomName(10);
$this
->updateBlock($switcher, array(
'title' => $title,
'i18n_mode' => I18N_MODE_LOCALIZE,
));
$this
->assertText($title, "The new custom title is displayed on the home page.");
$translations = $this
->createStringTranslation('blocks', $title);
$this
->i18nAssertTranslations($translations);
$block = $this
->i18nCreateBlock();
$languages = $this
->getEnabledLanguages();
$setlanguage = array_shift($languages);
$otherlanguage = array_shift($languages);
$this
->setBlockLanguages($block, array(
$setlanguage->language,
));
$this
->i18nGet($setlanguage);
$this
->assertText($block['title']);
$this
->i18nGet($otherlanguage);
$this
->assertNoText($block['title']);
$box2 = $this
->i18nCreateBlock();
$translations = $this
->i18nTranslateBlock($box2);
$this
->i18nAssertTranslations($translations['title'], '', 'Custom block title translation displayed.');
$this
->i18nAssertTranslations($translations['body'], '', 'Custom block body translation displayed.');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/structure/block/manage/' . $box2['module'] . '/' . $box2['delta'] . '/configure');
$this
->assertNoFieldByName('save_and_translate');
$this
->drupalLogin($block_translater);
$this
->drupalPost('admin/structure/block/manage/' . $box2['module'] . '/' . $box2['delta'] . '/configure', array(), t('Save and translate'));
$this
->assertText(t('Spanish'));
$this
->assertText(t('translated'));
$this
->clickLink(t('translate'));
$this
->assertFieldByName('strings[blocks:block:' . $box2['delta'] . ':title]', $translations['title']['es']);
$this
->assertFieldByName('strings[blocks:block:' . $box2['delta'] . ':body][value]', $translations['body']['es']);
$translations['title']['es'] = $this
->randomName(10);
$translations['body']['es'] = $this
->randomName(20);
$edit = array(
'strings[blocks:block:' . $box2['delta'] . ':title]' => $translations['title']['es'],
'strings[blocks:block:' . $box2['delta'] . ':body][value]' => $translations['body']['es'],
);
$this
->drupalPost(NULL, $edit, t('Save translation'));
$this
->i18nAssertTranslations($translations['title'], '', 'Updated block title translation displayed.');
$this
->i18nAssertTranslations($translations['body'], '', 'Updated block body translation displayed.');
$box3 = $this
->i18nCreateBlock(array(
'title' => '<div><script>alert(0)</script>Title</script>',
'body' => "Dangerous text\nOne line\nTwo lines<script>alert(1)</script>",
));
$title = check_plain($box3['title']);
$body = check_markup($box3['body'], $box3['format']);
$this
->drupalGet('');
$this
->assertRaw($title, "Title being displayed for default language: " . $title);
$this
->assertRaw($body, "Body being displayed for default language: " . $body);
$translations = array();
foreach ($this
->getOtherLanguages() as $langcode => $language) {
$translations[$langcode] = $box3['body'] . "\n" . $language->name;
$filtered[$langcode] = check_markup($translations[$langcode], $box3['format']);
}
$this
->createStringTranslation('blocks', 'Dangerous text', $translations);
$this
->i18nAssertTranslations($filtered);
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/structure/block/manage/system/powered-by/configure');
$this
->assertText(t('This block has generated content, only the title can be translated here.'));
$this
->drupalGet('admin/structure/block/manage/system/navigation/configure');
$this
->assertText(t('To translate the block content itself, translate the menu that is being shown.'));
}