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


Public Member Functions | |
| __construct ($label=false) | |
| tearDown () | |
| __destruct () | |
Protected Member Functions | |
| switch_to_test_db () | |
| revert_to_real_db () | |
| switch_to_test_cfg () | |
| revert_to_real_cfg () | |
| switch_global_user_id ($userid) | |
| revert_global_user_id () | |
| create_system_context_record () | |
| create_test_table ($tablename, $installxmlfile) | |
| create_test_tables ($tablenames, $installxmlfile) | |
| drop_test_table ($tablename) | |
| drop_test_tables ($tablenames) | |
| load_test_data ($table, array $cols, array $data) | |
| delete_test_data ($table, array $rows) | |
Protected Attributes | |
| $testdb | |
| $testcfg | |
Definition at line 636 of file simpletestlib.php.
| __construct | ( | $ | label = false | ) |
| __destruct | ( | ) |
Reimplemented in grade_category_test.
Definition at line 837 of file simpletestlib.php.
| create_system_context_record | ( | ) | [protected] |
Recreates the system context record in the 'context' table
Once we have switched to test db, if we have recreated the context table and it's empty, it may be necessary to manually create the system context record if unittests are going to play with contexts.
This is needed because the context_system::instance() method is exceptional and always requires the record to exist, never creating it :-( No problem for other contexts.
Altenatively one complete install can be done, like {
Ideally some day we'll move a lot of these UnitTests to a complete cloned installation with real data to play with. That day this won't be necessary anymore.
Definition at line 769 of file simpletestlib.php.

| create_test_table | ( | $ | tablename, |
| $ | installxmlfile | ||
| ) | [protected] |
Create a test table just like a real one, getting getting the definition from the specified install.xml file.
| string | $tablename | the name of the test table. |
| string | $installxmlfile | the install.xml file in which this table is defined. $CFG->dirroot . '/' will be prepended, and '/db/install.xml' appended, so you need only specify, for example, 'mod/quiz'. |
Definition at line 850 of file simpletestlib.php.


| create_test_tables | ( | $ | tablenames, |
| $ | installxmlfile | ||
| ) | [protected] |
Convenience method for calling create_test_table repeatedly.
| array | $tablenames | an array of table names. |
| string | $installxmlfile | the install.xml file in which this table is defined. $CFG->dirroot . '/' will be prepended, and '/db/install.xml' appended, so you need only specify, for example, 'mod/quiz'. |
Definition at line 872 of file simpletestlib.php.


| delete_test_data | ( | $ | table, |
| array $ | rows | ||
| ) | [protected] |
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 940 of file simpletestlib.php.
| drop_test_table | ( | $ | tablename | ) | [protected] |
Drop a test table.
| $tablename | the name of the test table. |
Definition at line 882 of file simpletestlib.php.


| drop_test_tables | ( | $ | tablenames | ) | [protected] |
Convenience method for calling drop_test_table repeatedly.
| array | $tablenames | an array of table names. |
Definition at line 897 of file simpletestlib.php.

| load_test_data | ( | $ | table, |
| array $ | cols, | ||
| array $ | data | ||
| ) | [protected] |
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 918 of file simpletestlib.php.

| revert_global_user_id | ( | ) | [protected] |
Revert $USER->id to the real value.
Definition at line 738 of file simpletestlib.php.

| revert_to_real_cfg | ( | ) | [protected] |
Revert to using the real $CFG for all future queries.
Definition at line 711 of file simpletestlib.php.

| revert_to_real_db | ( | ) | [protected] |
Revert to using the test database for all future queries.
Definition at line 689 of file simpletestlib.php.


| switch_global_user_id | ( | $ | userid | ) | [protected] |
Switch $USER->id to a test value.
It might be worth making this method do more robuse $USER switching in future, however, this is sufficient for my needs at present.
Definition at line 725 of file simpletestlib.php.


| switch_to_test_cfg | ( | ) | [protected] |
Switch to using the test $CFG for all queries until further notice.
Definition at line 700 of file simpletestlib.php.


| switch_to_test_db | ( | ) | [protected] |
Switch to using the test database for all queries until further notice.
Definition at line 678 of file simpletestlib.php.


| tearDown | ( | ) |
Reimplemented in accesslib_test, filter_filter_set_applies_to_strings, moodle_page_cm_test, moodle_page_categories_test, moodle_page_with_context_table_test, portfoliolib_test, moodle_block_manager_test_saving_loading, completionlib_test, bloglib_test, grade_test, backup_structure_test, rating_db_test, portfoliolibaddbutton_test, qubaid_condition_test, conditionlib_test, and testPortfolioPluginDownload.
Definition at line 832 of file simpletestlib.php.

$testcfg [protected] |
Definition at line 643 of file simpletestlib.php.
$testdb [protected] |
Definition at line 638 of file simpletestlib.php.