contextual_links_example.test

  1. examples
    1. 7 contextual_links_example/contextual_links_example.test
    2. 8 contextual_links_example/contextual_links_example.test

Tests for the contextual links example module.

Classes

NameDescription
ContextualLinksExampleTestCase@file Tests for the contextual links example module.

File

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