metatag.test 6.9 KB

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