metatag_panels.i18n.test 3.4 KB

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