Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250530) (c39b7370636)
mod_lti_testcase Class Reference
Inheritance diagram for mod_lti_testcase:
externallib_advanced_testcase advanced_testcase base_testcase

Public Member Functions

 assertDebuggingCalled ($debugmessage=null, $debuglevel=null, $message='')
 Assert that exactly debugging was just called once.
 
 assertdebuggingcalledcount ($expectedcount, $debugmessages=[], $debuglevels=[], $message='')
 Asserts how many times debugging has been called.
 
 assertDebuggingNotCalled ($message='')
 Call when no debugging() messages expected.
 
 assertEqualsIgnoringWhitespace ($expected, $actual, string $message='')
 Assert that two Date/Time strings are equal.
 
 assertEventContextNotUsed (\core\event\base $event, $message='')
 Assert that various event methods are not using event->context.
 
 assertEventLegacyData ($expected, core\event\base $event, $message='')
 Assert that an event legacy data is equal to the expected value.
 
 assertEventLegacyLogData ($expected, core\event\base $event, $message='')
 Assert that an event legacy log data is equal to the expected value.
 
 assertTimeCurrent ($time, $message='')
 Assert that: start < $time < time()
 
 getDebuggingMessages ()
 Return debugging messages from the current test.
 
 isInIsolation ()
 Determine whether the test is running in isolation.
 
 mock_clock_with_frozen (?int $time=null,)
 Mock the clock with a frozen clock.
 
 mock_clock_with_incrementing (?int $starttime=null,)
 Mock the clock with an incrementing clock.
 
 preventResetByRollback ()
 Call this method from test if you want to make sure that the resetting of database is done the slow way without transaction rollback.
 
 recurseFolders ($path, $callback, $fileregexp='/.*/', $exclude=false, $ignorefolders=array())
 Recursively visit all the files in the source tree.
 
 redirectEmails ()
 Starts email redirection.
 
 redirectEvents ()
 Starts event redirection.
 
 redirectHook (string $hookname, callable $callback)
 Override hook callbacks.
 
 redirectMessages ()
 Starts message redirection.
 
 resetAfterTest ($reset=true)
 Reset everything after current test.
 
 resetDebugging ()
 Clear all previous debugging messages in current test and revert to default DEVELOPER_DEBUG level.
 
 setCurrentTimeStart ()
 Stores current time as the base for assertTimeCurrent().
 
 setup_test_environment ()
 
 stopHookRedirections ()
 Remove all hook overrides.
 
 teardown_test_environment ()
 
 waitForSecond ()
 Wait for a second to roll over, ensures future calls to time() return a different result.
 

Static Public Member Functions

static assertNotTag ($matcher, $actual, $message='', $ishtml=true)
 Note: we are overriding this method to remove the deprecated error.
 
static assertTag ($matcher, $actual, $message='', $ishtml=true)
 Note: we are overriding this method to remove the deprecated error.
 
static assertValidKeys (array $hash, array $validKeys)
 Validate list of keys in the associative array.
 
static assignUserCapability ($capability, $contextid, $roleid=null)
 Assign a capability to $USER The function creates a student $USER if $USER->id is empty.
 
static configure_filters ($filters)
 Configure some filters for external tests.
 
static findNodes (DOMDocument $dom, array $options, $isHtml=true)
 Parse out the options from the tag using DOM object tree.
 
static getDataGenerator ()
 Get data generator.
 
static getExternalTestFileUrl (string $path, bool $https=false,)
 Returns UTL of the external test file.
 
static loadHTML (string $actual)
 Load HTML into a DomDocument.
 
static resetAllData ($detectchanges=false)
 Reset all database tables, restore global state and clear caches and optionally purge dataroot dir.
 
static setAdminUser ()
 Set current $USER to admin account, reset access cache.
 
static setGuestUser ()
 Set current $USER to guest account, reset access cache.
 
static setTimezone ($servertimezone='Australia/Perth', $defaultphptimezone='Australia/Perth')
 Change server and default php timezones.
 
static setUser ($user=null)
 Set current $USER, reset access cache.
 
static unassignUserCapability ($capability, $contextid=null, $roleid=null, $courseid=null, $enrol='manual')
 Unassign a capability to $USER.
 

