1 translation.test | TranslationTestCase::testLanguageSwitchLinks() |
Checks that the language switch links behave properly.
File
- core/
modules/ translation/ tests/ translation.test, line 156 - Tests for the Translation module.
Class
- TranslationTestCase
- Functional tests for the Translation module.
Code
function testLanguageSwitchLinks() {
// Create a Page in English and its translations in Spanish and
// Italian.
$node = $this->createPage($this->randomName(), $this->randomName(), 'en');
$translation_es = $this->createTranslation($node, $this->randomName(), $this->randomName(), 'es');
$translation_it = $this->createTranslation($node, $this->randomName(), $this->randomName(), 'it');
// Check that language switch links are correctly shown only for enabled
// languages.
$this->assertLanguageSwitchLinks($node, $translation_es);
$this->assertLanguageSwitchLinks($translation_es, $node);
$this->assertLanguageSwitchLinks($node, $translation_it, FALSE);
// Check that links to the displayed translation appear only in the language
// switcher block.
$this->assertLanguageSwitchLinks($node, $node, FALSE, 'node');
$this->assertLanguageSwitchLinks($node, $node, TRUE, 'block-locale');
// Unpublish the Spanish translation to check that the related language
// switch link is not shown.
$this->backdropLogin($this->admin_user);
$edit = array('status' => 0);
$this->backdropPost("node/$translation_es->nid/edit", $edit, t('Save'));
$this->backdropLogin($this->translator);
$this->assertLanguageSwitchLinks($node, $translation_es, FALSE);
// Check that content translation links are shown even when no language
// negotiation is configured.
$this->backdropLogin($this->admin_user);
$edit = array('language[locale-url][enabled]' => FALSE);
$this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));
$this->resetCaches();
$edit = array('status' => 1);
$this->backdropPost("node/$translation_es->nid/edit", $edit, t('Save'));
$this->backdropLogin($this->translator);
$this->assertLanguageSwitchLinks($node, $translation_es, TRUE, 'node');
// Check that language switch links are not shown if hidden for this content
// type.
config_set('node.type.' . $node->type, 'settings.translation_show_links', FALSE);
$this->assertLanguageSwitchLinks($node, $translation_es, FALSE, 'node');
}