metatag_views.i18n.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Metatag module for the direct Views integration.
  5. */
  6. class MetatagViewsI18nTest extends MetatagTestHelper {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Metatag:Views i18n tests',
  13. 'description' => 'Test Metatag integration via the Metatag:Views module.',
  14. 'group' => 'Metatag',
  15. );
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. function setUp(array $modules = array()) {
  21. $modules[] = 'views';
  22. $modules[] = 'metatag_views';
  23. // Needed for translations.
  24. $modules[] = 'locale';
  25. $modules[] = 'i18n';
  26. $modules[] = 'i18n_string';
  27. // Enable the hidden submodule to manage some default configs.
  28. $modules[] = 'metatag_views_tests';
  29. parent::setUp($modules);
  30. // Set up the locales.
  31. $perms = array(
  32. 'administer languages',
  33. 'translate interface',
  34. // From i18n.
  35. 'translate admin strings',
  36. 'translate user-defined strings',
  37. );
  38. $this->adminUser = $this->createAdminUser($perms);
  39. $this->setupLocales();
  40. // Reload the translations.
  41. drupal_flush_all_caches();
  42. module_load_include('admin.inc', 'i18n_string');
  43. i18n_string_refresh_group('metatag');
  44. }
  45. /**
  46. * Test the Metatag:Views translations.
  47. */
  48. public function testExportedPage() {
  49. // Plan out the different translation string tests.
  50. $string_en = 'Testing Metatag:Views.';
  51. $string_fr = 'French page description.';
  52. $config_name = 'metatag_views:metatag_views_test' . METATAG_VIEWS_CONTEXT_SEPARATOR . 'page:description';
  53. $path = 'metatag-views-test';
  54. // Confirm the string is present as it has been grabbed by the string-
  55. // refresh triggered in $this->setUp().
  56. $this->searchTranslationPage($string_en, $config_name);
  57. // Get the translation string lid for the generator tag.
  58. $lid = $this->getTranslationLidByContext($config_name);
  59. $this->assertNotEqual($lid, 0, 'Found the locales_source string for the description tag.');
  60. // Save the translation string.
  61. $this->saveTranslationString($lid, $config_name, 'fr', $string_en, $string_fr);
  62. // Load the English page again.
  63. $this->drupalGet($path);
  64. $this->assertResponse(200, 'Loaded the default test page again.');
  65. // Confirm the page's description is what we set it to.
  66. $xpath = $this->xpath("//meta[@name='description']");
  67. $this->assertEqual(count($xpath), 1, 'Exactly one description meta tag found.');
  68. $this->assertEqual($xpath[0]['content'], $string_en);
  69. $this->assertNotEqual($xpath[0]['content'], $string_fr);
  70. // Load the French page.
  71. $this->drupalGet('fr/' . $path);
  72. $this->assertResponse(200, 'Loaded the French test page.');
  73. // Confirm the generator string was translated.
  74. $xpath = $this->xpath("//meta[@name='description']");
  75. $this->assertEqual(count($xpath), 1, 'Exactly one description meta tag found.');
  76. $this->assertEqual($xpath[0]['content'], $string_fr);
  77. $this->assertNotEqual($xpath[0]['content'], $string_en);
  78. }
  79. // @todo Test translations on an in-db display.
  80. }