PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/web/modules/contrib/metatag/metatag_favicons/tests/src/Functional/MetatagFaviconsTagsTest.php

https://gitlab.com/mohamed_hussein/prodt
PHP | 266 lines | 119 code | 36 blank | 111 comment | 0 complexity | c52be523112e63d2847bfa60deec92b2 MD5 | raw file
  1. <?php
  2. namespace Drupal\Tests\metatag_favicons\Functional;
  3. use Drupal\Tests\metatag\Functional\MetatagTagsTestBase;
  4. /**
  5. * Tests that each of the Metatag Favicons tags work correctly.
  6. *
  7. * @group metatag
  8. */
  9. class MetatagFaviconsTagsTest extends MetatagTagsTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected static $modules = ['metatag_favicons'];
  14. /**
  15. * {@inheritdoc}
  16. */
  17. protected $tags = [
  18. 'shortcut_icon',
  19. 'icon_16x16',
  20. 'icon_32x32',
  21. 'icon_96x96',
  22. 'icon_192x192',
  23. 'apple_touch_icon',
  24. 'apple_touch_icon_72x72',
  25. 'apple_touch_icon_76x76',
  26. 'apple_touch_icon_114x114',
  27. 'apple_touch_icon_120x120',
  28. 'apple_touch_icon_144x144',
  29. 'apple_touch_icon_152x152',
  30. 'apple_touch_icon_180x180',
  31. 'apple_touch_icon_precomposed',
  32. 'apple_touch_icon_precomposed_72x72',
  33. 'apple_touch_icon_precomposed_76x76',
  34. 'apple_touch_icon_precomposed_114x114',
  35. 'apple_touch_icon_precomposed_120x120',
  36. 'apple_touch_icon_precomposed_144x144',
  37. 'apple_touch_icon_precomposed_152x152',
  38. 'apple_touch_icon_precomposed_180x180',
  39. ];
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected $testTag = 'link';
  44. /**
  45. * {@inheritdoc}
  46. */
  47. protected $testNameAttribute = 'rel';
  48. /**
  49. * {@inheritdoc}
  50. */
  51. protected $testValueAttribute = 'href';
  52. /**
  53. * Implements {tag_name}TestValueAttribute() for 'shortcut icon'.
  54. */
  55. protected function shortcutIconTestValueAttribute() {
  56. return 'href';
  57. }
  58. /**
  59. * Implements {tag_name}TestOutputXpath() for 'icon_16x16'.
  60. */
  61. protected function icon16x16TestOutputXpath() {
  62. return "//link[@rel='icon' and @sizes='16x16']";
  63. }
  64. /**
  65. * Implements {tag_name}TestOutputXpath() for 'icon_192x192'.
  66. */
  67. protected function icon192x192TestOutputXpath() {
  68. return "//link[@rel='icon' and @sizes='192x192']";
  69. }
  70. /**
  71. * Implements {tag_name}TestOutputXpath() for 'icon_32x32'.
  72. */
  73. protected function icon32x32TestOutputXpath() {
  74. return "//link[@rel='icon' and @sizes='32x32']";
  75. }
  76. /**
  77. * Implements {tag_name}TestOutputXpath() for 'icon_96x96'.
  78. */
  79. protected function icon96x96TestOutputXpath() {
  80. return "//link[@rel='icon' and @sizes='96x96']";
  81. }
  82. /**
  83. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_precomposed'.
  84. */
  85. protected function appleTouchIconPrecomposedTestOutputXpath() {
  86. return "//link[@rel='apple-touch-icon-precomposed' and not(@sizes)]";
  87. }
  88. /**
  89. * Implements {tag_name}TestOutputXpath().
  90. *
  91. * For 'apple_touch_icon_precomposed_114x114'.
  92. */
  93. protected function appleTouchIconPrecomposed114x114TestOutputXpath() {
  94. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='114x114']";
  95. }
  96. /**
  97. * Implements {tag_name}TestOutputXpath().
  98. *
  99. * For 'apple_touch_icon_precomposed_120x120'.
  100. */
  101. protected function appleTouchIconPrecomposed120x120TestOutputXpath() {
  102. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='120x120']";
  103. }
  104. /**
  105. * Implements {tag_name}TestOutputXpath().
  106. *
  107. * For 'apple_touch_icon_precomposed_144x144'.
  108. */
  109. protected function appleTouchIconPrecomposed144x144TestOutputXpath() {
  110. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='144x144']";
  111. }
  112. /**
  113. * Implements {tag_name}TestOutputXpath().
  114. *
  115. * For 'apple_touch_icon_precomposed_152x152'.
  116. */
  117. protected function appleTouchIconPrecomposed152x152TestOutputXpath() {
  118. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='152x152']";
  119. }
  120. /**
  121. * Implements {tag_name}TestOutputXpath().
  122. *
  123. * For 'apple_touch_icon_precomposed_180x180'.
  124. */
  125. protected function appleTouchIconPrecomposed180x180TestOutputXpath() {
  126. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='180x180']";
  127. }
  128. /**
  129. * Implements {tag_name}TestOutputXpath().
  130. *
  131. * For 'apple_touch_icon_precomposed_72x72'.
  132. */
  133. protected function appleTouchIconPrecomposed72x72TestOutputXpath() {
  134. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='72x72']";
  135. }
  136. /**
  137. * Implements {tag_name}TestOutputXpath().
  138. *
  139. * For 'apple_touch_icon_precomposed_76x76'.
  140. */
  141. protected function appleTouchIconPrecomposed76x76TestOutputXpath() {
  142. return "//link[@rel='apple-touch-icon-precomposed' and @sizes='76x76']";
  143. }
  144. /**
  145. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon'.
  146. */
  147. protected function appleTouchIconTestOutputXpath() {
  148. return "//link[@rel='apple-touch-icon' and not(@sizes)]";
  149. }
  150. /**
  151. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_114x114'.
  152. */
  153. protected function appleTouchIcon114x114TestOutputXpath() {
  154. return "//link[@rel='apple-touch-icon' and @sizes='114x114']";
  155. }
  156. /**
  157. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_120x120'.
  158. */
  159. protected function appleTouchIcon120x120TestOutputXpath() {
  160. return "//link[@rel='apple-touch-icon' and @sizes='120x120']";
  161. }
  162. /**
  163. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_144x144'.
  164. */
  165. protected function appleTouchIcon144x144TestOutputXpath() {
  166. return "//link[@rel='apple-touch-icon' and @sizes='144x144']";
  167. }
  168. /**
  169. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_152x152'.
  170. */
  171. protected function appleTouchIcon152x152TestOutputXpath() {
  172. return "//link[@rel='apple-touch-icon' and @sizes='152x152']";
  173. }
  174. /**
  175. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_180x180'.
  176. */
  177. protected function appleTouchIcon180x180TestOutputXpath() {
  178. return "//link[@rel='apple-touch-icon' and @sizes='180x180']";
  179. }
  180. /**
  181. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_72x72'.
  182. */
  183. protected function appleTouchIcon72x72TestOutputXpath() {
  184. return "//link[@rel='apple-touch-icon' and @sizes='72x72']";
  185. }
  186. /**
  187. * Implements {tag_name}TestOutputXpath() for 'apple_touch_icon_76x76'.
  188. */
  189. protected function appleTouchIcon76x76TestOutputXpath() {
  190. return "//link[@rel='apple-touch-icon' and @sizes='76x76']";
  191. }
  192. /**
  193. * Implements {tag_name}TestTagName for 'shortcut icon'.
  194. */
  195. protected function shortcutIconTestTagName() {
  196. return 'icon';
  197. }
  198. /**
  199. * Test mask_icon.
  200. *
  201. * The mask_icon is a separate test case because of it's unusual structure.
  202. * Mask_icon exists of 2 parts, an href and a color.
  203. */
  204. public function testMaskIcon() {
  205. // Test that mask icon fields are available.
  206. $this->drupalGet('admin/config/search/metatag/global');
  207. $this->assertSession()->statusCodeEquals(200);
  208. $this->assertSession()->fieldExists('mask_icon[href]');
  209. $this->assertSession()->fieldExists('mask_icon[color]');
  210. // Test that a mask_icon is saved successfully and is correctly shown in
  211. // the meta tags.
  212. $edit = [
  213. 'mask_icon[href]' => 'mask_icon_href',
  214. ];
  215. $this->submitForm($edit, 'Save');
  216. $this->assertSession()->pageTextContains('Saved the Global Metatag defaults.');
  217. $this->drupalGet('user');
  218. $this->xpath("//link[@rel='mask-icon' and @href='mask_icon_href']");
  219. // Add a mask_icon color and check if it's correctly shown in the meta
  220. // tags.
  221. $this->drupalGet('admin/config/search/metatag/global');
  222. $edit = [
  223. 'mask_icon[color]' => '#FFFFFF',
  224. ];
  225. $this->submitForm($edit, 'Save');
  226. $this->assertSession()->pageTextContains('Saved the Global Metatag defaults.');
  227. $this->drupalGet('user');
  228. $this->xpath("//link[@rel='mask-icon' and @href='mask_icon_href' and @color='#FFFFFF']");
  229. }
  230. }