You are here

public function MetatagViewsI18nTest::testExportedPage in Metatag 7

Test the Metatag:Views translations.

File

metatag_views/tests/MetatagViewsI18nTest.test, line 67
Tests for the Metatag module for the direct Views integration.

Class

MetatagViewsI18nTest
Tests for the Metatag module for the direct Views integration.

Code

public function testExportedPage() {

  // Plan out the different translation string tests.
  $string_en = 'Testing Metatag:Views.';
  $string_fr = 'French page description.';
  $config_name = 'metatag_views:metatag_views_test' . METATAG_VIEWS_CONTEXT_SEPARATOR . 'page:description';
  $path = 'metatag-views-test';

  // Confirm the string is present as it has been grabbed by the string-
  // refresh triggered in $this->setUp().
  $this
    ->searchTranslationPage($string_en, $config_name);

  // Get the translation string lid for the generator tag.
  $lid = $this
    ->getTranslationLidByContext($config_name);
  $this
    ->assertNotEqual($lid, 0, 'Found the locales_source string for the description tag.');

  // Save the translation string.
  $this
    ->saveTranslationString($lid, $config_name, 'fr', $string_en, $string_fr);

  // Load the English page again.
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, 'Loaded the default test page again.');

  // Confirm the page's description is what we set it to.
  $xpath = $this
    ->xpath("//meta[@name='description']");
  $this
    ->assertEqual(count($xpath), 1, 'Exactly one description meta tag found.');
  $this
    ->assertEqual($xpath[0]['content'], $string_en);
  $this
    ->assertNotEqual($xpath[0]['content'], $string_fr);

  // Load the French page.
  $this
    ->drupalGet('fr/' . $path);
  $this
    ->assertResponse(200, 'Loaded the French test page.');

  // Confirm the generator string was translated.
  $xpath = $this
    ->xpath("//meta[@name='description']");
  $this
    ->assertEqual(count($xpath), 1, 'Exactly one description meta tag found.');
  $this
    ->assertEqual($xpath[0]['content'], $string_fr);
  $this
    ->assertNotEqual($xpath[0]['content'], $string_en);
}