Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
behat_util Class Reference

Init/reset utilities for Behat database and dataroot. More...

Inheritance diagram for behat_util:

Static Public Member Functions

static build_themes ($mtraceprogress=false)
 Build theme CSS.
 
static check_server_status ()
 Checks if $CFG->behat_wwwroot is available and using same versions for cli and web.
 
static clean_tables_updated_by_scenario_list ()
 Delete tablesupdatedbyscenario file.
 
static drop_dataroot ()
 Delete files and directories under dataroot.
 
static drop_site ()
 Drops dataroot and remove test database tables.
 
static get_behat_status ()
 Returns the status of the behat test environment.
 
static get_data_generator ()
 Get data generator.
 
static get_dataroot ()
 Return the dataroot.
 
static get_environment ()
 Return list of environment versions on which tests will run.
 
static get_git_hash ()
 Try to get current git hash of the Moodle in $CFG->dirroot.
 
static get_originaldatafilesjson ()
 Return the name of the JSON file containing the init filenames.
 
static get_sequencenames ()
 Returns the names of sequences for each autoincrementing id field in all standard tables.
 
static get_site_info ()
 Gets a text-based site version description.
 
static get_tablestructure ()
 Returns structure of all tables right after installation.
 
static get_test_file_path ()
 Returns the path to the file which specifies if test environment is enabled.
 
static install_site ()
 Installs a site using $CFG->dataroot and $CFG->prefix.
 
static is_test_data_updated ()
 Returns whether test database and dataroot were created using the current version codebase.
 
static is_test_mode_enabled ()
 Checks whether test environment is enabled or disabled.
 
static is_test_site ()
 Does this site (db and dataroot) appear to be used for production? We try very hard to prevent accidental damage done to production servers!!
 
static pause (Session $session, string $message)
 Pause execution immediately.
 
static remove_added_config ()
 Removes config settings that were added to the main $CFG config within the Behat CLI run.
 
static reset_all_data ()
 Reset contents of all database tables to initial values, reset caches, etc.
 
static reset_all_database_sequences (array $empties=null)
 Reset all database sequences to initial values.
 
static reset_database ()
 Reset all database tables to default values.
 
static reset_dataroot ()
 Purge dataroot directory.
 
static reset_updated_table_list ()
 Reset updated table list.
 
static restore_saved_themes ()
 Restore theme CSS stored during behat setup.
 
static set_dataroot ($dataroot)
 Set the dataroot.
 
static set_table_modified_by_sql ($sql)
 Set state of modified tables.
 
static start_test_mode ($themesuitewithallfeatures=false, $tags='', $parallelruns=0, $run=0)
 Enables test mode.
 
static stop_test_mode ()
 Disables test mode.
 

Public Attributes

const BEHATSITENAME = "Acceptance test site"
 The behat test site fullname and shortname.
 

Static Public Attributes

static array $tableupdated = array()
 list of updated tables.
 

Static Protected Member Functions

static drop_database ($displayprogress=false)
 Drop the whole test database.
 
static get_framework ()
 Returns the testing framework name.
 
static get_tabledata ()
 Returns contents of all tables right after installation.
 
static get_tables_updated_by_scenario_list_path ()
 Returns the path to the file which holds list of tables updated in scenario.
 
static guess_unmodified_empty_tables ()
 Returns list of tables that are unmodified and empty.
 
static save_original_data_files ()
 Save the list of the original dataroot files into a json file.
 
static skip_original_data_files ($utilclassname)
 Skip the original dataroot files to not been reset.
 
static store_database_state ()
 Stores the status of the database.
 
static store_versions_hash ()
 Stores the version hash in both database and dataroot.
 
static test_environment_problem ()
 Checks whether the test database and dataroot is ready Stops execution if something went wrong.
 

Static Protected Attributes

static array $datarootskipondrop = array('.', '..', 'lock')
 Files to skip when dropping dataroot folder.
 
static array $datarootskiponreset = array('.', '..', 'behat', 'behattestdir.txt')
 Files to skip when resetting dataroot folder.
 
static testing_data_generator $generator = null
 
static array $sequencenames = null
 original structure of all database tables
 
static int $sequencenextstartingid = null
 next sequence value for a single test cycle.
 
static array $tabledata = null
 original content of all database tables
 
static array $tablestructure = null
 original structure of all database tables
 
static string $versionhash = null
 current version hash from php files
 

Detailed Description

Init/reset utilities for Behat database and dataroot.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ check_server_status()

static behat_util::check_server_status ( )
static

Checks if $CFG->behat_wwwroot is available and using same versions for cli and web.

Return values
void

◆ clean_tables_updated_by_scenario_list()

static testing_util::clean_tables_updated_by_scenario_list ( )
staticinherited

Delete tablesupdatedbyscenario file.

This should be called before suite, to ensure full db reset.

◆ drop_database()

static testing_util::drop_database ( $displayprogress = false)
staticprotectedinherited

Drop the whole test database.

Parameters
bool$displayprogress

◆ drop_dataroot()

static behat_util::drop_dataroot ( )
static

Delete files and directories under dataroot.

Reimplemented from testing_util.

◆ drop_site()

static behat_util::drop_site ( )
static

Drops dataroot and remove test database tables.

Exceptions
coding_exception
Return values
void

◆ get_behat_status()

static behat_util::get_behat_status ( )
static

Returns the status of the behat test environment.

Return values
intError code

◆ get_data_generator()

static testing_util::get_data_generator ( )
staticinherited

Get data generator.

Return values
testing_data_generator

◆ get_dataroot()

static testing_util::get_dataroot ( )
staticinherited

Return the dataroot.

It's useful when mocking the dataroot when unit testing this class itself.

