metatag.with_panels.test 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Tests for the Metatag module for Panels integration, outside of
  4. * Metatag:Panels.
  5. */
  6. class MetatagCoreWithPanelsTest extends MetatagTestHelper {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Metatag core tests with Panels',
  13. 'description' => 'Test Metatag integration with the Panels module.',
  14. 'group' => 'Metatag',
  15. 'dependencies' => array('ctools', 'token', 'panels', 'page_manager'),
  16. );
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. function setUp(array $modules = array()) {
  22. // We'll be using Panels but most of the work is actually in Page Manager.
  23. $modules[] = 'page_manager';
  24. $modules[] = 'panels';
  25. parent::setUp($modules);
  26. }
  27. /**
  28. * Test out a node_view Panels display with Metatag.
  29. */
  30. public function testPanelsNodeView() {
  31. $content_type = 'metatag_test';
  32. $content_type_path = str_replace('_', '-', $content_type);
  33. $label = 'Test';
  34. // Create a content type.
  35. $this->createContentType($content_type, $label);
  36. // Create an admin user and log them in.
  37. $perms = array(
  38. // Needed for the content type.
  39. 'create ' . $content_type . ' content',
  40. 'delete any ' . $content_type . ' content',
  41. 'edit any ' . $content_type . ' content',
  42. // Needed for Panels et al.
  43. 'use page manager',
  44. 'administer page manager',
  45. );
  46. $this->adminUser = $this->createAdminUser($perms);
  47. // Log in the admin user.
  48. $this->drupalLogin($this->adminUser);
  49. // Create a test node.
  50. // Load the node form.
  51. $this->drupalGet('node/add/' . $content_type_path);
  52. $this->assertResponse(200);
  53. // Verify the page loaded correctly.
  54. // @todo Update this to extract the page title.
  55. $this->assertText(strip_tags(t('Create @name', array('@name' => $label))));
  56. // Verify that it's possible to submit values to the form.
  57. $this->drupalPost(NULL, array(
  58. 'metatags[und][abstract][value]' => '[node:title] ponies',
  59. 'title' => 'Who likes magic',
  60. ), t('Save'));
  61. $this->assertResponse(200);
  62. // Verify that the node saved correctly.
  63. // $xpath = $this->xpath("//h1");
  64. $t_args = array('@type' => 'Test', '%title' => 'Who likes magic');
  65. // This doesn't work for some reason, it seems the HTML is stripped off
  66. // during output so the %title's standard Drupal wrappers don't match.
  67. // $this->assertText(t('@type %title has been created.', $t_args));
  68. // .. so this has to be done instead.
  69. $this->assertText(strip_tags(t('@type %title has been created.', $t_args)));
  70. // Save the node URL for later.
  71. $node_url = $this->getUrl();
  72. // Confirm the tags load correctly.
  73. $this->confirmNodeTags();
  74. // Enable the Page Manager display for nodes.
  75. variable_set('page_manager_node_view_disabled', FALSE);
  76. // Confirm that the main Panels page loads correctly.
  77. $this->drupalGet('admin/structure/pages');
  78. $this->assertResponse(200);
  79. // Confirm that the Panels node_view page loads.
  80. $this->drupalGet('admin/structure/pages/edit/node_view');
  81. $this->assertResponse(200);
  82. // Confirm that a new variant can be added.
  83. $this->drupalGet('admin/structure/pages/nojs/operation/node_view/actions/add');
  84. $this->assertResponse(200);
  85. // Create a variant. This is done as a series of form submissions.
  86. $args = array(
  87. 'title' => 'Test',
  88. 'name' => 'test',
  89. 'handler' => 'panel_context',
  90. );
  91. $this->drupalPost('admin/structure/pages/nojs/operation/node_view/actions/add', $args, t('Create variant'));
  92. $this->assertResponse(200);
  93. $args = array(
  94. 'layout' => 'flexible',
  95. );
  96. $this->drupalPost(NULL, $args, t('Continue'));
  97. $this->assertResponse(200);
  98. $args = array();
  99. $this->drupalPost(NULL, $args, t('Continue'));
  100. $this->assertResponse(200);
  101. $args = array();
  102. $this->drupalPost(NULL, $args, t('Create variant'));
  103. $this->assertResponse(200);
  104. $this->assertText(t('The page has been updated. Changes will not be permanent until you save.'));
  105. $args = array();
  106. $this->drupalPost(NULL, $args, t('Save'));
  107. $this->assertResponse(200);
  108. // Confirm the process completed successfully.
  109. $this->assertEqual($this->getUrl(), url('admin/structure/pages/edit/node_view', array('absolute' => TRUE)));
  110. $this->assertText(t('Panel') . ': Test');
  111. // Clear all caches, so we can start off properly.
  112. drupal_flush_all_caches();
  113. // Load the node page again.
  114. $this->confirmNodeTags($node_url);
  115. }
  116. /**
  117. * Confirm that the meta tags for the requested node load properly.
  118. *
  119. * @param string $path
  120. * Optional path to load, if not present the current path will be used.
  121. */
  122. function confirmNodeTags($path = NULL) {
  123. if (!empty($path)) {
  124. $this->drupalGet($path);
  125. $this->assertResponse(200);
  126. }
  127. // Verify the title is using the custom default for this content type.
  128. $xpath = $this->xpath("//meta[@name='abstract']");
  129. $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.');
  130. $this->assertEqual($xpath[0]['content'], 'Who likes magic ponies');
  131. }
  132. /**
  133. * Test out a term_view Panels display with Metatag.
  134. *
  135. * @todo Write this.
  136. */
  137. // public function testPanelsTermView() {
  138. // // Enable the Page Manager display for terms.
  139. // variable_set('page_manager_term_view_disabled', FALSE);
  140. // }
  141. /**
  142. * Test out a user_view Panels display with Metatag.
  143. *
  144. * @todo Write this.
  145. */
  146. // public function testPanelsUserView() {
  147. // // Enable the Page Manager display for users.
  148. // variable_set('page_manager_user_view_disabled', FALSE);
  149. // }
  150. }