Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

Testing util classes

Copyright: 2012 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1133 lines (39 kb)
Included or required: 3 times
Referenced: 0 times
Includes or requires: 1 file
 lib/testing/generator/lib.php

Defines 1 class


Class: testing_util  - X-Ref

Utils for test sites creation

get_originaldatafilesjson()   X-Ref
Return the name of the JSON file containing the init filenames.

return: string

get_dataroot()   X-Ref
Return the dataroot. It's useful when mocking the dataroot when unit testing this class itself.

return: string the dataroot.

set_dataroot($dataroot)   X-Ref
Set the dataroot. It's useful when mocking the dataroot when unit testing this class itself.

param: string $dataroot the dataroot of the test framework.

get_framework()   X-Ref
Returns the testing framework name

return: string

get_data_generator()   X-Ref
Get data generator

return: testing_data_generator

is_test_site()   X-Ref
Does this site (db and dataroot) appear to be used for production?
We try very hard to prevent accidental damage done to production servers!!

return: bool

is_test_data_updated()   X-Ref
Returns whether test database and dataroot were created using the current version codebase

return: bool

store_database_state()   X-Ref
Stores the status of the database

Serializes the contents and the structure and
stores it in the test framework space in dataroot

store_versions_hash()   X-Ref
Stores the version hash in both database and dataroot


get_tabledata()   X-Ref
Returns contents of all tables right after installation.

return: array  $table=>$records

get_tablestructure()   X-Ref
Returns structure of all tables right after installation.

return: array $table=>$records

get_sequencenames()   X-Ref
Returns the names of sequences for each autoincrementing id field in all standard tables.

return: array $table=>$sequencename

guess_unmodified_empty_tables()   X-Ref
Returns list of tables that are unmodified and empty.

return: array of table names, empty if unknown

get_next_sequence_starting_value($records, $table)   X-Ref
Determine the next unique starting id sequences.

param: array $records The records to use to determine the starting value for the table.
param: string $table table name.
return: int The value the sequence should be set to.

reset_all_database_sequences(array $empties = null)   X-Ref
Reset all database sequences to initial values.

param: array $empties tables that are known to be unmodified and empty
return: void

reset_database()   X-Ref
Reset all database tables to default values.

return: bool true if reset done, false if skipped

reset_dataroot()   X-Ref
Purge dataroot directory

return: void

get_site_info()   X-Ref
Gets a text-based site version description.

return: string The site info

get_git_hash()   X-Ref
Try to get current git hash of the Moodle in $CFG->dirroot.

return: string null if unknown, sha1 hash if known

set_table_modified_by_sql($sql)   X-Ref
Set state of modified tables.

param: string $sql sql which is updating the table.

reset_updated_table_list()   X-Ref
Reset updated table list. This should be done after every reset.


clean_tables_updated_by_scenario_list()   X-Ref
Delete tablesupdatedbyscenario file. This should be called before suite,
to ensure full db reset.


get_tables_updated_by_scenario_list_path()   X-Ref
Returns the path to the file which holds list of tables updated in scenario.

return: string

drop_database($displayprogress = false)   X-Ref
Drop the whole test database

param: bool $displayprogress

drop_dataroot()   X-Ref
Drops the test framework dataroot


skip_original_data_files($utilclassname)   X-Ref
Skip the original dataroot files to not been reset.

param: string $utilclassname the util class name..

save_original_data_files()   X-Ref
Save the list of the original dataroot files into a json file.


get_environment()   X-Ref
Return list of environment versions on which tests will run.
Environment includes:
- moodleversion
- phpversion
- dbtype
- dbversion
- os

return: array