You are here

public function MetatagContextWithI18nTest::testContextI18n in Metatag 7

Verify that strings are added to the translation system.

File

metatag_context/tests/MetatagContextWithI18nTest.test, line 70
Tests the Metatag:Context module for i18n integration.

Class

MetatagContextWithI18nTest
Tests the Metatag:Context module for i18n integration.

Code

public function testContextI18n() {

  // Generate a test object with English strings.
  $object_en = $this
    ->createTestObject('frontpage_metatags', '<front>');

  // Generate a copy of that object only designed for loading on the French
  // front page.
  $object_fr = $this
    ->createTestObject('frontpage_metatags', 'fr');
  foreach (array(
    'title',
    'description',
    'abstract',
    'keywords',
  ) as $tag) {
    $object_fr->{$tag} = $object_fr->{$tag} . ' in French';
  }

  // Create the English test object and check their content.
  $this
    ->generateByPathConfig($object_en);
  $this
    ->editByPathConfig($object_en);
  $this
    ->checkByPathConfig($object_en);

  // Check each of the meta tags that were transmitted.
  foreach (array(
    'title',
    'description',
    'abstract',
    'keywords',
  ) as $tag) {
    $i18n_context = 'metatag_context:' . $object_en->name . ':' . $tag;
    $lid = $this
      ->getTranslationLidByContext($i18n_context);
    $this
      ->assertNotEqual($lid, 0, "Found the {locales_source} record for the {$tag} tag.");

    // Save a translation for this tag.
    $this
      ->saveTranslationString($lid, $i18n_context, 'fr', $object_en->{$tag}, $object_fr->{$tag});
  }

  // Confirm the configuration still works.
  $this
    ->checkByPathConfig($object_en);

  // Confirm the French configuration works too.
  $this
    ->checkByPathConfig($object_fr);
}