metatag_views.i18n.test 3.1 KB

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