metatag_hreflang.tags.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @file
  4. * Tests that each of the Metatag Hreflang tags work correctly.
  5. */
  6. /**
  7. * Tests that each of the Metatag Hreflang tags work correctly.
  8. */
  9. class MetatagHreflangTagsTest extends MetatagTagsTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Metatag tags: Hreflang',
  16. 'description' => 'Test the Hreflang meta tags.',
  17. 'group' => 'Metatag',
  18. );
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public $tags = array(
  24. 'hreflang_xdefault',
  25. // Additional meta tags added at the end of setUp().
  26. // @see setUp()
  27. );
  28. /**
  29. * {@inheritdoc}
  30. */
  31. function setUp(array $modules = array()) {
  32. $modules[] = 'metatag_hreflang';
  33. parent::setUp($modules);
  34. // Create an admin user that can also manage locales.
  35. $perms = array(
  36. // For Locale, so languages can be added.
  37. 'administer languages',
  38. );
  39. $this->adminUser = $this->createAdminUser($perms);
  40. // Log in the admin user.
  41. $this->drupalLogin($this->adminUser);
  42. // Add some new languages.
  43. foreach ($this->supportedLocales() as $langcode) {
  44. if ($langcode != 'en') {
  45. $this->addSiteLanguage($langcode);
  46. }
  47. }
  48. // Clear all the caches so that all of the various hooks are activated and
  49. // the appropriate tokens, fields, meta tags, etc are available.
  50. drupal_flush_all_caches();
  51. // Additional meta tags that will be available.
  52. foreach ($this->supportedLocales() as $langcode) {
  53. $this->tags[] = 'hreflang_' . $langcode;
  54. }
  55. }
  56. /**
  57. * The list of locales that are being tested.
  58. *
  59. * @return array
  60. * A simple list of language codes.
  61. */
  62. private function supportedLocales() {
  63. return array(
  64. 'de',
  65. 'fr',
  66. 'es',
  67. // English is automatic, so remember to not try enabling it.
  68. 'en',
  69. );
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public $test_tag = 'link';
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public $test_name_attribute = 'hreflang';
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public $test_value_attribute = 'href';
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function getTestTagValue() {
  87. return base_path() . $this->randomMachineName() . '/' . $this->randomMachineName();
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. public function getTestTagName($tag_name) {
  93. $tag_name = str_replace('xdefault', 'x-default', $tag_name);
  94. return str_replace('hreflang_', '', $tag_name);
  95. }
  96. }