metatag_hreflang.tags.test 2.3 KB

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