-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetatag.test
261 lines (250 loc) · 6.95 KB
/
metatag.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
class MetaTagsTestHelper extends DrupalWebTestCase {
function setUp(array $modules = array()) {
$modules[] = 'ctools';
$modules[] = 'token';
$modules[] = 'metatag';
$modules[] = 'metatag_test';
parent::setUp($modules);
}
}
class MetaTagsUnitTest extends MetaTagsTestHelper {
public static function getInfo() {
return array(
'name' => 'Meta tag unit tests',
'description' => 'Test basic meta tag functionality.',
'group' => 'Metatag',
);
}
/**
* Test the metatag_config_load_with_defaults() function.
*/
public function testConfigLoadDefaults() {
$defaults = metatag_config_load_with_defaults('test:foo');
$this->assertEqual($defaults, array(
'description' => array('value' => 'Test foo description'),
'abstract' => array('value' => 'Test foo abstract'),
'title' => array('value' => 'Test altered title'),
'test:foo' => array('value' => 'foobar'),
'generator' => array('value' => 'Drupal 7 (http://drupal.org)'),
'canonical' => array('value' => '[current-page:url:absolute]'),
'shortlink' => array('value' => '[current-page:url:unaliased]'),
));
}
public function testEntitySupport() {
$test_cases[1] = array('type' => 'node', 'bundle' => 'article', 'expected' => TRUE);
$test_cases[2] = array('type' => 'node', 'bundle' => 'page', 'expected' => TRUE);
$test_cases[3] = array('type' => 'node', 'bundle' => 'invalid-bundle', 'expected' => FALSE);
$test_cases[4] = array('type' => 'user', 'expected' => TRUE);
foreach ($test_cases as $test_case) {
$test_case += array('bundle' => NULL);
$this->assertMetatagEntityHasMetatags($test_case['type'], $test_case['bundle'], $test_case['expected']);
}
variable_set('metatag_test_entity_info_disable', TRUE);
drupal_static_reset('metatag_entity_has_metatags');
drupal_static_reset('metatag_entity_supports_metatags');
entity_info_cache_clear();
$test_cases[2]['expected'] = FALSE;
$test_cases[4]['expected'] = FALSE;
foreach ($test_cases as $test_case) {
$test_case += array('bundle' => NULL);
$this->assertMetatagEntityHasMetatags($test_case['type'], $test_case['bundle'], $test_case['expected']);
}
}
function assertMetatagEntityHasMetatags($entity_type, $bundle, $expected) {
$entity = entity_create_stub_entity($entity_type, array(0, NULL, $bundle));
return $this->assertEqual(
metatag_entity_has_metatags($entity_type, $entity),
$expected,
t("metatag_entity_has_metatags(:type, :entity) is :expected", array(
':type' => var_export($entity_type, TRUE),
':entity' => var_export($entity, TRUE),
':expected' => var_export($expected, TRUE),
))
);
}
/**
* Test the metatag_config_instance_label() function.
*/
public function testConfigLabels() {
$test_cases = array(
'node' => 'Node',
'node:article' => 'Node: Article',
'node:article:c' => 'Node: Article: Unknown (c)',
'node:b' => 'Node: Unknown (b)',
'node:b:c' => 'Node: Unknown (b): Unknown (c)',
'a' => 'Unknown (a)',
'a:b' => 'Unknown (a): Unknown (b)',
'a:b:c' => 'Unknown (a): Unknown (b): Unknown (c)',
'a:b:c:d' => 'Unknown (a): Unknown (b): Unknown (c): Unknown (d)',
);
foreach ($test_cases as $input => $expected_output) {
drupal_static_reset('metatag_config_instance_label');
$actual_output = metatag_config_instance_label($input);
$this->assertEqual($actual_output, $expected_output);
}
}
}
// TODO: Test each meta tag.
// TODO: Scenarios.
//
// 1. Node
// * No language assignment.
// * First save.
//
// 2. Node
// * No language assignment.
// * Edit existing revision.
//
// 3. Node
// * No language assignment.
// * Create new revision.
// * Publish new revision.
//
// 4. Node
// * No language assignment.
// * Create new revision.
// * Delete new revision.
//
// 5. Node + Translation
// * No language assignment
// * Change language assignment.
// * Edit existing revision.
//
// 6. Node + Translation
// * No language assignment
// * Change language assignment.
// * Create new revision.
// * Publish new revision.
//
// 7. Node + Translation
// * No language assignment
// * Change language assignment.
// * Create new revision.
// * Delete new revision.
//
// 8. Node + Translation
// * Initial language assignment
//
// 9. Node + Translation
// * Initial language assignment
// * Create new revision.
// * Publish new revision.
//
// 10. Node + Translation
// * Initial language assignment
// * Create new revision.
// * Delete new revision.
//
// 11. Node + Translation
// * Initial language assignment
// * Change language assignment.
// * Create new revision.
// * Publish new revision.
//
// 12. Node + Translation
// * Initial language assignment
// * Change language assignment.
// * Create new revision.
// * Delete new revision.
//
// 13. Node + Translation
// * Initial language assignment
// * Create translated node.
//
// 14. Node + Translation
// * Initial language assignment
// * Create new revision.
// * Publish new revision.
// * Create translated node.
//
// 15. Node + Translation
// * Initial language assignment
// * Create new revision.
// * Publish new revision.
// * Create translated node.
// * Delete translated node.
//
// 16. Node + Translation
// * Initial language assignment
// * Create translated node.
// * Delete original node.
//
// 17. Node + Translation
// * Initial language assignment
// * Create new revision.
// * Publish new revision.
// * Create translated node.
// * Delete original node.
//
// 18. Node + entity_translation
// * Initial language assignment
// * Create translated node.
//
// 19. Node + entity_translation
// * Initial language assignment
// * Create translated node.
// * Delete original.
//
// 20. Node + entity_translation
// * Initial language assignment
// * Create translated node.
// * Create new revision.
// * Publish new revision.
//
// 21. Node + entity_translation
// * Initial language assignment
// * Create translated node.
// * Create new revision.
// * Publish new revision.
// * Delete new revision.
//
// 22. Node + entity_translation
// * Initial language assignment
// * Create translated node.
// * Create new revision.
// * Publish new revision.
// * Delete original.
//
// 23. Node + entity_translation
// * Initial language assignment
// * Create translated node.
// * Create new revision.
// * Publish new revision.
// * Delete original.
//
// 24. Node + entity_translation
// * Initial language assignment
// * Create new revision.
// * Publish new revision.
// * Create translated node.
//
// 25. Node + entity_translation
// * Initial language assignment
// * Create new revision.
// * Publish new revision.
// * Create translated node.
// * Delete new revision.
//
//
// 30. Node + i18n
//
//
// 50. Term
// * Create term.
//
// 51. Term
// * Create term.
// * Change values.
//
//
// 60. User
// * Create user.
//
// 61. User
// * Create user.
// * Change values.
//
//
// 70. Custom path
// * Defaults loaded.