Protected Member Functions

 add_mocked_plugin (string $plugintype, string $pluginname, string $path,)
 Add a mocked plugin to Moodle.
 
 add_mocked_plugintype (string $plugintype, string $path, bool $deprecated=false,)
 Add a mocked plugintype to Moodle.
 
 generate_tool_proxy (string $uniqueid)
 Generate a tool proxy.
 
 generate_tool_type (string $uniqueid, ?int $toolproxyid=null)
 Generate a tool type.
 
 get_mocked_http_client (?array &$history=null,)
 Get a mocked HTTP Client, inserting it into the Dependency Injector.
 
 get_mocked_string_manager ()
 Get a copy of the mocked string manager.
 
 run_all_adhoc_tasks ()
 Run adhoc tasks.
 
 runAdhocTasks ($matchclass='', $matchuserid=null)
 Run adhoc tasks, optionally matching the specified classname.
 

Static Protected Member Functions

static dataset_from_array (array $data)
 Creates a new dataset from PHP array.
 
static dataset_from_files (array $files)
 Creates a new dataset from CVS/XML files.
 
static dataset_from_string (string $content, string $type, ?string $table=null)
 Creates a new dataset from string (CSV or XML).
 
static get_fixture_path (string $component, string $path,)
 Convenience method to get the path to a fixture.
 
static get_invokable ()
 Get an invokable object for testing.
 
static getDescendants (DOMNode $node)
 Recursively get flat array of all descendants of this node.
 
static getElementsByCaseInsensitiveTagName (DOMDocument $dom, $tag)
 Gets elements by case insensitive tagname.
 
static getInvocationCount (InvocationOrder $counter)
 Helper to get the count of invocation.
 
static getNodeText (DOMNode $node)
 Get the text value of this node's child text node.
 
static load_fixture (string $component, string $path,)
 Convenience method to load a fixture from a component's fixture directory.
 

Member Function Documentation

◆ add_mocked_plugin()

advanced_testcase::add_mocked_plugin ( string $plugintype,
string $pluginname,
string $path )
protectedinherited

Add a mocked plugin to Moodle.

A new plugin name must be provided with a path to the plugin's root. The plugin type must already exist (or have been mocked separately).

Please note that tests calling this method must be run in separate isolation mode. Please avoid using this if at all possible.

Parameters
string$plugintypeThe name of the plugintype
string$pluginnameThe name of the plugin
string$pathThe path to the plugin's root

◆ add_mocked_plugintype()

advanced_testcase::add_mocked_plugintype ( string $plugintype,
string $path,
bool $deprecated = false )
protectedinherited

Add a mocked plugintype to Moodle.

A new plugintype name must be provided with a path to the plugintype's root.

Please note that tests calling this method must be run in separate isolation mode. Please avoid using this if at all possible.

Parameters
string$plugintypeThe name of the plugintype
string$pathThe path to the plugintype's root
bool$deprecatedwhether to add the plugintype as a deprecated plugin type.

◆ assertDebuggingCalled()

advanced_testcase::assertDebuggingCalled ( $debugmessage = null,
$debuglevel = null,
$message = '' )
inherited

Assert that exactly debugging was just called once.

Discards the debugging message if successful.

Parameters
null | string$debugmessagenull means any
null | string$debuglevelnull means any
string$message

◆ assertdebuggingcalledcount()

advanced_testcase::assertdebuggingcalledcount ( $expectedcount,
$debugmessages = [],
$debuglevels = [],
$message = '' )
inherited

Asserts how many times debugging has been called.

Parameters
int$expectedcountThe expected number of times
array$debugmessagesExpected debugging messages, one for each expected message.
array$debuglevelsExpected debugging levels, one for each expected message.
string$message
Return values
void

◆ assertDebuggingNotCalled()

advanced_testcase::assertDebuggingNotCalled ( $message = '')
inherited

Call when no debugging() messages expected.

Parameters
string$message

◆ assertEqualsIgnoringWhitespace()

base_testcase::assertEqualsIgnoringWhitespace ( $expected,
$actual,
string $message = '' )
inherited

Assert that two Date/Time strings are equal.

The strings generated by DateTime, strtotime, date, time, etc. are generated outside of our control. From time-to-time string changes are made. One such example is from ICU 72.1 which changed the time format to include a narrow-non-breaking-space (U+202F) between the time and AM/PM.

We should not update our tests to match these changes, as it is not our code that is generating the strings and they may change again. In addition, the changes are not equal amongst all systems as they depend on the version of ICU installed.

Parameters
string$expected
string$actual
string$message

◆ assertEventContextNotUsed()

advanced_testcase::assertEventContextNotUsed ( \core\event\base $event,
$message = '' )
inherited

Assert that various event methods are not using event->context.

While restoring context might not be valid and it should not be used by event url or description methods.

Parameters
core\event\base$eventthe event object.
string$message
Return values
void

◆ assertEventLegacyData()

