NodeExampleTestCase

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

Functionality tests for node example module.

Hierarchy

Functions & methods

NameDescription
NodeExampleTestCase::getInfo
NodeExampleTestCase::setUp
NodeExampleTestCase::testBodyLabel
NodeExampleTestCase::testNodeCreationVerify the functionality of the example module.

File

node_example/node_example.test, line 13
Simpletest case for node_example module.

View source
class NodeExampleTestCase extends DrupalWebTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Node example', 
      'description' => 'Verify the custom node type creation.', 
      'group' => 'Examples',
    );
  }

  function setUp() {
    // Enable the module.
    parent::setUp('node_example');
  }

  /**
   * Verify the functionality of the example module.
   */
  function testNodeCreation() {
    // Create and login user.
    $account = $this->drupalCreateUser(array('access content', 'create node_example content'));
    $this->drupalLogin($account);

    // Create a new node. The image makes it more complicated, so skip it.
    $edit = array(
      'title' => $this->randomName(), 
      'node_example_color[und][0][value]' => 'red', 
      'node_example_color[und][1][value]' => 'green', 
      'node_example_color[und][2][value]' => 'blue', 
      'node_example_quantity[und][0][value]' => 100,
    );
    $this->drupalPost('node/add/node-example', $edit, t('Save'));
    $this->assertText("Example Node " . $edit['title'] . " has been created", "Found node creation message");
    $this->assertPattern("/The colors available.*red.*green.*blue/", "Correct 'colors available' on node page");

    // Look on the examples page to make sure it shows up there also.
    $this->drupalGet('examples/node_example');
    $this->assertText($edit['title'], "Found random title string");
    $this->assertPattern("/red.*green.*blue/", "Correct 'colors available' on node example page");

  }

  /**
   * Check the value of body label.
   *
   * Checks whether body label has a value of "Example Description"
   */

  function testBodyLabel() {
    // Create and login user.
    $account = $this->drupalCreateUser(array('access content', 'create node_example content'));
    $this->drupalLogin($account);

    // Request a node add node-example page.
    // Test whether the body label equals 'Example Description'.
    // Use '$this->assertRaw' to make certain to test the body label and not some other text.
    $this->drupalGet('node/add/node-example');
    $this->assertResponse(200, 'node/add/node-example page found');
    $this->assertRaw('<label for="edit-body-und-0-value">Example Description </label>', 'Body label equals \'Example Description\'');
  }
}
Login or register to post comments