You are here

public function SimpleTestExampleMockModuleTestCase::testSimpleTestExampleMockModule in Examples for Developers 7

Test modifications made by our mock module.

We create a simpletest_example node and then see if our submodule operated on it.

File

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

Class

SimpleTestExampleMockModuleTestCase
SimpleTestExampleMockModuleTestCase allows us to demonstrate how you can use a mock module to aid in functional testing in Drupal.

Code

public function testSimpleTestExampleMockModule() {

  // Create a user.
  $test_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Log them in.
  $this
    ->drupalLogin($test_user);

  // Set up some content.
  $settings = array(
    'type' => 'simpletest_example',
    'title' => $this
      ->randomName(32),
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          $this
            ->randomName(64),
        ),
      ),
    ),
  );

  // Create the content node.
  $node = $this
    ->drupalCreateNode($settings);

  // View the node.
  $this
    ->drupalGet("node/{$node->nid}");

  // Check that our module did it's thing.
  $this
    ->assertText(t('The test module did its thing.'), "Found evidence of test module.");
}