metatag.term.with_i18n.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Metatag module to ensure i18n integration doesn't break.
  5. */
  6. /**
  7. * Tests for the Metatag module to ensure i18n integration doesn't break.
  8. */
  9. class MetatagCoreTermWithI18nTest extends MetatagTestHelper {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Metatag core term tests with i18n',
  16. 'description' => 'Test Metatag taxonomy config integration with the i18n module.',
  17. 'group' => 'Metatag',
  18. 'dependencies' => array('ctools', 'token', 'i18n'),
  19. );
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. function setUp(array $modules = array()) {
  25. // Need the i18n and i18n_strings modules.
  26. $modules[] = 'i18n';
  27. $modules[] = 'i18n_string';
  28. // Enable all of the modules that are needed.
  29. parent::setUp($modules);
  30. // Add more locales.
  31. $this->setupLocales();
  32. // Set up the locales.
  33. $perms = array(
  34. 'administer languages',
  35. 'translate interface',
  36. // From i18n.
  37. 'translate admin strings',
  38. 'translate user-defined strings',
  39. );
  40. $this->adminUser = $this->createAdminUser($perms);
  41. // Log in the admin user.
  42. $this->drupalLogin($this->adminUser);
  43. // Reload the translations.
  44. drupal_flush_all_caches();
  45. module_load_include('admin.inc', 'i18n_string');
  46. i18n_string_refresh_group('metatag');
  47. }
  48. /**
  49. * Test translations of the main taxonomy term configuration.
  50. */
  51. public function testI18nTermConfig() {
  52. // Plan out the different translation string tests.
  53. $string_en = 'It is a term page!';
  54. $config_name = 'metatag_config:taxonomy_term:title';
  55. // Confirm the translation page exists and has some Metatag strings.
  56. $this->searchTranslationPage('', $config_name);
  57. // Confirm the string is not present yet.
  58. $this->searchTranslationPage($string_en, $config_name, FALSE);
  59. // Load the meta tags.
  60. $instance = 'taxonomy_term';
  61. $config = metatag_config_load($instance);
  62. // Set something specific as the homepage.
  63. $config->config['title']['value'] = $string_en;
  64. metatag_config_save($config);
  65. // Confirm the string is present now.
  66. $this->searchTranslationPage($string_en, $config_name);
  67. // Get the translation string lid for the term's title.
  68. $lid = $this->getTranslationLidByContext($config_name);
  69. $this->assertNotEqual($lid, 0, 'Found the locales_source string for the taxonomy term title tag.');
  70. }
  71. /**
  72. * Test translations of the 'tags' vocabulary configuration.
  73. */
  74. public function testI18nTermTagsConfig() {
  75. // Plan out the different translation string tests.
  76. $string_en = 'It is a taxonomy term Tags page!';
  77. $config_name = 'metatag_config:taxonomy_term:tags:title';
  78. // Confirm the translation page exists and has some Metatag strings.
  79. $this->searchTranslationPage('', $config_name);
  80. // Confirm the string is not present yet.
  81. $this->searchTranslationPage($string_en, $config_name, FALSE);
  82. // Create a new config object for the taxonomy_term:tags structure.
  83. $config = new StdClass();
  84. $config->instance = 'taxonomy_term:tags';
  85. // Set an example tag.
  86. $config->config['title']['value'] = $string_en;
  87. metatag_config_save($config);
  88. // Confirm the string is present now.
  89. $this->searchTranslationPage($string_en, $config_name);
  90. // Get the translation string lid for the term's title.
  91. $lid = $this->getTranslationLidByContext($config_name);
  92. $this->assertNotEqual($lid, 0, 'Found the locales_source string for the taxonomy term title tag.');
  93. }
  94. }