You are here

public function SimpleTestExampleTestCase::testSimpleTestExampleEdit in Examples for Developers 7

Same name and namespace in other branches
  1. 6 simpletest_example/simpletest_example.test \SimpleTestExampleTestCase::testSimpleTestExampleEdit()

Create a simpletest_example node and then see if our user can edit it.

File

simpletest_example/simpletest_example.test, line 81
An example of simpletest tests to accompany the tutorial at http://drupal.org/node/890654.

Class

SimpleTestExampleTestCase
The SimpleTestExampleTestCase is a functional test case, meaning that it actually exercises a particular sequence of actions through the web UI. The majority of core test cases are done this way, but the SimpleTest suite also provides unit tests as…

Code

public function testSimpleTestExampleEdit() {
  $settings = array(
    'type' => 'simpletest_example',
    'title' => $this
      ->randomName(32),
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          $this
            ->randomName(64),
        ),
      ),
    ),
  );
  $node = $this
    ->drupalCreateNode($settings);

  // For debugging, we might output the node structure with $this->verbose()
  // It would only be output if the testing settings had 'verbose' set.
  $this
    ->verbose('Node created: ' . var_export($node, TRUE));

  // We'll run this test normally, but not on the testbot, as it would
  // indicate that the examples module was failing tests.
  if (!$this
    ->runningOnTestbot()) {

    // The debug() statement will output information into the test results.
    // It can also be used in Drupal 7 anywhere in code and will come out
    // as a drupal_set_message().
    debug('We are not running on the PIFR testing server, so will go ahead and catch the failure.');
    $this
      ->drupalGet("node/{$node->nid}/edit");

    // Make sure we don't get a 401 unauthorized response:
    $this
      ->assertResponse(200, 'User is allowed to edit the content.');

    // Looking for title text in the page to determine whether we were
    // successful opening edit form.
    $this
      ->assertText(t("@title", array(
      '@title' => $settings['title'],
    )), "Found title in edit form");
  }
}