SimpletestUnitTestExampleTestCase

  1. examples
    1. 7 simpletest_example/simpletest_example.test
    2. 8 simpletest_example/simpletest_example.test

Although most core test cases are based on DrupalWebTestCase and are functional tests (exercising the web UI) we also have DrupalUnitTestCase, which executes much faster because a Drupal install does not have to be one. No environment is provided to a test case based on DrupalUnitTestCase; it must be entirely self-contained.

See also

DrupalUnitTestCase

Hierarchy

Functions & methods

NameDescription
SimpletestUnitTestExampleTestCase::getInfo
SimpletestUnitTestExampleTestCase::setUp
SimpletestUnitTestExampleTestCase::testSimpletestUnitTestExampleFunctionCall simpletest_example_empty_mysql_date and check that it returns correct result.

File

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

View source
class SimpletestUnitTestExampleTestCase extends DrupalUnitTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Simpletest Example unit tests', 
      'description' => 'Test that simpletest_example_empty_mysql_date works properly.', 
      'group' => 'Examples',
    );
  }

  function setUp() {
    drupal_load('module', 'simpletest_example');
    parent::setUp();
  }

  /**
   * Call simpletest_example_empty_mysql_date and check that it returns correct
   * result.
   *
   * Note that no environment is provided; we're just testing the correct
   * behavior of a function when passed specific arguments.
   */
  public function testSimpletestUnitTestExampleFunction() {
    $result = simpletest_example_empty_mysql_date(NULL);
    $message = t('A NULL value should return TRUE.');
    $this->assertTrue($result, $message);

    $result = simpletest_example_empty_mysql_date('');
    $message = t('An empty string should return TRUE.');
    $this->assertTrue($result, $message);

    $result = simpletest_example_empty_mysql_date('0000-00-00');
    $message = t('An "empty" MySQL DATE should return TRUE.');
    $this->assertTrue($result, $message);

    $result = simpletest_example_empty_mysql_date(date('Y-m-d'));
    $message = t('A valid date should return FALSE.');
    $this->assertFalse($result, $message);
  }
}
Login or register to post comments