advanced_testcase::assertEventLegacyData ( $expected,
core\event\base $event,
$message = '' )
inherited

Assert that an event legacy data is equal to the expected value.

Parameters
mixed$expectedexpected data.
core\event\base$eventthe event object.
string$message
Return values
void

◆ assertEventLegacyLogData()

advanced_testcase::assertEventLegacyLogData ( $expected,
core\event\base $event,
$message = '' )
inherited

Assert that an event legacy log data is equal to the expected value.

Parameters
mixed$expectedexpected data.
core\event\base$eventthe event object.
string$message
Return values
void

◆ assertNotTag()

static base_testcase::assertNotTag ( $matcher,
$actual,
$message = '',
$ishtml = true )
staticinherited

Note: we are overriding this method to remove the deprecated error.

See also
https://tracker.moodle.org/browse/MDL-47129
Parameters
array$matcher
string$actual
string$message
boolean$ishtml
Deprecated
3.0

◆ assertTag()

static base_testcase::assertTag ( $matcher,
$actual,
$message = '',
$ishtml = true )
staticinherited

Note: we are overriding this method to remove the deprecated error.

See also
https://tracker.moodle.org/browse/MDL-47129
Parameters
array$matcher
string$actual
string$message
boolean$ishtml
Deprecated
3.0

◆ assertTimeCurrent()

advanced_testcase::assertTimeCurrent ( $time,
$message = '' )
inherited

Assert that: start < $time < time()

Parameters
int$time
string$message
Return values
void

◆ assertValidKeys()

static base_testcase::assertValidKeys ( array $hash,
array $validKeys )
staticinherited

Validate list of keys in the associative array.

Parameters
array$hash
array$validKeys
Return values
array
Exceptions
PHPUnit::Framework::Exception

◆ assignUserCapability()

static externallib_advanced_testcase::assignUserCapability ( $capability,
$contextid,
$roleid = null )
staticinherited

Assign a capability to $USER The function creates a student $USER if $USER->id is empty.

Parameters
string$capabilitycapability name
int | context$contextid
int$roleid
Return values
intthe role id - mainly returned for creation, so calling function can reuse it

◆ configure_filters()

static externallib_advanced_testcase::configure_filters ( $filters)
staticinherited

Configure some filters for external tests.

Parameters
array$filtersFilters to enable. Each filter should contain:
  • name: name of the filter.
  • state: the state of the filter.
  • move: -1 means up, 0 means the same, 1 means down.
  • applytostrings: true to apply the filter to content and headings, false for just content.

◆ dataset_from_array()

static advanced_testcase::dataset_from_array ( array $data)
staticprotectedinherited

Creates a new dataset from PHP array.

Since
Moodle 3.10
Parameters
array$dataarray of tables, see {
See also
phpunit_dataset\from_array()} for supported formats.
Return values
phpunit_dataset

◆ dataset_from_files()

static advanced_testcase::dataset_from_files ( array $files)
staticprotectedinherited

Creates a new dataset from CVS/XML files.

This method accepts an array of full paths to CSV or XML files to be loaded into the dataset. For CSV files, the name of the table which the file belongs to needs to be specified. Example:

$fullpaths = [ '/path/to/users.xml', 'course' => '/path/to/courses.csv', ];

Since
Moodle 3.10
Parameters
array$filesfull paths to CSV or XML files to load.
Return values
phpunit_dataset

◆ dataset_from_string()

static advanced_testcase::dataset_from_string ( string $content,
string $type,
?string $table = null )
staticprotectedinherited

Creates a new dataset from string (CSV or XML).

Since
Moodle 3.10
Parameters
string$contentcontents (CSV or XML) to load.
string$typeformat of the content to be loaded (csv or xml).
string$tablename of the table which the file belongs to (only for CSV files).
Return values
phpunit_dataset

◆ findNodes()

static base_testcase::findNodes ( DOMDocument $dom,
array $options,
$isHtml = true )
staticinherited

Parse out the options from the tag using DOM object tree.

Parameters
DOMDocument$dom
array$options
bool$isHtml
Return values
array

◆ generate_tool_proxy()

mod_lti_testcase::generate_tool_proxy ( string $uniqueid)
protected

Generate a tool proxy.

Parameters
string$uniqueidEach tool proxy needs a different reg url. Provide a unique string for every tool proxy created.
Return values
stdClassA tool proxy.

◆ generate_tool_type()

mod_lti_testcase::generate_tool_type ( string $uniqueid,
?int $toolproxyid = null )
protected

Generate a tool type.

Parameters
string$uniqueidEach tool type needs a different base url. Provide a unique string for every tool type created.
int | null$toolproxyidOptional proxy to associate with tool type.
Return values
stdClassA tool type.

