Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
lti_advantage_testcase Class Reference
Inheritance diagram for lti_advantage_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=array(), $debuglevels=array(), $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.
 
 getExternalTestFileUrl ($path, $https=false)
 Returns UTL of the external test file.
 
 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.
 
 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.
 
 runBare ()
 Runs the bare test sequence.
 
 setCurrentTimeStart ()
 Stores current time as the base for assertTimeCurrent().
 
 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 findNodes (DOMDocument $dom, array $options, $isHtml=true)
 Parse out the options from the tag using DOM object tree.
 
static getDataGenerator ()
 Get data generator.
 
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.
 

Protected Member Functions

 create_test_environment (bool $enableauthplugin=true, bool $enableenrolplugin=true, bool $membersync=true, int $membersyncmode=helper::MEMBER_SYNC_ENROL_AND_UNENROL, bool $gradesync=true, bool $gradesynccompletion=false, int $enrolstartdate=0, int $provisioningmodeinstructor=0, int $provisioningmodelearner=0)
 Sets up and returns a test course, including LTI-published resources, ready for testing.
 
 createArrayDataSet ()
 
 createCsvDataSet ()
 
 createXMLDataSet ()
 
 dataset_from_array (array $data)
 Creates a new dataset from PHP array.
 
 dataset_from_files (array $files)
 Creates a new dataset from CVS/XML files.
 
 dataset_from_string (string $content, string $type, ?string $table=null)
 Creates a new dataset from string (CSV or XML).
 
 enable_auth ()
 Enable auth_lti plugin.
 
 enable_enrol ()
 Enable enrol_lti plugin.
 
 get_mock_launch (\stdClass $resource, array $mockuser, ?string $resourcelinkid=null, ?array $ags=[], bool $nrps=true, ?array $migrationclaiminfo=null, ?array $customparams=null, $aud='123')
 Get a mock LtiMessageLaunch object, as if a user had launched from a resource link in the platform.
 
 get_mock_launch_users_with_ids (array $ids, bool $includepicture=false, string $role='http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor')
 Get a list of users ready for use with mock launches by providing an array of user ids.
 
 get_tool_launch_service ()
 Helper to get a tool_launch_service instance.
 
 loadDataSet ()
 
 lti_advantage_user_authenticates (string $sub, array $migrationclaiminfo=[])
 Helper to return a user which has been bound to the LTI credentials provided and is deemed a valid linked user.
 
 runAdhocTasks ($matchclass='', $matchuserid=null)
 Run adhoc tasks, optionally matching the specified classname.
 
 setup_legacy_data (\stdClass $course, array $legacydata)
 Set up data representing a several published legacy tools, including tool records, tool consumer maps and a user.
 

Static Protected Member Functions

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 getNodeText (DOMNode $node)
 Get the text value of this node's child text node.
 

Protected Attributes

string $issuer = 'https://lms.example.org'
 the default issuer for tests extending this class.
 

Member Function Documentation

◆ 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 = array(),
$debuglevels = array(),
$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

◆ create_test_environment()

lti_advantage_testcase::create_test_environment ( bool $enableauthplugin = true,
bool $enableenrolplugin = true,
bool $membersync = true,
int $membersyncmode = helper::MEMBER_SYNC_ENROL_AND_UNENROL,
bool $gradesync = true,
bool $gradesynccompletion = false,
int $enrolstartdate = 0,
int $provisioningmodeinstructor = 0,
int $provisioningmodelearner = 0 )
protected

Sets up and returns a test course, including LTI-published resources, ready for testing.

Parameters
bool$enableauthpluginwhether to enable the auth plugin during setup.
bool$enableenrolpluginwhether to enable the enrol plugin during setup.
bool$membersyncwhether or not the published resource support membership sync with the platform.
int$membersyncmodethe mode of member sync to set up on the shared resource.
bool$gradesyncwhether or not to enabled gradesync on the published resources.
bool$gradesynccompletionwhether or not to require gradesynccompletion on the published resources.
int$enrolstartdatethe unix time when the enrolment starts, or 0 for no start time.
int$provisioningmodeinstructorthe teacher provisioning mode for all created resources, 0 for default (prompt).
int$provisioningmodelearnerthe student provisioning mode for all created resources, 0 for default (auto).
Return values
arrayarray of objects for use in individual tests; courses, tools.

