Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

(no description)

File Size: 1422 lines (51 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.

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.

set_test_user_by_role(stdClass $course, string $rolename)   X-Ref
Enrol, set and create the test user depending on the role name.

param: stdClass $course the course data
param: string $rolename the testing role name

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,array $expectedtotals = [],?string $coursefield = null,$coursevalue = 0,?string $sectionfield = null,$sectionvalue = 0,?string $cmfield = null,$cmvalue = 0,?string $targetsection = null,?string $targetcm = null)   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 indexed by put, remove and create
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
param: string|null $targetsection optional target section reference
param: string|null $targetcm optional target cm reference
return: array an array of elements to do extra validations (course, references, results)

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_duplicate(string $targetsection = '',bool $validcms = true,string $role = 'admin',bool $expectedexception = false)   X-Ref
Duplicate course module method.

param: string $targetsection the target section (empty for none)
param: bool $validcms if uses valid cms
param: string $role the current user role name
param: bool $expectedexception if the test will raise an exception

cm_duplicate_provider()   X-Ref
Duplicate course module data provider.

return: array the testing scenarios

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

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

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.

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

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

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

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

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

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

test_section_move_after(array $sectiontomove,string $targetsection,array $finalorder,array $updatedcms,int $totalputs)   X-Ref
Test for section_move_after

param: string[] $sectiontomove the sections to move
param: string $targetsection the target section reference
param: string[] $finalorder the final sections order
param: string[] $updatedcms the list of cms in the state updates
param: int $totalputs the total amount of put updates

section_move_after_provider()   X-Ref
Provider for test_section_move_after.

return: array the testing scenarios

test_section_move_after_capabilities(string $role = 'editingteacher',bool $expectedexception = false)   X-Ref
Test for section_move_after capability checks.

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