|
Moodle
2.2.1
http://www.collinsharper.com
|


Public Member Functions | |
| __construct ($label=false) | |
| get_table_data ($filename) | |
| setUp () | |
| tearDown () | |
| __destruct () | |
| load_test_data ($table, array $cols, array $data) | |
| delete_test_data ($table, array $rows) | |
Data Fields | |
| $tables = array() | |
| $pkfile | |
| $cfg | |
| $DB | |
Definition at line 956 of file simpletestlib.php.
| __construct | ( | $ | label = false | ) |
In the constructor, record the max(id) of each test table into a csv file. If this file already exists, it means that a previous run of unit tests did not complete, and has left data undeleted in the DB. This data is then deleted and the file is retained. Otherwise it is created.
throws moodle_exception if CSV file cannot be created
Definition at line 970 of file simpletestlib.php.

| __destruct | ( | ) |
This will execute once all the tests have been run. It should delete the text file holding info about database contents prior to the tests It should also detect if data is missing from the original tables.
Definition at line 1105 of file simpletestlib.php.

| delete_test_data | ( | $ | table, |
| array $ | rows | ||
| ) |
Clean up data loaded with load_test_data. The call corresponding to the example load above would be:
$this->delete_test_data('config_plugins', $config);
| string | $table | the table name. |
| array | $rows | the rows to delete. Actually, only $rows[$key]->id is used. |
Definition at line 1161 of file simpletestlib.php.
| get_table_data | ( | $ | filename | ) |
Given a filename, opens it and parses the csv contained therein. It expects two fields per line: 1. Table name 2. Max id
throws moodle_exception if file doesn't exist
| string | $filename |
Definition at line 1039 of file simpletestlib.php.

| load_test_data | ( | $ | table, |
| array $ | cols, | ||
| array $ | data | ||
| ) |
Load a table with some rows of data. A typical call would look like:
$config = $this->load_test_data('config_plugins', array('plugin', 'name', 'value'), array( array('frog', 'numlegs', 2), array('frog', 'sound', 'croak'), array('frog', 'action', 'jump'), ));
| string | $table | the table name. |
| array | $cols | the columns to fill. |
| array | $data | the data to load. |
Definition at line 1133 of file simpletestlib.php.
| setUp | ( | ) |
Method called before each test method. Replaces the real $DB with the one configured for unit tests (different prefix, $CFG->unittestprefix). Also detects if this config setting is properly set, and if the user table exists.
Definition at line 1067 of file simpletestlib.php.
| tearDown | ( | ) |
Method called after each test method. Doesn't do anything extraordinary except restore the global $DB to the real one.
Definition at line 1082 of file simpletestlib.php.

| $cfg |
Definition at line 959 of file simpletestlib.php.
| $DB |
Definition at line 960 of file simpletestlib.php.
| $pkfile |
Definition at line 958 of file simpletestlib.php.
| $tables = array() |
Definition at line 957 of file simpletestlib.php.