1 upgrade.language.test public LanguageUpgradePathTestCase::testLanguageUpgrade()

Tests a successful upgrade.

File

core/modules/simpletest/tests/upgrade/upgrade.language.test, line 28
Upgrade tests for the Language module.

Class

LanguageUpgradePathTestCase
Tests upgrading a filled database with language data.

Code

public function testLanguageUpgrade() {
  $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');

  // Ensure Catalan was properly upgraded to be the new default language.
  $this->assertTrue(language_default()->langcode == 'ca', t('Catalan is the default language'));
  $languages = language_list();
  foreach ($languages as $language) {
    $this->assertTrue($language->default == ($language->langcode == 'ca'), t('@language default property properly set', array('@language' => $language->name)));
  }

  // Ensure the default gets used for URL generation in this test.
  $GLOBALS['language_url'] = language_default();

  // Check that both comments display on the node.
  $this->backdropGet('node/38');
  $this->assertText('Node title 38', t('Node 38 displayed after update.'));
  $this->assertText('First test comment', t('Comment 1 displayed after update.'));
  $this->assertText('Reply to first test comment', t('Comment 2 displayed after update.'));

  // Check each language uses their locale-specific date formats.
  $this->assertText('2010/01/17 - 15:00', 'Localized Catalan medium date format displayed correctly after update.');

  $this->backdropGet('en/node/38');
  $this->assertText('01/17/2010 - 15:00', 'Default U.S. English medium date format displayed correctly after update.');

  $this->backdropGet('cv/node/38');
  $this->assertText('2010/01/17 - 3:00pm', 'Localized Chuvash medium date format displayed correctly after update.');

  // Directly check the comment language property on the first comment.
  $comment = db_query('SELECT * FROM {comment} WHERE cid = :cid', array(':cid' => 1))->fetchObject();
  $this->assertTrue($comment->langcode == 'und', t('Comment 1 language code found.'));

  // Ensure that the language switcher has been correctly upgraded. We need to
  // assert the expected HTML id because the block might appear even if the
  // language negotiation settings are not properly upgraded.
  $elements = $this->xpath('//*[contains(@class, :block)]', array(
    ':block' => 'block-locale-language',
  ));
  $this->assertTrue($elements, t('The language switcher block is being correctly showed.'));

  // Test that the 'language' property was properly renamed to 'langcode'.
  $language_none_nid = 38;
  $spanish_nid = 39;
  $translation_source_nid = 40;
  $translation_nid = 41;
  // Check directly for the $node->langcode property.
  $this->assertEqual(node_load($language_none_nid)->langcode, LANGUAGE_NONE, "'language' property was renamed to 'langcode' for LANGUAGE_NONE node.");
  $this->assertEqual(node_load($spanish_nid)->langcode, 'ca', "'language' property was renamed to 'langcode' for Catalan node.");
  // Check that the translation table works correctly.
  $this->backdropGet("node/$translation_source_nid/translate");
  $this->assertResponse(200, 'The translated node has a proper translation table.');
  $this->assertRaw('<td><strong>English</strong> (source)</td>', 'English is the source node of the translation.');
  $this->assertRaw('<td>Chuvash</td>', 'There is a Chuvash translation of the node.');
  $this->assertLinkByHref("node/$translation_nid", 0, 'The translation table links to the Chuvash translation.');
  $this->assertRaw('<td>Catalan</td><td>N/A</td><td>Not translated</td>', 'There is no Catalan translation of this node.');

  // Check for node content type settings upgrade.
  $this->backdropGet('node/add/article');
  $this->assertFieldByName('langcode');
  $this->backdropGet('node/add/page');
  $this->assertNoFieldByName('langcode');
}