metatag.with_panels.test 5.6 KB

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