contextual_links_example.test 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file
  4. * Functional tests for the contextual_links_example module.
  5. */
  6. /**
  7. * Functional tests for the contextual_links_example module.
  8. *
  9. * @ingroup contextual_links_example
  10. */
  11. class ContextualLinksExampleTestCase extends DrupalWebTestCase {
  12. protected $webUser;
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static function getInfo() {
  17. return array(
  18. 'name' => 'Contextual links example functionality',
  19. 'description' => 'Tests the behavior of the contextual links provided by the Contextual links example module.',
  20. 'group' => 'Examples',
  21. );
  22. }
  23. /**
  24. * Enable modules and create user with specific permissions.
  25. */
  26. public function setUp() {
  27. parent::setUp('contextual', 'contextual_links_example');
  28. $this->webUser = $this->drupalCreateUser(array('access contextual links', 'administer blocks'));
  29. $this->drupalLogin($this->webUser);
  30. }
  31. /**
  32. * Test the various contextual links that this module defines and displays.
  33. */
  34. public function testContextualLinksExample() {
  35. // Create a node and promote it to the front page. Then view the front page
  36. // and verify that the "Example action" contextual link works.
  37. $node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
  38. $this->drupalGet('');
  39. $this->clickLink(t('Example action'));
  40. $this->assertUrl('node/' . $node->nid . '/example-action', array('query' => array('destination' => 'node')));
  41. // Visit our example overview page and click the third contextual link.
  42. // This should take us to a page for editing the third object we defined.
  43. $this->drupalGet('examples/contextual-links');
  44. $this->clickLink('Edit object', 2);
  45. $this->assertUrl('examples/contextual-links/3/edit', array('query' => array('destination' => 'examples/contextual-links')));
  46. // Enable our module's block, go back to the front page, and click the
  47. // "Edit object" contextual link that we expect to be there.
  48. $edit['blocks[contextual_links_example_example][region]'] = 'sidebar_first';
  49. $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  50. $this->drupalGet('');
  51. $this->clickLink('Edit object');
  52. $this->assertUrl('examples/contextual-links/1/edit', array('query' => array('destination' => 'node')));
  53. }
  54. }