You are here

public function SimpleTestExampleTestCase::setUp in Examples for Developers 7

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

Set up the test environment.

This method is called once per test method, before the test is executed. It gives you a chance to control the setup of the test environment.

If you need a different test environment, then you should create another test class which overloads DrupalWebTestCase::setUp() differently.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::setUp()

File

simpletest_example/simpletest_example.test, line 55
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 setUp() {

  // We call parent::setUp() with the list of modules we want to enable.
  // This can be an array or just a list of arguments.
  parent::setUp('simpletest_example');

  // Create and log in our user. The user has the arbitrary privilege
  // 'extra special edit any simpletest_example' which is provided by
  // our module to grant access.
  $this->privilegedUser = $this
    ->drupalCreateUser(array(
    'create simpletest_example content',
    'extra special edit any simpletest_example',
  ));
  $this
    ->drupalLogin($this->privilegedUser);
}