1 translation.test TranslationTestCase::testLanguageSwitcherBlockIntegration()

Tests that the language switcher block alterations work as intended.

File

core/modules/translation/tests/translation.test, line 202
Tests for the Translation module.

Class

TranslationTestCase
Functional tests for the Translation module.

Code

function testLanguageSwitcherBlockIntegration() {
  // Enable Italian to have three items in the language switcher block.
  $this->backdropLogin($this->admin_user);
  $edit = array('languages[it][enabled]' => TRUE);
  $this->backdropPost('admin/config/regional/language', $edit, t('Save configuration'));
  $this->resetCaches();
  $this->backdropLogin($this->translator);

  // Create a Page in English.
  $type = 'block-locale';
  $node = $this->createPage($this->randomName(), $this->randomName(), 'en');
  $this->assertLanguageSwitchLinks($node, $node, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $this->emptyNode('es'), TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $this->emptyNode('it'), TRUE, $type);

  // Create the Spanish translation.
  $translation_es = $this->createTranslation($node, $this->randomName(), $this->randomName(), 'es');
  $this->assertLanguageSwitchLinks($node, $node, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $translation_es, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $this->emptyNode('it'), TRUE, $type);

  // Create the Italian translation.
  $translation_it = $this->createTranslation($node, $this->randomName(), $this->randomName(), 'it');
  $this->assertLanguageSwitchLinks($node, $node, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $translation_es, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $translation_it, TRUE, $type);

  // Create a language neutral node and check that the language switcher is
  // left untouched.
  $node2 = $this->createPage($this->randomName(), $this->randomName(), LANGUAGE_NONE);
  $node2_en = (object) array('nid' => $node2->nid, 'langcode' => 'en');
  $node2_es = (object) array('nid' => $node2->nid, 'langcode' => 'es');
  $node2_it = (object) array('nid' => $node2->nid, 'langcode' => 'it');
  $this->assertLanguageSwitchLinks($node2_en, $node2_en, TRUE, $type);
  $this->assertLanguageSwitchLinks($node2_en, $node2_es, TRUE, $type);
  $this->assertLanguageSwitchLinks($node2_en, $node2_it, TRUE, $type);

  // Disable translation support to check that the language switcher is left
  // untouched only for new nodes.
  $this->backdropLogin($this->admin_user);
  $edit = array('language' => 0);
  $this->backdropPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  $this->backdropLogin($this->translator);

  // Existing translations trigger alterations even if translation support is
  // disabled.
  $this->assertLanguageSwitchLinks($node, $node, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $translation_es, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $translation_it, TRUE, $type);

  // Check that new nodes with a language assigned do not trigger language
  // switcher alterations when translation support is disabled.
  $node = $this->createPage($this->randomName(), $this->randomName());
  $node_es = (object) array('nid' => $node->nid, 'langcode' => 'es');
  $node_it = (object) array('nid' => $node->nid, 'langcode' => 'it');
  $this->assertLanguageSwitchLinks($node, $node, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $node_es, TRUE, $type);
  $this->assertLanguageSwitchLinks($node, $node_it, TRUE, $type);
}