metatag_panels.i18n.test 3.3 KB

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