metatag_favicons.test 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Metatag Favicons module.
  5. */
  6. class MetatagFaviconsTest extends MetatagTestHelper {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Metatag Favicons tests',
  13. 'description' => 'Test the Metatag:Favicons module.',
  14. 'group' => 'Metatag',
  15. );
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. function setUp(array $modules = array()) {
  21. $modules[] = 'metatag_favicons';
  22. parent::setUp($modules);
  23. // Create an admin user and log them in.
  24. $this->adminUser = $this->createAdminUser();
  25. $this->drupalLogin($this->adminUser);
  26. }
  27. /**
  28. * Confirm that it's possible to load the main admin page.
  29. */
  30. public function testAdminPage() {
  31. $this->drupalGet('admin/config/search/metatags');
  32. $this->assertResponse(200);
  33. // Confirm the page is correct.
  34. $this->assertText(t('To view a summary of the default meta tags and the inheritance, click on a meta tag type.'));
  35. }
  36. /**
  37. * Confirm the mask-icon meta tag works correctly.
  38. */
  39. public function testMaskIconValue() {
  40. // The SVG image is copied from the archive obtained from
  41. // https://www.drupal.org/about/media-kit/logos on 6/20/2016.
  42. $svg_path = drupal_get_path('module', 'metatag_favicons') . '/tests/druplicon-vector.svg';
  43. $relative_path = url($svg_path, array('absolute' => FALSE));
  44. $absolute_path = url($svg_path, array('absolute' => TRUE));
  45. // Testbot doesn't have "clean_url" enabled.
  46. $relative_path = str_replace('?q=', '', $relative_path);
  47. $absolute_path = str_replace('?q=', '', $absolute_path);
  48. // Try filling in a path relative to the Drupal installation.
  49. $config = metatag_config_load('global');
  50. $config->config['mask-icon']['value'] = $svg_path;
  51. metatag_config_save($config);
  52. // Load the config page.
  53. $this->drupalGet('admin/config/search/metatags');
  54. $this->assertResponse(200);
  55. // Confirm the meta tag's value is on the page.
  56. $this->assertText(t('Icon: SVG') . ':');
  57. $this->assertText($absolute_path);
  58. // Load the front page.
  59. $this->drupalGet('<front>');
  60. $this->assertResponse(200);
  61. // Confirm the meta tag is present.
  62. $xpath = $this->xpath("//link[@rel='mask-icon']");
  63. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  64. $this->assertNotEqual((string)$xpath[0]['href'], $svg_path);
  65. $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
  66. // Before proceeding, clear the site's caches.
  67. drupal_flush_all_caches();
  68. // Try filling in a relative path.
  69. $config = metatag_config_load('global');
  70. $config->config['mask-icon']['value'] = $relative_path;
  71. metatag_config_save($config);
  72. // Load the front page.
  73. $this->drupalGet('<front>');
  74. $this->assertResponse(200);
  75. // Confirm the meta tag is present.
  76. $xpath = $this->xpath("//link[@rel='mask-icon']");
  77. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  78. $this->assertNotEqual((string)$xpath[0]['href'], $svg_path);
  79. $this->assertNotEqual((string)$xpath[0]['href'], $relative_path);
  80. // Before proceeding, clear the site's caches.
  81. drupal_flush_all_caches();
  82. // Test filling in an absolute path.
  83. $config = metatag_config_load('global');
  84. $config->config['mask-icon']['value'] = $absolute_path;
  85. metatag_config_save($config);
  86. // Load the front page.
  87. $this->drupalGet('<front>');
  88. $this->assertResponse(200);
  89. // Confirm the meta tag is present.
  90. $xpath = $this->xpath("//link[@rel='mask-icon']");
  91. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  92. $this->assertNotEqual((string)$xpath[0]['href'], $svg_path);
  93. $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
  94. // Before proceeding, clear the site's caches.
  95. drupal_flush_all_caches();
  96. // Test filling in an absolute path for an external file
  97. $path = 'https://www.example.com/example.svg';
  98. $config = metatag_config_load('global');
  99. $config->config['mask-icon']['value'] = $path;
  100. metatag_config_save($config);
  101. // Load the front page.
  102. $this->drupalGet('<front>');
  103. $this->assertResponse(200);
  104. // Confirm the meta tag is present.
  105. $xpath = $this->xpath("//link[@rel='mask-icon']");
  106. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  107. $this->assertNotEqual((string)$xpath[0]['href'], $absolute_path);
  108. $this->assertEqual((string)$xpath[0]['href'], $path);
  109. }
  110. /**
  111. * Confirm the mask-icon meta tag 'color' attribute works correctly.
  112. */
  113. public function testMaskIconColor() {
  114. // The SVG image is copied from the archive obtained from
  115. // https://www.drupal.org/about/media-kit/logos on 6/20/2016.
  116. $svg_path = drupal_get_path('module', 'metatag_favicons') . '/tests/druplicon-vector.svg';
  117. $absolute_path = url($svg_path, array('absolute' => TRUE));
  118. // Testbot doesn't have "clean_url" enabled.
  119. $absolute_path = str_replace('?q=', '', $absolute_path);
  120. // Try a color string.
  121. $color = 'red';
  122. // Update the global config.
  123. $config = metatag_config_load('global');
  124. $config->config['mask-icon']['value'] = $svg_path;
  125. $config->config['mask-icon']['color'] = $color;
  126. metatag_config_save($config);
  127. // Load the front page.
  128. $this->drupalGet('<front>');
  129. $this->assertResponse(200);
  130. // Confirm the meta tag is present.
  131. $xpath = $this->xpath("//link[@rel='mask-icon']");
  132. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  133. $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
  134. $this->assertEqual((string)$xpath[0]['color'], $color);
  135. // Before proceeding, clear the site's caches.
  136. drupal_flush_all_caches();
  137. // Try a color hex code.
  138. $color = '#990000';
  139. // Update the global config.
  140. $config = metatag_config_load('global');
  141. $config->config['mask-icon']['value'] = $svg_path;
  142. $config->config['mask-icon']['color'] = $color;
  143. metatag_config_save($config);
  144. // Load the front page.
  145. $this->drupalGet('<front>');
  146. $this->assertResponse(200);
  147. // Confirm the meta tag is present.
  148. $xpath = $this->xpath("//link[@rel='mask-icon']");
  149. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  150. $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
  151. $this->assertEqual((string)$xpath[0]['color'], $color);
  152. // Try a color RGB value.
  153. $color = 'rgb(153, 0, 0)';
  154. // Update the global config.
  155. $config = metatag_config_load('global');
  156. $config->config['mask-icon']['value'] = $svg_path;
  157. $config->config['mask-icon']['color'] = $color;
  158. metatag_config_save($config);
  159. // Load the front page.
  160. $this->drupalGet('<front>');
  161. $this->assertResponse(200);
  162. // Confirm the meta tag is present.
  163. $xpath = $this->xpath("//link[@rel='mask-icon']");
  164. $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
  165. $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
  166. $this->assertEqual((string)$xpath[0]['color'], $color);
  167. }
  168. }