You are here

MetatagCoreTermWithI18nTest.test in Metatag 7

Tests for the Metatag module to ensure i18n integration doesn't break.

File

tests/MetatagCoreTermWithI18nTest.test
View source
<?php

/**
 * @file
 * Tests for the Metatag module to ensure i18n integration doesn't break.
 */

/**
 * Tests for the Metatag module to ensure i18n integration doesn't break.
 */
class MetatagCoreTermWithI18nTest extends MetatagTestBase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Metatag core term tests with i18n',
      'description' => 'Test Metatag taxonomy config integration with the i18n module.',
      'group' => 'Metatag',
      'dependencies' => array(
        'ctools',
        'devel',
        'token',
        'i18n',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp(array $modules = array()) {

    // Need the i18n and i18n_strings modules.
    $modules[] = 'i18n';
    $modules[] = 'i18n_string';

    // Enable all of the modules that are needed.
    parent::setUp($modules);

    // Add more locales.
    $this
      ->setupLocales();

    // Set up the locales.
    $perms = array(
      'administer languages',
      'translate interface',
      // From i18n.
      'translate admin strings',
      'translate user-defined strings',
    );
    $this->adminUser = $this
      ->createAdminUser($perms);

    // Log in the admin user.
    $this
      ->drupalLogin($this->adminUser);

    // Reload the translations.
    drupal_flush_all_caches();
    module_load_include('admin.inc', 'i18n_string');
    i18n_string_refresh_group('metatag');
  }

  /**
   * Test translations of the main taxonomy term configuration.
   */
  public function testI18nTermConfig() {

    // Plan out the different translation string tests.
    $string_en = 'It is a term page!';
    $config_name = 'metatag_config:taxonomy_term:title';

    // Confirm the translation page exists and has some Metatag strings.
    $this
      ->searchTranslationPage('', $config_name);

    // Confirm the string is not present yet.
    $this
      ->searchTranslationPage($string_en, $config_name, FALSE);

    // Load the meta tags.
    $instance = 'taxonomy_term';
    $config = metatag_config_load($instance);

    // Set something specific as the homepage.
    $config->config['title']['value'] = $string_en;
    metatag_config_save($config);

    // Confirm the string is present now.
    $this
      ->searchTranslationPage($string_en, $config_name);

    // Get the translation string lid for the term's title.
    $lid = $this
      ->getTranslationLidByContext($config_name);
    $this
      ->assertNotEqual($lid, 0, 'Found the locales_source string for the taxonomy term title tag.');
  }

  /**
   * Test translations of the 'tags' vocabulary configuration.
   */
  public function testI18nTermTagsConfig() {

    // Plan out the different translation string tests.
    $string_en = 'It is a taxonomy term Tags page!';
    $config_name = 'metatag_config:taxonomy_term:tags:title';

    // Confirm the translation page exists and has some Metatag strings.
    $this
      ->searchTranslationPage('', $config_name);

    // Confirm the string is not present yet.
    $this
      ->searchTranslationPage($string_en, $config_name, FALSE);

    // Create a new config object for the taxonomy_term:tags structure.
    $config = new StdClass();
    $config->instance = 'taxonomy_term:tags';

    // Set an example tag.
    $config->config['title']['value'] = $string_en;
    metatag_config_save($config);

    // Confirm the string is present now.
    $this
      ->searchTranslationPage($string_en, $config_name);

    // Get the translation string lid for the term's title.
    $lid = $this
      ->getTranslationLidByContext($config_name);
    $this
      ->assertNotEqual($lid, 0, 'Found the locales_source string for the taxonomy term title tag.');
  }

}

Classes

Namesort descending Description
MetatagCoreTermWithI18nTest Tests for the Metatag module to ensure i18n integration doesn't break.