Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

Testing general functions Note: these functions must be self contained and must not rely on any library or include

Copyright: 2012 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 307 lines (9 kb)
Included or required: 6 times
Referenced: 0 times
Includes or requires: 0 files

Defines 8 functions


Functions that are not part of a class:

testing_cli_argument_path($moodlepath)   X-Ref
Returns relative path against current working directory,
to be used for shell execution hints.

param: string $moodlepath starting with "/", ex: "/admin/tool/cli/init.php"
return: string path relative to current directory or absolute path

testing_fix_file_permissions($file)   X-Ref
Try to change permissions to $CFG->dirroot or $CFG->dataroot if possible

param: string $file
return: bool success

testing_is_cygwin()   X-Ref
Find out if running under Cygwin on Windows.

return: bool

testing_is_mingw()   X-Ref
Returns whether a mingw CLI is running.

MinGW sets $_SERVER['TERM'] to cygwin, but it
can not run .bat files; this function may be useful
when we need to output proposed commands to users
using Windows CLI interfaces.

return: bool

testing_initdataroot($dataroot, $framework)   X-Ref
Mark empty dataroot to be used for testing.

param: string $dataroot  The dataroot directory
param: string $framework The test framework
return: void

testing_error($errorcode, $text = '')   X-Ref
Prints an error and stops execution

param: integer $errorcode
param: string $text
return: void exits

testing_update_composer_dependencies(bool $selfupdate = true, bool $updatedependencies = true)   X-Ref
Perform necessary steps to install and/or upgrade composer and its dependencies.

Installation is mandatory, but upgrade is optional.

Note: This function does not return, but will call `exit()` on error.

param: bool $selfupdate Perform a composer self-update to update the composer.phar utility
param: bool $updatedependencies Upgrade dependencies

testing_cli_fix_directory_separator($path)   X-Ref
Fix DIRECTORY_SEPARATOR for windows.

In PHP on Windows, DIRECTORY_SEPARATOR is set to the backslash (\)
character. However, if you're running a Cygwin/Msys/Git shell
exec() calls will return paths using the forward slash (/) character.

NOTE: Because PHP on Windows will accept either forward or backslashes,
paths should be built using ONLY forward slashes, regardless of
OS. MOODLE_DIRECTORY_SEPARATOR should only be used when parsing
paths returned by the shell.

param: string $path
return: string.