◆ get_fixture_path()

static advanced_testcase::get_fixture_path ( string $component,
string $path )
staticprotectedinherited

Convenience method to get the path to a fixture.

Parameters
string$component
string$path
Exceptions
coding_exception

◆ get_invokable()

static base_testcase::get_invokable ( )
staticprotectedinherited

Get an invokable object for testing.

This is a helper method to create an invokable object for testing which can be used to track invocations, including arguments provided.

This can be useful for modifications to the error handler.

Return values
object

◆ get_mocked_http_client()

advanced_testcase::get_mocked_http_client ( ?array & $history = null)
protectedinherited

Get a mocked HTTP Client, inserting it into the Dependency Injector.

Parameters
array | null$historyAn array which will contain the Request/Response history of the HTTP client
Return values
arrayContaining the client, the mock, and the history

◆ get_mocked_string_manager()

advanced_testcase::get_mocked_string_manager ( )
protectedinherited

Get a copy of the mocked string manager.

Return values
core\tests\mocking_string_manager

◆ getDataGenerator()

static advanced_testcase::getDataGenerator ( )
staticinherited

Get data generator.

Return values
testing_data_generator

◆ getDebuggingMessages()

advanced_testcase::getDebuggingMessages ( )
inherited

Return debugging messages from the current test.

Return values
arraywith instances having 'message', 'level' and 'stacktrace' property.

◆ getDescendants()

static base_testcase::getDescendants ( DOMNode $node)
staticprotectedinherited

Recursively get flat array of all descendants of this node.

Parameters
DOMNode$node
Return values
array

◆ getElementsByCaseInsensitiveTagName()

static base_testcase::getElementsByCaseInsensitiveTagName ( DOMDocument $dom,
$tag )
staticprotectedinherited

Gets elements by case insensitive tagname.

Parameters
DOMDocument$dom
string$tag
Return values
DOMNodeList

◆ getExternalTestFileUrl()

static advanced_testcase::getExternalTestFileUrl ( string $path,
bool $https = false )
staticinherited

Returns UTL of the external test file.

The result depends on the value of following constants:

  • TEST_EXTERNAL_FILES_HTTP_URL
  • TEST_EXTERNAL_FILES_HTTPS_URL

They should point to standard external test files repository, it defaults to 'http://download.moodle.org/unittest'.

False value means skip tests that require external files.

Parameters
string$path
bool$httpstrue if https required
Return values
stringurl

◆ getInvocationCount()

static base_testcase::getInvocationCount ( InvocationOrder $counter)
staticprotectedinherited

Helper to get the count of invocation.

This is required because the method to use changed names in PHPUnit 10.0 in a breaking change.

Parameters
PHPUnit::Framework::MockObject::Rule::InvocationOrder$counter
Return values
int

◆ getNodeText()

static base_testcase::getNodeText ( DOMNode $node)
staticprotectedinherited

Get the text value of this node's child text node.

Parameters
DOMNode$node
Return values
string

◆ isInIsolation()

base_testcase::isInIsolation ( )
inherited

Determine whether the test is running in isolation.

Note: This was previously a public method of the TestCase, but as removed in PHPUnit 10. There is no direct replacement, but we can use reflection to access the protected property.

Return values
bool

◆ load_fixture()

static advanced_testcase::load_fixture ( string $component,
string $path )
staticprotectedinherited

Convenience method to load a fixture from a component's fixture directory.

Parameters
string$component
string$path
Exceptions
coding_exception

◆ loadHTML()

static base_testcase::loadHTML ( string $actual)
staticinherited

Load HTML into a DomDocument.

Note: THis is a replacement for functionality removed from PHPUnit 10.

Parameters
string$actual
Exceptions
PHPUnit::Util::Xml::XmlException
Return values
DOMDocument

◆ mock_clock_with_frozen()

advanced_testcase::mock_clock_with_frozen ( ?int $time = null)
inherited

Mock the clock with a frozen clock.

Parameters
null | int$time
Return values
frozen_clock

◆ mock_clock_with_incrementing()

advanced_testcase::mock_clock_with_incrementing ( ?int $starttime = null)
inherited

Mock the clock with an incrementing clock.

Parameters
null | int$starttime
Return values
incrementing_clock

◆ preventResetByRollback()

advanced_testcase::preventResetByRollback ( )
inherited

Call this method from test if you want to make sure that the resetting of database is done the slow way without transaction rollback.

This is useful especially when testing stuff that is not compatible with transactions.

Return values
void

◆ recurseFolders()