Return values
stringthe dataroot.

◆ get_environment()

static testing_util::get_environment ( )
staticinherited

Return list of environment versions on which tests will run.

Environment includes:

  • moodleversion
  • phpversion
  • dbtype
  • dbversion
  • os
Return values
array

◆ get_framework()

static testing_util::get_framework ( )
staticfinalprotectedinherited

Returns the testing framework name.

Return values
string

◆ get_git_hash()

static testing_util::get_git_hash ( )
staticinherited

Try to get current git hash of the Moodle in $CFG->dirroot.

Return values
stringnull if unknown, sha1 hash if known

◆ get_originaldatafilesjson()

static testing_util::get_originaldatafilesjson ( )
staticinherited

Return the name of the JSON file containing the init filenames.

Return values
string

◆ get_sequencenames()

static testing_util::get_sequencenames ( )
staticinherited

Returns the names of sequences for each autoincrementing id field in all standard tables.

Return values
array\$table,=>$sequencename

◆ get_site_info()

static behat_util::get_site_info ( )
static

Gets a text-based site version description.

Return values
stringThe site info

Reimplemented from testing_util.

◆ get_tabledata()

static testing_util::get_tabledata ( )
staticprotectedinherited

Returns contents of all tables right after installation.

Return values
array\$table,=>$records

◆ get_tables_updated_by_scenario_list_path()

static testing_util::get_tables_updated_by_scenario_list_path ( )
staticfinalprotectedinherited

Returns the path to the file which holds list of tables updated in scenario.

Return values
string

◆ get_tablestructure()

static testing_util::get_tablestructure ( )
staticinherited

Returns structure of all tables right after installation.

Return values
array\$table,=>$records

◆ get_test_file_path()

static behat_util::get_test_file_path ( )
staticfinal

Returns the path to the file which specifies if test environment is enabled.

Return values
string

◆ guess_unmodified_empty_tables()

static testing_util::guess_unmodified_empty_tables ( )
staticprotectedinherited

Returns list of tables that are unmodified and empty.

Return values
arrayof table names, empty if unknown

◆ install_site()

static behat_util::install_site ( )
static

Installs a site using $CFG->dataroot and $CFG->prefix.

Exceptions
coding_exception
Return values
void

◆ is_test_data_updated()

static testing_util::is_test_data_updated ( )
staticinherited

Returns whether test database and dataroot were created using the current version codebase.

Return values
bool

◆ is_test_mode_enabled()

static behat_util::is_test_mode_enabled ( )
static

Checks whether test environment is enabled or disabled.

To check is the current script is running in the test environment

Return values
bool

◆ is_test_site()

static testing_util::is_test_site ( )
staticinherited

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 values
bool

◆ pause()

static behat_util::pause ( Session $session,
string $message )
static

Pause execution immediately.

Parameters
Session$session
string$messageThe message to show when pausing. This will be passed through cli_ansi_format so appropriate ANSI formatting and features are available.

◆ remove_added_config()

static behat_util::remove_added_config ( )
static

Removes config settings that were added to the main $CFG config within the Behat CLI run.

Database storage is already handled by reset_database and existing config values will be reset automatically by initialise_cfg(), so we only need to remove added ones.

◆ reset_all_database_sequences()

static testing_util::reset_all_database_sequences ( array $empties = null)
staticinherited

Reset all database sequences to initial values.

Parameters
array$emptiestables that are known to be unmodified and empty
Return values
void

◆ reset_database()

static testing_util::reset_database ( )
staticinherited

Reset all database tables to default values.

Return values
booltrue if reset done, false if skipped

Reimplemented in phpunit_util.

◆ reset_dataroot()

static testing_util::reset_dataroot ( )
staticinherited

Purge dataroot directory.

Return values
void

◆ reset_updated_table_list()

static testing_util::reset_updated_table_list ( )
staticinherited

Reset updated table list.

This should be done after every reset.

◆ set_dataroot()

static testing_util::set_dataroot ( $dataroot)
staticinherited

Set the dataroot.

It's useful when mocking the dataroot when unit testing this class itself.

Parameters
string$datarootthe dataroot of the test framework.

◆ set_table_modified_by_sql()

static testing_util::set_table_modified_by_sql ( $sql)
staticinherited

Set state of modified tables.

Parameters
string$sqlsql which is updating the table.

◆ skip_original_data_files()

static testing_util::skip_original_data_files ( $utilclassname)
staticprotectedinherited

Skip the original dataroot files to not been reset.

Parameters
string$utilclassnamethe util class name..

◆ start_test_mode()

static behat_util::start_test_mode ( $themesuitewithallfeatures = false,
$tags = '',
$parallelruns = 0,
$run = 0 )
static

Enables test mode.

It uses CFG->behat_dataroot

Starts the test mode checking the composer installation and the test environment and updating the available features and steps definitions.

Stores a file in dataroot/behat to allow Moodle to switch to the test environment when using cli-server.

Parameters
bool$themesuitewithallfeaturesList themes to include core features.
string$tagscomma separated tag, which will be given preference while distributing features in parallel run.
int$parallelrunsnumber of parallel runs.
int$runcurrent run.
Exceptions
coding_exception
Return values
void

◆ stop_test_mode()

static behat_util::stop_test_mode ( )
static

Disables test mode.

Exceptions
coding_exception
Return values
void

◆ store_database_state()

static testing_util::store_database_state ( )
staticprotectedinherited

Stores the status of the database.

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

◆ test_environment_problem()

static behat_util::test_environment_problem ( )
staticprotected

Checks whether the test database and dataroot is ready Stops execution if something went wrong.

Exceptions
coding_exception
Return values
void

The documentation for this class was generated from the following file: