metatag.node.with_i18n.test 3.3 KB

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