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 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 927 lines (33 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: stateactions_test  - X-Ref

Tests for the stateactions class.

setupBeforeClass()   X-Ref
Setup to ensure that fixtures are loaded.


create_activity(int $courseid,string $type,int $section,bool $visible = true)   X-Ref
Helper method to create an activity into a section and add it to the $sections and $activities arrays.

param: int $courseid Course identifier where the activity will be added.
param: string $type Activity type ('forum', 'assign', ...).
param: int $section Section number where the activity will be added.
param: bool $visible Whether the activity will be visible or not.
return: int the activity cm id

create_course(string $format, int $sections, array $hiddensections)   X-Ref
Helper to create a course and generate a section list.

param: string $format the course format
param: int $sections the number of sections
param: int[] $hiddensections the section numbers to hide
return: stdClass the course object

course_references(stdClass $course)   X-Ref
Return an array if the course references.

This method is used to create alias to sections and other stuff in the dataProviders.

param: stdClass $course the course object
return: int[] a relation betwee all references and its element id

translate_references(array $references, array $values)   X-Ref
Translate a references array into current ids.

param: string[] $references the references list
param: string[] $values the values to translate
return: int[] the list of ids

summarize_updates(stateupdates $updateobj)   X-Ref
Generate a sorted and summarized list of an state updates message.

It is important to note that the order in the update messages are not important in a real scenario
because each message affects a specific part of the course state. However, for the PHPUnit test
have them sorted and classified simplifies the asserts.

param: stateupdates $updateobj the state updates object
return: array of all data updates.

test_get_state(string $format,string $role,string $method,array $params,array $expectedresults,bool $expectedexception = false)   X-Ref
Test the behaviour course_state.

param: string $format The course will be created with this course format.
param: string $role The role of the user that will execute the method.
param: string $method the method to call
param: array $params the ids, targetsection and targetcm to use as params
param: array $expectedresults List of the course module names expected after calling the method.
param: bool $expectedexception If this call will raise an exception.

get_state_provider()   X-Ref
Data provider for data request creation tests.

return: array the testing scenarios

course_state_provider(string $format)   X-Ref
Course state data provider.

param: string $format the course format
return: array the testing scenarios

section_state_provider(string $format, string $role)   X-Ref
Section state data provider.

param: string $format the course format
param: string $role the user role
return: array the testing scenarios

cm_state_provider(string $format, string $role)   X-Ref
Course module state data provider.

param: string $format the course format
param: string $role the user role
return: array the testing scenarios

basic_state_text(string $method = 'section_hide',string $role = 'editingteacher',array $idrefs = [],bool $expectedexception = false,int $expectedtotal = 0,?string $coursefield = null,$coursevalue = 0,?string $sectionfield = null,$sectionvalue = 0,?string $cmfield = null,$cmvalue = 0)   X-Ref
Internal method for testing a specific state action.

param: string $method the method to test
param: string $role the user role
param: string[] $idrefs the sections or cms id references to be used as method params
param: bool $expectedexception whether the call should throw an exception
param: int $expectedtotal the expected total number of state puts
param: string|null $coursefield the course field to check
param: int|string|null $coursevalue the section field value
param: string|null $sectionfield the section field to check
param: int|string|null $sectionvalue the section field value
param: string|null $cmfield the cm field to check
param: int|string|null $cmvalue the cm field value
return: array the state update summary

test_section_hide(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for section_hide

param: string $role the user role
param: bool $expectedexception if it will expect an exception.

test_section_show(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for section_hide

param: string $role the user role
param: bool $expectedexception if it will expect an exception.

test_cm_show(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for cm_show

param: string $role the user role
param: bool $expectedexception if it will expect an exception.

test_cm_hide(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for cm_hide

param: string $role the user role
param: bool $expectedexception if it will expect an exception.

test_cm_stealth(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for cm_stealth

param: string $role the user role
param: bool $expectedexception if it will expect an exception.

basic_role_provider()   X-Ref
Data provider for basic role tests.

return: array the testing scenarios

test_cm_moveright(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for cm_moveright

param: string $role the user role
param: bool $expectedexception if it will expect an exception.

test_cm_moveleft(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for cm_moveleft

param: string $role the user role
param: bool $expectedexception if it will expect an exception.