node_example.test

  1. examples
    1. 6 node_example/node_example.test
    2. 7 node_example/node_example.test
    3. 8 node_example/node_example.test

Simpletest case for node_example module.

Verify example module functionality.

Classes

NameDescription
NodeExampleTestCaseFunctionality tests for node example module.

File

node_example/node_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Simpletest case for node_example module.
  5. *
  6. * Verify example module functionality.
  7. */
  8. /**
  9. * Functionality tests for node example module.
  10. */
  11. class NodeExampleTestCase extends DrupalWebTestCase {
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Node example',
  15. 'description' => 'Verify the custom node type creation.',
  16. 'group' => 'Examples',
  17. );
  18. }
  19. function setUp() {
  20. // Enable the module.
  21. parent::setUp('node_example');
  22. }
  23. /**
  24. * Verify the functionality of the example module.
  25. */
  26. function testNodeCreation() {
  27. // Create and login user.
  28. $account = $this->drupalCreateUser(array('access content', 'create node_example content'));
  29. $this->drupalLogin($account);
  30. // Create a new node. The image makes it more complicated, so skip it.
  31. $edit = array(
  32. 'title' => $this->randomName(),
  33. 'node_example_color[und][0][value]' => 'red',
  34. 'node_example_color[und][1][value]' => 'green',
  35. 'node_example_color[und][2][value]' => 'blue',
  36. 'node_example_quantity[und][0][value]' => 100,
  37. );
  38. $this->drupalPost('node/add/node-example', $edit, t('Save'));
  39. $this->assertText("Example Node " . $edit['title'] . " has been created", "Found node creation message");
  40. $this->assertPattern("/The colors available.*red.*green.*blue/", "Correct 'colors available' on node page");
  41. // Look on the examples page to make sure it shows up there also.
  42. $this->drupalGet('examples/node_example');
  43. $this->assertText($edit['title'], "Found random title string");
  44. $this->assertPattern("/red.*green.*blue/", "Correct 'colors available' on node example page");
  45. }
  46. /**
  47. * Check the value of body label.
  48. *
  49. * Checks whether body label has a value of "Example Description"
  50. */
  51. function testBodyLabel() {
  52. // Create and login user.
  53. $account = $this->drupalCreateUser(array('access content', 'create node_example content'));
  54. $this->drupalLogin($account);
  55. // Request a node add node-example page.
  56. // Test whether the body label equals 'Example Description'.
  57. // Use '$this->assertRaw' to make certain to test the body label and not some other text.
  58. $this->drupalGet('node/add/node-example');
  59. $this->assertResponse(200, 'node/add/node-example page found');
  60. $this->assertRaw('<label for="edit-body-und-0-value">Example Description </label>', 'Body label equals \'Example Description\'');
  61. }
  62. }
Login or register to post comments