metatag.with_views.test 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Views integration, outside of Metatag:Views.
  5. */
  6. /**
  7. * Tests for the Views integration, outside of Metatag:Views.
  8. */
  9. class MetatagCoreWithViewsTest extends MetatagTestHelper {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Metatag core tests with Views',
  16. 'description' => 'Test Metatag integration with the Views module.',
  17. 'group' => 'Metatag',
  18. 'dependencies' => array('ctools', 'token', 'views'),
  19. );
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. function setUp(array $modules = array()) {
  25. $modules[] = 'views';
  26. $modules[] = 'views_ui';
  27. // Need the Path module to set a alias which can then be loaded.
  28. $modules[] = 'path';
  29. parent::setUp($modules);
  30. }
  31. /**
  32. * Test the taxonomy term page still works when displayed via Views.
  33. */
  34. public function testTermViews() {
  35. $vocab_name = 'test_vocab';
  36. $term_name = 'Who likes magic';
  37. $term_path = 'term-test';
  38. // Create a vocabulary.
  39. $vocabulary = $this->createVocabulary($vocab_name);
  40. // Create an admin user and log them in.
  41. $perms = array(
  42. // Global admin access.
  43. 'administer site configuration',
  44. // Needed for the vocabulary.
  45. 'administer taxonomy',
  46. 'edit terms in ' . $vocabulary->vid,
  47. 'delete terms in ' . $vocabulary->vid,
  48. // Needed for the Path module.
  49. 'create url aliases',
  50. // Needed for Views.
  51. 'administer views',
  52. );
  53. $this->adminUser = $this->createAdminUser($perms);
  54. // Log in the admin user.
  55. $this->drupalLogin($this->adminUser);
  56. // Load the "add default configuration" page.
  57. $this->drupalGet('admin/config/search/metatags/config/add');
  58. $this->assertResponse(200);
  59. // Verify the page loaded correct.
  60. $this->assertText(t('Select the type of default meta tags you would like to add.'));
  61. // Submit the initial form to select an entity bundle.
  62. $this->drupalPost(NULL, array(
  63. 'instance' => 'taxonomy_term:' . $vocabulary->name,
  64. ), t('Add and configure'));
  65. $this->assertResponse(200);
  66. // @todo Update this to extract the H1 tag.
  67. $this->assertText(strip_tags('Taxonomy term: ' . $vocabulary->name));
  68. // Submit the form with some values.
  69. $this->drupalPost(NULL, array(
  70. 'metatags[und][abstract][value]' => '[term:name]',
  71. ), t('Save'));
  72. $this->assertResponse(200);
  73. // Verify the page loaded correct.
  74. $this->assertText(strip_tags(t('The meta tag defaults for @label have been saved.', array('@label' => 'Taxonomy term: ' . $vocabulary->name))));
  75. // Verify that the user was redirected to the settings page again.
  76. $this->assertEqual($this->getUrl(), url('admin/config/search/metatags', array('absolute' => TRUE)));
  77. // Create a test term.
  78. // Load the term form.
  79. $this->drupalGet('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add');
  80. $this->assertResponse(200);
  81. // Verify the page loaded correctly.
  82. // @todo Update this to extract the H1 tag.
  83. // $this->assertText(strip_tags(t('Create @name', array('@name' => $vocabulary->name))));
  84. // Verify that it's possible to submit values to the form.
  85. $this->drupalPost(NULL, array(
  86. 'metatags[und][abstract][value]' => '[term:name] ponies',
  87. 'name' => $term_name,
  88. 'path[alias]' => $term_path,
  89. ), t('Save'));
  90. $this->assertResponse(200);
  91. // Verify that the node saved correctly.
  92. $t_args = array('%name' => $term_name);
  93. // This doesn't work for some reason, it seems the HTML is stripped off
  94. // during output so the %name's standard Drupal wrappers don't match.
  95. // $this->assertText(t('Created new term %name.', $t_args));
  96. // .. so this has to be done instead.
  97. $this->assertText(strip_tags(t('Created new term %name.', $t_args)));
  98. // Verify the term data saved correctly.
  99. $this->drupalGet($term_path);
  100. $this->assertResponse(200);
  101. // Confirm the page is managed by the default taxonomy term page.
  102. $this->assertText(t('There is currently no content classified with this term.'));
  103. // Enable the taxonomy_term default display.
  104. $view = views_get_view('taxonomy_term');
  105. ctools_include('export');
  106. ctools_export_set_object_status($view, 0);
  107. $this->clearAllCaches();
  108. $this->drupalGet('admin/structure/views');
  109. $this->assertResponse(200);
  110. $vars = variable_get('views_defaults');
  111. $this->verbose($vars);
  112. $this->assertFalse($vars['taxonomy_term'], 'Taxonomy term page is enabled.');
  113. // Load the page again.
  114. $this->drupalGet($term_path);
  115. $this->assertResponse(200);
  116. // Confirm this page is managed by Views - if it's managed by the default
  117. // taxonomy term page this text will show.
  118. $this->assertNoText(t('There is currently no content classified with this term.'));
  119. // Try to extract the 'edit' link.
  120. $xpaths = $this->xpath("//ul/li/a");
  121. $matches = array();
  122. $tid = 0;
  123. if (!empty($xpaths)) {
  124. foreach ($xpaths as $xpath) {
  125. $attributes = $xpath->attributes();
  126. if (!empty($attributes['href'])) {
  127. if (preg_match('@taxonomy/term/(\d+)/edit$@', $attributes['href'], $matches)) {
  128. $tid = $matches[1];
  129. }
  130. }
  131. }
  132. }
  133. // Presuing a term ID was found, load the term.
  134. if (!empty($tid)) {
  135. $term = taxonomy_term_load($tid);
  136. // Only the non-default values are stored.
  137. $expected = array(
  138. 'und' => array(
  139. 'abstract' => array(
  140. 'value' => '[term:name] ponies',
  141. ),
  142. ),
  143. );
  144. $this->assertEqual($expected, $term->metatags);
  145. }
  146. // This shouldn't happen, it indicates a problem.
  147. else {
  148. $this->fail(t('Could not determine the ID for created term.'));
  149. }
  150. // Verify the title is using the custom default for this vocabulary.
  151. $xpath = $this->xpath("//meta[@name='abstract']");
  152. $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.');
  153. $this->assertEqual($xpath[0]['content'], "Who likes magic ponies");
  154. }
  155. }