◆ createArrayDataSet()

advanced_testcase::createArrayDataSet ( )
protectedinherited
Deprecated
since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info.

◆ createCsvDataSet()

advanced_testcase::createCsvDataSet ( )
protectedinherited
Deprecated
since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info.

◆ createXMLDataSet()

advanced_testcase::createXMLDataSet ( )
protectedinherited
Deprecated
since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info.

◆ dataset_from_array()

advanced_testcase::dataset_from_array ( array $data)
protectedinherited

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()

advanced_testcase::dataset_from_files ( array $files)
protectedinherited

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()

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

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

◆ get_mock_launch()

lti_advantage_testcase::get_mock_launch ( \stdClass $resource,
array $mockuser,
?string $resourcelinkid = null,
?array $ags = [],
bool $nrps = true,
?array $migrationclaiminfo = null,
?array $customparams = null,
$aud = '123' )
protected

Get a mock LtiMessageLaunch object, as if a user had launched from a resource link in the platform.

Parameters
stdClass$resourcethe resource record, allowing the mock to generate a link to this.
array$mockuserthe user on the platform who is performing the launch.
string | null$resourcelinkidthe id of resource link in the platform, if desired.
array | null$agsarray representing the lti-ags claim info. Pass null to omit, empty array to use a default.
bool$nrpswhether to include a mock NRPS claim or not.
array | null$migrationclaiminfocontains consumer key, secret and any fields which are sent in the claim.
array | null$customparamsan array of custom params to send, or null to just use defaults.
mixed$audthe array or string value of aud to use in the mock launch data.
Return values
LtiMessageLaunchthe mock launch object with test launch data.

◆ get_mock_launch_users_with_ids()

lti_advantage_testcase::get_mock_launch_users_with_ids ( array $ids,
bool $includepicture = false,
string $role = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor' )
protected

Get a list of users ready for use with mock launches by providing an array of user ids.

Parameters
array$idsthe platform user_ids for the users.
bool$includepicturewhether to include a profile picture or not (slows tests, so defaults to false).
string$rolethe LTI role to include in the user data.
Return values
arraythe users list.

◆ get_tool_launch_service()

lti_advantage_testcase::get_tool_launch_service ( )
protected

Helper to get a tool_launch_service instance.

Return values
tool_launch_servicethe instance.

◆ 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()

advanced_testcase::getExternalTestFileUrl ( $path,
$https = false )
inherited

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

◆ 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

◆ loadDataSet()

advanced_testcase::loadDataSet ( )
protectedinherited
Deprecated
since Moodle 3.10 - See MDL-67673 and MDL-64600 for more info.

◆ lti_advantage_user_authenticates()

lti_advantage_testcase::lti_advantage_user_authenticates ( string $sub,
array $migrationclaiminfo = [] )
protected

Helper to return a user which has been bound to the LTI credentials provided and is deemed a valid linked user.

Parameters
string$subthe subject id string
array$migrationclaiminfomocked migration claim information, allowing the mock auth to bind to an existing user.
Return values
stdClassthe user record.

◆ 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

◆ 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.

◆ runBare()

advanced_testcase::runBare ( )
finalinherited

Runs the bare test sequence.

Return values
void

◆ 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)

◆ setup_legacy_data()

lti_advantage_testcase::setup_legacy_data ( \stdClass $course,
array $legacydata )
protected

Set up data representing a several published legacy tools, including tool records, tool consumer maps and a user.

Parameters
stdClass$coursethe course in which to create the tools.
array$legacydataarray containing user id, consumer key and tool secrets for creation of records.
Return values
arrayarray containing [tool1record, tool2record, consumerrecord, userrecord].

◆ 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

◆ 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: