2f0c7ba792f16f151d5811e6ff0d40666e203ccf
[yaffs-website] / web / modules / contrib / metatag / metatag_mobile / src / Tests / MetatagMobileTagsTest.php
1 <?php
2
3 namespace Drupal\metatag_mobile\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\metatag\Tests\MetatagTagsTestBase;
7
8 /**
9  * Tests that each of the Metatag mobile tags work correctly.
10  *
11  * @group metatag
12  */
13 class MetatagMobileTagsTest extends MetatagTagsTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public $tags = [
19     'android_app_link_alternative',
20     'android_manifest',
21     'apple_itunes_app',
22     'apple_mobile_web_app_capable',
23     'apple_mobile_web_app_status_bar_style',
24     'apple_mobile_web_app_title',
25     'application_name',
26     'cleartype',
27     'format_detection',
28     'handheldfriendly',
29     'ios_app_link_alternative',
30     'mobileoptimized',
31     'msapplication_allowDomainApiCalls',
32     'msapplication_allowDomainMetaTags',
33     'msapplication_badge',
34     'msapplication_config',
35     'msapplication_navbutton_color',
36     'msapplication_notification',
37     'msapplication_square150x150logo',
38     'msapplication_square310x310logo',
39     'msapplication_square70x70logo',
40     'msapplication_starturl',
41     'msapplication_task',
42     'msapplication_task_separator',
43     'msapplication_tilecolor',
44     'msapplication_tileimage',
45     'msapplication_tooltip',
46     'msapplication_wide310x150logo',
47     'msapplication_window',
48     'theme_color',
49     'viewport',
50     'x_ua_compatible',
51   ];
52
53   /**
54    * {@inheritdoc}
55    */
56   protected function setUp() {
57     parent::$modules[] = 'metatag_mobile';
58     parent::setUp();
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function getTestTagName($tag_name) {
65     // These tags all use dashes instead of underlines.
66     $tag_name = str_replace('_', '-', $tag_name);
67
68     // Fix a few specific tags.
69     $tag_name = str_replace('mobileoptimized', 'MobileOptimized', $tag_name);
70     $tag_name = str_replace('handheldfriendly', 'HandheldFriendly', $tag_name);
71
72     return $tag_name;
73   }
74
75   /**
76    * Implements {meta_tag_name}_test_output_xpath() for 'alternate-handheld'.
77    */
78   public function alternate_handheld_test_output_xpath() {
79     return "//link[@rel='alternate' and @media='handheld']";
80   }
81
82   /**
83    * Implements {meta_tag_name}_test_value_attribute() for 'alternate-handheld'.
84    */
85   public function alternate_handheld_test_value_attribute() {
86     return 'href';
87   }
88
89   /**
90    * Implements {meta_tag_name}_test_output_xpath() for 'amphtml'.
91    */
92   public function amphtml_test_output_xpath() {
93     return "//link[@rel='amphtml']";
94   }
95
96   /**
97    * Implements {meta_tag_name}_test_value_attribute() for 'amphtml'.
98    */
99   public function amphtml_test_value_attribute() {
100     return 'href';
101   }
102
103   /**
104    * Implements {meta_tag_name}_test_value() for 'android_app_link_alternative'.
105    */
106   public function android_app_link_alternative_test_value() {
107     return 'android-app:' . $this->randomMachineName();
108   }
109
110   /**
111    * Implements {meta_tag_name}_test_output_xpath() for
112    * 'android-app-link-alternative'.
113    */
114   public function android_app_link_alternative_test_output_xpath() {
115     return "//link[@rel='alternate' and starts-with(@href, 'android-app:')]";
116   }
117
118   /**
119    * Implements {meta_tag_name}_test_preprocess_output() for
120    * 'android-app-link-alternative'.
121    */
122   public function android_app_link_alternative_test_preprocess_output($string) {
123     return 'android-app://' . $string;
124   }
125
126   /**
127    * Implements {meta_tag_name}_test_value_attribute() for
128    * 'android-app-link-alternative'.
129    */
130   public function android_app_link_alternative_test_value_attribute() {
131     return 'href';
132   }
133
134   /**
135    * Implements {meta_tag_name}_test_output_xpath() for 'android_manifest'.
136    */
137   public function android_manifest_test_output_xpath() {
138     return "//link[@rel='manifest']";
139   }
140
141   /**
142    * Implements {meta_tag_name}_test_value_attribute() for 'android_manifest'.
143    */
144   public function android_manifest_test_value_attribute() {
145     return 'href';
146   }
147
148   /**
149    * Implements {meta_tag_name}_test_name_attribute() for 'cleartype'.
150    */
151   public function cleartype_test_name_attribute() {
152     return 'http-equiv';
153   }
154
155   /**
156    * Implements {meta_tag_name}_test_output_xpath() for 'handheldfriendly'.
157    */
158   public function handheldfriendly_test_output_xpath() {
159     return "//meta[@name='HandheldFriendly']";
160   }
161
162   /**
163    * Implements {meta_tag_name}_test_value() for
164    * 'ios_app_link_alternative'.
165    */
166   public function ios_app_link_alternative_test_value() {
167     return 'ios-app:' . $this->randomMachineName();
168   }
169
170   /**
171    * Implements {meta_tag_name}_test_output_xpath() for
172    * 'ios_app_link_alternative'.
173    */
174   public function ios_app_link_alternative_test_output_xpath() {
175     return "//link[@rel='alternate' and starts-with(@href, 'ios-app:')]";
176   }
177
178   /**
179    * Implements {meta_tag_name}_test_output_prefix() for
180    * 'ios_app_link_alternative'.
181    */
182   public function ios_app_link_alternative_test_preprocess_output($string) {
183     return 'ios-app://' . $string;
184   }
185
186   /**
187    * Implements {meta_tag_name}_test_value_attribute() for
188    * 'ios_app_link_alternative'.
189    */
190   public function ios_app_link_alternative_test_value_attribute() {
191     return 'href';
192   }
193
194   /**
195    * Implements {meta_tag_name}_test_output_xpath() for 'mobileoptimized'.
196    */
197   public function mobileoptimized_test_output_xpath() {
198     return "//meta[@name='MobileOptimized']";
199   }
200
201   /**
202    * Implements {meta_tag_name}_test_value() for 'msapplication-square150x150logo'.
203    */
204   public function msapplication_square150x150logo_test_value() {
205     return $this->randomImageUrl();
206   }
207
208   /**
209    * Implements {meta_tag_name}_test_value() for 'msapplication-square310x310logo'.
210    */
211   public function msapplication_square310x310logo_test_value() {
212     return $this->randomImageUrl();
213   }
214
215   /**
216    * Implements {meta_tag_name}_test_value() for 'msapplication-square70x70logo'.
217    */
218   public function msapplication_square70x70logo_test_value() {
219     return $this->randomImageUrl();
220   }
221
222   /**
223    * Implements {meta_tag_name}_test_value() for 'msapplication-tileimage'.
224    */
225   public function msapplication_tileimage_test_value() {
226     return $this->randomImageUrl();
227   }
228
229   /**
230    * Implements {meta_tag_name}_test_value() for 'msapplication-wide310x150logo'.
231    */
232   public function msapplication_wide310x150logo_test_value() {
233     return $this->randomImageUrl();
234   }
235
236   /**
237    * Implements {meta_tag_name}_test_name_attribute() for 'x-ua-compatible'.
238    */
239   public function x_ua_compatible_test_name_attribute() {
240     return 'http-equiv';
241   }
242
243 }