advanced_testcase::recurseFolders ( $path,
$callback,
$fileregexp = '/.*/',
$exclude = false,
$ignorefolders = array() )
inherited

Recursively visit all the files in the source tree.

Calls the callback function with the pathname of each file found.

Parameters
string$paththe folder to start searching from.
string$callbackthe method of this class to call with the name of each file found.
string$fileregexpa regexp used to filter the search (optional).
bool$excludeIf true, pathnames that match the regexp will be ignored. If false, only files that match the regexp will be included. (default false).
array$ignorefolderswill not go into any of these folders (optional).
Return values
void

◆ redirectEmails()

advanced_testcase::redirectEmails ( )
inherited

Starts email redirection.

You can verify if email were sent or not by inspecting the email array in the returned phpmailer sink instance. The redirection can be stopped by calling $sink->close();

Return values
phpunit_message_sink

◆ redirectEvents()

advanced_testcase::redirectEvents ( )
inherited

Starts event redirection.

You can verify if events were triggered or not by inspecting the events array in the returned event sink instance. The redirection can be stopped by calling $sink->close();

Return values
phpunit_event_sink

◆ redirectHook()

advanced_testcase::redirectHook ( string $hookname,
callable $callback )
inherited

Override hook callbacks.

Parameters
string$hookname
callable$callback
Return values
void

◆ redirectMessages()

advanced_testcase::redirectMessages ( )
inherited

Starts message redirection.

You can verify if messages were sent or not by inspecting the messages array in the returned messaging sink instance. The redirection can be stopped by calling $sink->close();

Return values
phpunit_message_sink

◆ resetAfterTest()

advanced_testcase::resetAfterTest ( $reset = true)
inherited

Reset everything after current test.

Parameters
bool$resettrue means reset state back, false means keep all data for the next test, null means reset state and show warnings if anything changed
Return values
void

◆ resetAllData()

static advanced_testcase::resetAllData ( $detectchanges = false)
staticinherited

Reset all database tables, restore global state and clear caches and optionally purge dataroot dir.

Parameters
bool$detectchangestrue - changes in global state and database are reported as errors false - no errors reported null - only critical problems are reported as errors
Return values
void

◆ runAdhocTasks()

advanced_testcase::runAdhocTasks ( $matchclass = '',
$matchuserid = null )
protectedinherited

Run adhoc tasks, optionally matching the specified classname.

Parameters
string$matchclassThe name of the class to match on.
int$matchuseridThe userid to match.

◆ setAdminUser()

static advanced_testcase::setAdminUser ( )
staticinherited

Set current $USER to admin account, reset access cache.

Return values
void

◆ setCurrentTimeStart()

advanced_testcase::setCurrentTimeStart ( )
inherited

Stores current time as the base for assertTimeCurrent().

Note: this is called automatically before calling individual test methods.

Return values
intcurrent time

◆ setGuestUser()

static advanced_testcase::setGuestUser ( )
staticinherited

Set current $USER to guest account, reset access cache.

Return values
void

◆ setTimezone()

static advanced_testcase::setTimezone ( $servertimezone = 'Australia/Perth',
$defaultphptimezone = 'Australia/Perth' )
staticinherited

Change server and default php timezones.

Parameters
string$servertimezonetimezone to set in $CFG->timezone (not validated)
string$defaultphptimezonetimezone to fake default php timezone (must be valid)

◆ setUser()

static advanced_testcase::setUser ( $user = null)
staticinherited

Set current $USER, reset access cache.

Parameters
null | int | stdClass$useruser record, null or 0 means non-logged-in, positive integer means userid
Return values
void

◆ stopHookRedirections()

advanced_testcase::stopHookRedirections ( )
inherited

Remove all hook overrides.

Return values
void

◆ unassignUserCapability()

static externallib_advanced_testcase::unassignUserCapability ( $capability,
$contextid = null,
$roleid = null,
$courseid = null,
$enrol = 'manual' )
staticinherited

Unassign a capability to $USER.

Parameters
string$capabilitycapability name.
int$contextidset the context id if you used assignUserCapability.
int$roleidset the role id if you used assignUserCapability.
int$courseidset the course id if you used getDataGenerator->enrol_users.
string$enrolset the enrol plugin name if you used getDataGenerator->enrol_users with a different plugin than 'manual'.

◆ waitForSecond()

advanced_testcase::waitForSecond ( )
inherited

Wait for a second to roll over, ensures future calls to time() return a different result.

This is implemented instead of sleep() as we do not need to wait a full second. In some cases due to calls we may wait more than sleep() would have, on average it will be less.


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