metatag_favicons.test 7.7 KB

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