Moodle  2.2.1
http://www.collinsharper.com
FakeDBUnitTestCase Class Reference
Inheritance diagram for FakeDBUnitTestCase:
Collaboration diagram for FakeDBUnitTestCase:

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

Detailed Description

Definition at line 956 of file simpletestlib.php.


Constructor & Destructor Documentation

__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.

Here is the call graph for this function:

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.

Here is the call graph for this function:


Member Function Documentation

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);

Parameters:
string$tablethe table name.
array$rowsthe 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

Parameters:
string$filename

Definition at line 1039 of file simpletestlib.php.

Here is the caller graph for this function:

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'), ));

Parameters:
string$tablethe table name.
array$colsthe columns to fill.
array$datathe data to load.
Returns:
array $objects corresponding to $data.

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.

Todo:
Improve detection of incorrectly built DB test tables (e.g. detect version discrepancy and offer to upgrade/rebuild)

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.

Here is the caller graph for this function:


Field Documentation

$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.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations