123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * Tests for Metatag for when i18n is enabled and actively being used.
- */
- class MetatagCoreWithI18nOutputTest extends MetatagTestHelper {
- /**
- * {@inheritdoc}
- */
- public static function getInfo() {
- return array(
- 'name' => 'Metatag core tests with i18n: output',
- 'description' => 'Test Metatag integration with the i18n module.',
- 'group' => 'Metatag',
- 'dependencies' => array('ctools', 'token', 'i18n'),
- );
- }
- /**
- * {@inheritdoc}
- */
- 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);
- }
- /**
- * Test translations of the output tags.
- */
- public function testI18nOutputTranslationsEnabled() {
- // Enable output translations.
- $this->toggleOutputTranslations(TRUE);
- // Plan out the different translation string tests.
- $string_en = 'Welcome to the homepage!';
- $string_fr = 'Bonjour pour le homepage!';
- $string_context = 'output:frontpage:title';
- $this->searchTranslationPage('', $string_context);
- // Confirm the string is not present yet.
- $this->searchTranslationPage($string_en, $string_context, FALSE);
- // Load the front page's meta tags.
- $instance = 'global:frontpage';
- $config = metatag_config_load($instance);
- // Set something specific as the homepage.
- $config->config['title']['value'] = $string_en;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('');
- $this->assertResponse(200, 'Loaded the homepage.');
- // Confirm the page's title is what we set it to.
- $this->assertTitle($string_en);
- // Confirm the string is translatable.
- $this->searchTranslationPage($string_en, $string_context);
- // Get the translation string lid for the front page's title.
- $lid = $this->getTranslationLidByContext($string_context);
- $this->assertNotEqual($lid, 0, 'Found the locales_source string for the front page output title tag.');
- // Save the translation string.
- $this->saveTranslationString($lid, $string_context, 'fr', $string_en, $string_fr);
- // Load the English front page again.
- $this->drupalGet('');
- $this->assertResponse(200, 'Loaded the default homepage.');
- // Confirm the page's title is what we set it to.
- $this->assertTitle($string_en);
- // Load the French front page.
- $this->drupalGet('fr');
- $this->assertResponse(200, 'Loaded the French homepage.');
- // Confirm the page's title is what we set it to.
- $this->assertTitle($string_fr);
- // Make doubly sure there are output translations.
- $lids = $this->getTranslationsByContext($string_context);
- $this->assertNotEqual($lids, array());
- }
- /**
- * Verify that no output translation records are generated when it's disabled.
- */
- public function testI18nOutputTranslationsDisabled() {
- // Make sure output translations are disabled.
- $this->toggleOutputTranslations(FALSE);
- // Plan out the different translation string tests.
- $string_en = 'Welcome to the homepage!';
- $string_fr = 'Bonjour pour le homepage!';
- $string_context = 'output:frontpage:title';
- $this->searchTranslationPage('', $string_context);
- // Confirm the string is not present yet.
- $this->searchTranslationPage($string_en, $string_context, FALSE);
- // Load the front page's meta tags.
- $instance = 'global:frontpage';
- $config = metatag_config_load($instance);
- // Set something specific as the homepage.
- $config->config['title']['value'] = $string_en;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('');
- $this->assertResponse(200, 'Loaded the homepage.');
- // Confirm the page's title is what we set it to.
- $this->assertTitle($string_en);
- // Confirm the string is still not translatable.
- $this->searchTranslationPage($string_en, $string_context, FALSE);
- // Make doubly sure there are no output translations.
- $lids = $this->getTranslationsByContext($string_context);
- $this->assertEqual($lids, array());
- }
- /**
- *
- */
- public function testMenuPaths() {
- $paths = metatag_test_menu();
- $test_string = 'read-more-books-every-day';
- foreach ($paths as $path => $menu_item) {
- if (substr($path, -1) == '%') {
- $path = substr($path, 0, -1) . $test_string;
- }
- $this->drupalGet($path);
- $this->assertResponse(200, 'Loaded a page: ' . $path);
- }
- }
- /**
- * Enable or disable output translations.
- *
- * @param bool $enable
- * Whether or not to enable translations; defaults to TRUE.
- */
- private function toggleOutputTranslations($enable = TRUE) {
- // Enable output translation.
- variable_set('metatag_i18n_translate_output', $enable);
- // Reload the translations.
- drupal_flush_all_caches();
- module_load_include('admin.inc', 'i18n_string');
- i18n_string_refresh_group('metatag');
- }
- }
|