Merge branch 'MDL-86579-main' of https://github.com/aanabit/moodle
This commit is contained in:
@@ -22,14 +22,12 @@ namespace format_singleactivity;
|
||||
* @package format_singleactivity
|
||||
* @copyright 2023 Sara Arjona <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \format_singleactivity
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(\format_singleactivity::class)]
|
||||
final class format_singleactivity_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_view_url().
|
||||
*
|
||||
* @covers ::get_view_url
|
||||
*/
|
||||
public function test_get_view_url(): void {
|
||||
global $CFG;
|
||||
@@ -62,8 +60,6 @@ final class format_singleactivity_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_required_jsfiles().
|
||||
*
|
||||
* @covers ::get_required_jsfiles
|
||||
*/
|
||||
public function test_get_required_jsfiles(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -22,14 +22,12 @@ namespace format_social;
|
||||
* @package format_social
|
||||
* @copyright 2023 Sara Arjona <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \format_social
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(\format_social::class)]
|
||||
final class format_social_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_view_url().
|
||||
*
|
||||
* @covers ::get_view_url
|
||||
*/
|
||||
public function test_get_view_url(): void {
|
||||
global $CFG;
|
||||
@@ -62,8 +60,6 @@ final class format_social_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_required_jsfiles().
|
||||
*
|
||||
* @covers ::get_required_jsfiles
|
||||
*/
|
||||
public function test_get_required_jsfiles(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -110,22 +110,20 @@ final class activityoverviewbase_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_get_completion_overview.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function provider_get_completion_overview(): array {
|
||||
return [
|
||||
'complet' => [
|
||||
'setcompletion' => \COMPLETION_COMPLETE,
|
||||
],
|
||||
'incomplete' => [
|
||||
'setcompletion' => \COMPLETION_INCOMPLETE,
|
||||
],
|
||||
'complete pass' => [
|
||||
'setcompletion' => \COMPLETION_COMPLETE_PASS,
|
||||
],
|
||||
'complete fail' => [
|
||||
'setcompletion' => \COMPLETION_COMPLETE_FAIL,
|
||||
],
|
||||
public static function provider_get_completion_overview(): \Generator {
|
||||
yield 'complet' => [
|
||||
'setcompletion' => \COMPLETION_COMPLETE,
|
||||
];
|
||||
yield 'incomplete' => [
|
||||
'setcompletion' => \COMPLETION_INCOMPLETE,
|
||||
];
|
||||
yield 'complete pass' => [
|
||||
'setcompletion' => \COMPLETION_COMPLETE_PASS,
|
||||
];
|
||||
yield 'complete fail' => [
|
||||
'setcompletion' => \COMPLETION_COMPLETE_FAIL,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -347,55 +345,53 @@ final class activityoverviewbase_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_needs_filtering_by_groups.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function provider_needs_filtering_by_groups(): array {
|
||||
return [
|
||||
'Editing teacher with no groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Editing teacher with visible groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Editing teacher with separate groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non-editing teacher with no groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non-editing teacher with visible groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non-editing teacher with separate groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
],
|
||||
'Student with no groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student with visible groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student with separate groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
],
|
||||
public static function provider_needs_filtering_by_groups(): \Generator {
|
||||
yield 'Editing teacher with no groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Editing teacher with visible groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Editing teacher with separate groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non-editing teacher with no groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non-editing teacher with visible groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non-editing teacher with separate groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Student with no groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student with visible groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student with separate groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -443,55 +439,53 @@ final class activityoverviewbase_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_get_groups_for_filtering.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function provider_get_groups_for_filtering(): array {
|
||||
return [
|
||||
'Editing teacher with no groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => [],
|
||||
],
|
||||
'Editing teacher with visible groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => [],
|
||||
],
|
||||
'Editing teacher with separate groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => [],
|
||||
],
|
||||
'Non-editing teacher with no groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => [],
|
||||
],
|
||||
'Non-editing teacher with visible groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => ['g1', 'g2', 'g3'],
|
||||
],
|
||||
'Non-editing teacher with separate groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => ['g1', 'g2'],
|
||||
],
|
||||
'Student with no groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => [],
|
||||
],
|
||||
'Student with visible groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => ['g1', 'g2', 'g3'],
|
||||
],
|
||||
'Student with separate groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => ['g1', 'g2'],
|
||||
],
|
||||
public static function provider_get_groups_for_filtering(): \Generator {
|
||||
yield 'Editing teacher with no groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => [],
|
||||
];
|
||||
yield 'Editing teacher with visible groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => [],
|
||||
];
|
||||
yield 'Editing teacher with separate groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => [],
|
||||
];
|
||||
yield 'Non-editing teacher with no groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => [],
|
||||
];
|
||||
yield 'Non-editing teacher with visible groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => ['g1', 'g2', 'g3'],
|
||||
];
|
||||
yield 'Non-editing teacher with separate groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => ['g1', 'g2'],
|
||||
];
|
||||
yield 'Student with no groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => [],
|
||||
];
|
||||
yield 'Student with visible groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => ['g1', 'g2', 'g3'],
|
||||
];
|
||||
yield 'Student with separate groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => ['g1', 'g2'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -538,55 +532,53 @@ final class activityoverviewbase_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_has_error.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function provider_has_error(): array {
|
||||
return [
|
||||
'Editing teacher with no groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Editing teacher with visible groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Editing teacher with separate groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non-editing teacher with no groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non-editing teacher with visible groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non-editing teacher with separate groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
],
|
||||
'Student with no groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student with visible groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student with separate groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
],
|
||||
public static function provider_has_error(): \Generator {
|
||||
yield 'Editing teacher with no groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Editing teacher with visible groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Editing teacher with separate groups' => [
|
||||
'role' => 'editingteacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non-editing teacher with no groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non-editing teacher with visible groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non-editing teacher with separate groups' => [
|
||||
'role' => 'teacher',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Student with no groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => NOGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student with visible groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => VISIBLEGROUPS,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student with separate groups' => [
|
||||
'role' => 'student',
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
'expected' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
* @package core_course
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_courseformat\base
|
||||
* @coversDefaultClass \core_courseformat\base
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(core_courseformat\base::class)]
|
||||
final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -200,8 +199,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_view_url().
|
||||
*
|
||||
* @covers ::get_view_url
|
||||
*/
|
||||
public function test_get_view_url(): void {
|
||||
global $CFG;
|
||||
@@ -257,11 +254,11 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Test for get_output_classname method.
|
||||
*
|
||||
* @dataProvider get_output_classname_provider
|
||||
* @param string $find the class to find
|
||||
* @param string $result the expected result classname
|
||||
* @param bool $exception if the method will raise an exception
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('get_output_classname_provider')]
|
||||
public function test_get_output_classname($find, $result, $exception): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -279,32 +276,28 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_get_output_classname.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function get_output_classname_provider(): array {
|
||||
return [
|
||||
'overridden class' => [
|
||||
'find' => 'state\\course',
|
||||
'result' => 'format_theunittest\\output\\courseformat\\state\\course',
|
||||
'exception' => false,
|
||||
],
|
||||
'original class' => [
|
||||
'find' => 'state\\section',
|
||||
'result' => 'core_courseformat\\output\\local\\state\\section',
|
||||
'exception' => false,
|
||||
],
|
||||
'invalid overridden class' => [
|
||||
'find' => 'state\\invalidoutput',
|
||||
'result' => '',
|
||||
'exception' => true,
|
||||
],
|
||||
public static function get_output_classname_provider(): \Generator {
|
||||
yield 'overridden class' => [
|
||||
'find' => 'state\\course',
|
||||
'result' => 'format_theunittest\\output\\courseformat\\state\\course',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'original class' => [
|
||||
'find' => 'state\\section',
|
||||
'result' => 'core_courseformat\\output\\local\\state\\section',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'invalid overridden class' => [
|
||||
'find' => 'state\\invalidoutput',
|
||||
'result' => '',
|
||||
'exception' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the default delete format data behaviour.
|
||||
*
|
||||
* @covers ::get_sections_preferences
|
||||
*/
|
||||
public function test_get_sections_preferences(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -337,8 +330,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for the default delete format data behaviour.
|
||||
*
|
||||
* @covers ::set_sections_preference
|
||||
*/
|
||||
public function test_set_sections_preference(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -367,8 +358,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test add_section_preference_ids() method.
|
||||
*
|
||||
* @covers \core_courseformat\base::persist_to_user_preference
|
||||
*/
|
||||
public function test_add_section_preference_ids(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -398,8 +387,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test remove_section_preference_ids() method.
|
||||
*
|
||||
* @covers \core_courseformat\base::persist_to_user_preference
|
||||
*/
|
||||
public function test_remove_section_preference_ids(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -434,8 +421,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that retrieving last section number for a course
|
||||
*
|
||||
* @covers ::get_last_section_number
|
||||
*/
|
||||
public function test_get_last_section_number(): void {
|
||||
global $DB;
|
||||
@@ -461,10 +446,9 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Test for the default delete format data behaviour.
|
||||
*
|
||||
* @covers ::delete_format_data
|
||||
* @dataProvider delete_format_data_provider
|
||||
* @param bool $usehook if it should use course_delete to trigger $format->delete_format_data as a hook
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('delete_format_data_provider')]
|
||||
public function test_delete_format_data(bool $usehook): void {
|
||||
global $DB;
|
||||
|
||||
@@ -514,22 +498,19 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_delete_format_data.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function delete_format_data_provider(): array {
|
||||
return [
|
||||
'direct call' => [
|
||||
'usehook' => false
|
||||
],
|
||||
'use hook' => [
|
||||
'usehook' => true,
|
||||
]
|
||||
public static function delete_format_data_provider(): \Generator {
|
||||
yield 'direct call' => [
|
||||
'usehook' => false,
|
||||
];
|
||||
yield 'use hook' => [
|
||||
'usehook' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test duplicate_section()
|
||||
* @covers ::duplicate_section
|
||||
*/
|
||||
public function test_duplicate_section(): void {
|
||||
global $DB;
|
||||
@@ -572,7 +553,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test duplicate_section() with delegated section
|
||||
* @covers ::duplicate_section
|
||||
*/
|
||||
public function test_duplicate_section_with_delegated_sections(): void {
|
||||
global $DB;
|
||||
@@ -612,13 +592,12 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Test for the default delete format data behaviour.
|
||||
*
|
||||
* @covers ::get_format_string
|
||||
* @dataProvider get_format_string_provider
|
||||
* @param string $key the string key
|
||||
* @param string|null $data any string data
|
||||
* @param array|null $expectedstring the expected string (null for exception)
|
||||
* @param string $courseformat the course format
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('get_format_string_provider')]
|
||||
public function test_get_format_string(
|
||||
string $key,
|
||||
?string $data,
|
||||
@@ -645,48 +624,45 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_get_format_string.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function get_format_string_provider(): array {
|
||||
return [
|
||||
'Existing in format lang' => [
|
||||
'key' => 'addsection',
|
||||
'data' => null,
|
||||
'expectedstring' => ['addsection', 'format_weeks', null],
|
||||
'courseformat' => 'weeks',
|
||||
],
|
||||
'Not existing in format lang' => [
|
||||
'key' => 'bulkedit',
|
||||
'data' => null,
|
||||
'expectedstring' => ['bulkedit', 'core_courseformat', null],
|
||||
],
|
||||
'Existing in format lang with data' => [
|
||||
'key' => 'section_highlight_feedback',
|
||||
'data' => 'Example',
|
||||
'expectedstring' => ['section_highlight_feedback', 'format_topics', 'Example'],
|
||||
],
|
||||
'Not existing in format lang with data' => [
|
||||
'key' => 'bulkselection',
|
||||
'data' => 'X',
|
||||
'expectedstring' => ['bulkselection', 'core_courseformat', 'X'],
|
||||
],
|
||||
'Non existing string' => [
|
||||
'key' => '%&non_existing_string_in_lang_files$%@#',
|
||||
'data' => null,
|
||||
'expectedstring' => null,
|
||||
],
|
||||
public static function get_format_string_provider(): \Generator {
|
||||
yield 'Existing in format lang' => [
|
||||
'key' => 'addsection',
|
||||
'data' => null,
|
||||
'expectedstring' => ['addsection', 'format_weeks', null],
|
||||
'courseformat' => 'weeks',
|
||||
];
|
||||
yield 'Not existing in format lang' => [
|
||||
'key' => 'bulkedit',
|
||||
'data' => null,
|
||||
'expectedstring' => ['bulkedit', 'core_courseformat', null],
|
||||
];
|
||||
yield 'Existing in format lang with data' => [
|
||||
'key' => 'section_highlight_feedback',
|
||||
'data' => 'Example',
|
||||
'expectedstring' => ['section_highlight_feedback', 'format_topics', 'Example'],
|
||||
];
|
||||
yield 'Not existing in format lang with data' => [
|
||||
'key' => 'bulkselection',
|
||||
'data' => 'X',
|
||||
'expectedstring' => ['bulkselection', 'core_courseformat', 'X'],
|
||||
];
|
||||
yield 'Non existing string' => [
|
||||
'key' => '%&non_existing_string_in_lang_files$%@#',
|
||||
'data' => null,
|
||||
'expectedstring' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the move_section_after method.
|
||||
*
|
||||
* @covers ::move_section_after
|
||||
* @dataProvider move_section_after_provider
|
||||
* @param string $movesection the reference of the section to move
|
||||
* @param string $destination the reference of the destination section
|
||||
* @param string[] $order the references of the final section order
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('move_section_after_provider')]
|
||||
public function test_move_section_after(string $movesection, string $destination, array $order): void {
|
||||
global $DB;
|
||||
|
||||
@@ -724,81 +700,79 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_move_section_after.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function move_section_after_provider(): array {
|
||||
return [
|
||||
'Move top' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section0',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section3',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
public static function move_section_after_provider(): \Generator {
|
||||
yield 'Move top' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section0',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section3',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
'Move up' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section1',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section2',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
];
|
||||
yield 'Move up' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section1',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section2',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
'Do not move' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section2',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section3',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
];
|
||||
yield 'Do not move' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section2',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section3',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
'Same position' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section3',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section3',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
];
|
||||
yield 'Same position' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section3',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section3',
|
||||
'section4',
|
||||
'section5',
|
||||
],
|
||||
'Move down' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section4',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section3',
|
||||
'section5',
|
||||
],
|
||||
];
|
||||
yield 'Move down' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section4',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section3',
|
||||
'section5',
|
||||
],
|
||||
'Move bottom' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section5',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section5',
|
||||
'section3',
|
||||
],
|
||||
];
|
||||
yield 'Move bottom' => [
|
||||
'movesection' => 'section3',
|
||||
'destination' => 'section5',
|
||||
'order' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section5',
|
||||
'section3',
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -806,12 +780,11 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Test for the get_non_ajax_cm_action_url method.
|
||||
*
|
||||
* @covers ::get_non_ajax_cm_action_url
|
||||
* @dataProvider get_non_ajax_cm_action_url_provider
|
||||
* @param string $action the ajax action name
|
||||
* @param string $expectedparam the expected param to check
|
||||
* @param string $exception if an exception is expected
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('get_non_ajax_cm_action_url_provider')]
|
||||
public function test_get_non_ajax_cm_action_url(string $action, string $expectedparam, bool $exception): void {
|
||||
global $DB;
|
||||
|
||||
@@ -838,47 +811,43 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_get_non_ajax_cm_action_url.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function get_non_ajax_cm_action_url_provider(): array {
|
||||
return [
|
||||
'duplicate' => [
|
||||
'action' => 'cmDuplicate',
|
||||
'expectedparam' => 'duplicate',
|
||||
'exception' => false,
|
||||
],
|
||||
'hide' => [
|
||||
'action' => 'cmHide',
|
||||
'expectedparam' => 'hide',
|
||||
'exception' => false,
|
||||
],
|
||||
'show' => [
|
||||
'action' => 'cmShow',
|
||||
'expectedparam' => 'show',
|
||||
'exception' => false,
|
||||
],
|
||||
'stealth' => [
|
||||
'action' => 'cmStealth',
|
||||
'expectedparam' => 'stealth',
|
||||
'exception' => false,
|
||||
],
|
||||
'delete' => [
|
||||
'action' => 'cmDelete',
|
||||
'expectedparam' => 'delete',
|
||||
'exception' => false,
|
||||
],
|
||||
'non-existent' => [
|
||||
'action' => 'nonExistent',
|
||||
'expectedparam' => '',
|
||||
'exception' => true,
|
||||
],
|
||||
public static function get_non_ajax_cm_action_url_provider(): \Generator {
|
||||
yield 'duplicate' => [
|
||||
'action' => 'cmDuplicate',
|
||||
'expectedparam' => 'duplicate',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'hide' => [
|
||||
'action' => 'cmHide',
|
||||
'expectedparam' => 'hide',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'show' => [
|
||||
'action' => 'cmShow',
|
||||
'expectedparam' => 'show',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'stealth' => [
|
||||
'action' => 'cmStealth',
|
||||
'expectedparam' => 'stealth',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'delete' => [
|
||||
'action' => 'cmDelete',
|
||||
'expectedparam' => 'delete',
|
||||
'exception' => false,
|
||||
];
|
||||
yield 'non-existent' => [
|
||||
'action' => 'nonExistent',
|
||||
'expectedparam' => '',
|
||||
'exception' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_required_jsfiles().
|
||||
*
|
||||
* @covers ::get_required_jsfiles
|
||||
*/
|
||||
public function test_get_required_jsfiles(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -892,10 +861,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test set_sectionid().
|
||||
*
|
||||
* @covers ::set_sectionid
|
||||
* @covers ::get_sectionid
|
||||
* @covers ::get_sectionnum
|
||||
*/
|
||||
public function test_set_sectionid(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -930,12 +895,11 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Test set_sectionnum().
|
||||
*
|
||||
* @dataProvider set_sectionnum_provider
|
||||
* @covers ::set_sectionnum
|
||||
* @param int|null $sectionnum The section number
|
||||
* @param bool $nullexpected If null is expected
|
||||
* @param bool $exceptionexpected If an exception is expected
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('set_sectionnum_provider')]
|
||||
public function test_set_sectionnum(?int $sectionnum, bool $nullexpected = false, bool $exceptionexpected = false): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -959,43 +923,39 @@ final class base_test extends advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_set_sectionnum.
|
||||
*
|
||||
* @return array The testing scenarios
|
||||
* @return \Generator The testing scenarios
|
||||
*/
|
||||
public static function set_sectionnum_provider(): array {
|
||||
return [
|
||||
'General sectionnumber' => [
|
||||
'sectionnum' => 0,
|
||||
'nullexpected' => false,
|
||||
],
|
||||
'Existing sectionnumber' => [
|
||||
'sectionnum' => 1,
|
||||
'nullexpected' => false,
|
||||
],
|
||||
'Another existing sectionnumber' => [
|
||||
'sectionnum' => 2,
|
||||
'nullexpected' => false,
|
||||
],
|
||||
'Null sectionnumber' => [
|
||||
'sectionnum' => null,
|
||||
'nullexpected' => true,
|
||||
],
|
||||
'Invalid sectionnumber' => [
|
||||
'sectionnum' => 3,
|
||||
'nullexpected' => true,
|
||||
'exceptionexpected' => true,
|
||||
],
|
||||
'Another invalid sectionnumber' => [
|
||||
'sectionnum' => -1,
|
||||
'nullexpected' => true,
|
||||
'exceptionexpected' => true,
|
||||
],
|
||||
public static function set_sectionnum_provider(): \Generator {
|
||||
yield 'General sectionnumber' => [
|
||||
'sectionnum' => 0,
|
||||
'nullexpected' => false,
|
||||
];
|
||||
yield 'Existing sectionnumber' => [
|
||||
'sectionnum' => 1,
|
||||
'nullexpected' => false,
|
||||
];
|
||||
yield 'Another existing sectionnumber' => [
|
||||
'sectionnum' => 2,
|
||||
'nullexpected' => false,
|
||||
];
|
||||
yield 'Null sectionnumber' => [
|
||||
'sectionnum' => null,
|
||||
'nullexpected' => true,
|
||||
];
|
||||
yield 'Invalid sectionnumber' => [
|
||||
'sectionnum' => 3,
|
||||
'nullexpected' => true,
|
||||
'exceptionexpected' => true,
|
||||
];
|
||||
yield 'Another invalid sectionnumber' => [
|
||||
'sectionnum' => -1,
|
||||
'nullexpected' => true,
|
||||
'exceptionexpected' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test can_sections_be_removed_from_navigation().
|
||||
*
|
||||
* @covers ::can_sections_be_removed_from_navigation
|
||||
*/
|
||||
public function test_can_sections_be_removed_from_navigation(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1045,8 +1005,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for the get_generic_section_name method.
|
||||
*
|
||||
* @covers ::get_generic_section_name
|
||||
*/
|
||||
public function test_get_generic_section_name(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1070,11 +1028,6 @@ final class base_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test can_sections_be_removed_from_navigation().
|
||||
*
|
||||
* @covers ::session_cache
|
||||
* @covers ::session_cache_reset
|
||||
* @covers ::session_cache_reset_all
|
||||
* @covers ::invalidate_all_session_caches_for_course
|
||||
*/
|
||||
public function test_session_caches_methods(): void {
|
||||
global $DB;
|
||||
|
||||
@@ -28,8 +28,8 @@ use stdClass;
|
||||
* @category test
|
||||
* @copyright 2024 Mikel Martín <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\external\create_module
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(create_module::class)]
|
||||
final class create_module_test extends \core_external\tests\externallib_testcase {
|
||||
#[\Override]
|
||||
public static function setUpBeforeClass(): void {
|
||||
@@ -42,8 +42,6 @@ final class create_module_test extends \core_external\tests\externallib_testcase
|
||||
|
||||
/**
|
||||
* Test the webservice can execute the create_module action.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -72,8 +70,6 @@ final class create_module_test extends \core_external\tests\externallib_testcase
|
||||
|
||||
/**
|
||||
* Test the webservice can execute the create_module action with a format override.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute_with_format_override(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -97,8 +93,6 @@ final class create_module_test extends \core_external\tests\externallib_testcase
|
||||
|
||||
/**
|
||||
* Test the webservice can execute the create_module action with an invalid module.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute_with_invalid_module(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
+18
-21
@@ -28,20 +28,19 @@ use core_courseformat\stateupdates;
|
||||
* @copyright 2025 Laurent David <[email protected]>
|
||||
* @category test
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\stateactions
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(stateactions::class)]
|
||||
final class delete_section_test extends \core_external\tests\externallib_testcase {
|
||||
/**
|
||||
* Test the webservice can execute the section_delete action.
|
||||
*
|
||||
* @covers ::section_delete
|
||||
* @dataProvider section_delete_provider
|
||||
* @param int $sectionum
|
||||
* @param string $format
|
||||
* @param int $expectedsectionum
|
||||
*
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('section_delete_provider')]
|
||||
public function test_delete_section(int $sectionum, string $format, int $expectedsectionum): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -72,25 +71,23 @@ final class delete_section_test extends \core_external\tests\externallib_testcas
|
||||
/**
|
||||
* Data provider for the test_delete_section method.
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function section_delete_provider(): array {
|
||||
return [
|
||||
'format topic' => [
|
||||
'sectionum' => 4,
|
||||
'format' => 'topics',
|
||||
'expectedsectionum' => 1,
|
||||
],
|
||||
'format weeks' => [
|
||||
'sectionum' => 4,
|
||||
'format' => 'weeks',
|
||||
'expectedsectionum' => 1,
|
||||
],
|
||||
'format social' => [
|
||||
'sectionum' => 4,
|
||||
'format' => 'social',
|
||||
'expectedsectionum' => 5,
|
||||
],
|
||||
public static function section_delete_provider(): \Generator {
|
||||
yield 'format topic' => [
|
||||
'sectionum' => 4,
|
||||
'format' => 'topics',
|
||||
'expectedsectionum' => 1,
|
||||
];
|
||||
yield 'format weeks' => [
|
||||
'sectionum' => 4,
|
||||
'format' => 'weeks',
|
||||
'expectedsectionum' => 1,
|
||||
];
|
||||
yield 'format social' => [
|
||||
'sectionum' => 4,
|
||||
'format' => 'social',
|
||||
'expectedsectionum' => 5,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ use core_external\external_api;
|
||||
* @category test
|
||||
* @copyright 2022 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\external\file_handlers
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(file_handlers::class)]
|
||||
final class file_handlers_test extends \core_external\tests\externallib_testcase {
|
||||
|
||||
@@ -17,23 +17,19 @@
|
||||
namespace core_courseformat\external;
|
||||
|
||||
use core_external\external_api;
|
||||
use core_external\tests\externallib_testcase;
|
||||
use section_info;
|
||||
use stdClass;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
|
||||
|
||||
/**
|
||||
* Tests for courseformat get_section_content_items web service.
|
||||
*
|
||||
* @package core_courseformat
|
||||
* @copyright 2025 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_courseformat\external\get_section_content_items
|
||||
*/
|
||||
final class get_section_content_items_test extends \externallib_advanced_testcase {
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(get_section_content_items::class)]
|
||||
final class get_section_content_items_test extends externallib_testcase {
|
||||
/**
|
||||
* Test the web service returning course content items for inclusion in activity choosers, etc.
|
||||
*/
|
||||
|
||||
+71
-75
@@ -25,8 +25,8 @@ use core_external\external_api;
|
||||
* @category test
|
||||
* @copyright 2021 Sara Arjona ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\external\get_state
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(get_state::class)]
|
||||
final class get_state_test extends \core_external\tests\externallib_testcase {
|
||||
/** @var array Sections in the testing course. */
|
||||
private $sections;
|
||||
@@ -68,13 +68,11 @@ final class get_state_test extends \core_external\tests\externallib_testcase {
|
||||
/**
|
||||
* Test the behaviour of get_state::execute().
|
||||
*
|
||||
* @dataProvider get_state_provider
|
||||
* @covers ::execute
|
||||
*
|
||||
* @param string $role The role of the user that will execute the method.
|
||||
* @param string $format The course format of the course where the method will be executed.
|
||||
* @param string|null $expectedexception If this call will raise an exception, this is its name.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('get_state_provider')]
|
||||
public function test_get_state(string $role, string $format = 'topics', ?string $expectedexception = null): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -183,79 +181,77 @@ final class get_state_test extends \core_external\tests\externallib_testcase {
|
||||
/**
|
||||
* Data provider for test_get_state().
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function get_state_provider(): array {
|
||||
return [
|
||||
// ROLES. Testing behaviour depending on the user role calling the method.
|
||||
'Admin user should work' => [
|
||||
'role' => 'admin',
|
||||
],
|
||||
'Editing teacher should work' => [
|
||||
'role' => 'editingteacher',
|
||||
],
|
||||
'Student should work' => [
|
||||
'role' => 'student',
|
||||
],
|
||||
'Unenroled user should raise an exception' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'topics',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
],
|
||||
public static function get_state_provider(): \Generator {
|
||||
// ROLES. Testing behaviour depending on the user role calling the method.
|
||||
yield 'Admin user should work' => [
|
||||
'role' => 'admin',
|
||||
];
|
||||
yield 'Editing teacher should work' => [
|
||||
'role' => 'editingteacher',
|
||||
];
|
||||
yield 'Student should work' => [
|
||||
'role' => 'student',
|
||||
];
|
||||
yield 'Unenroled user should raise an exception' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'topics',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
];
|
||||
|
||||
// COURSEFORMAT. Test behaviour depending on course formats.
|
||||
'Single activity format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'singleactivity',
|
||||
],
|
||||
'Social format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'social',
|
||||
],
|
||||
'Weeks format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'weeks',
|
||||
],
|
||||
'The unit tests format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'theunittest',
|
||||
],
|
||||
'Single activity format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'singleactivity',
|
||||
],
|
||||
'Social format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'social',
|
||||
],
|
||||
'Weeks format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'weeks',
|
||||
],
|
||||
'The unit tests format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'theunittest',
|
||||
],
|
||||
'Single activity format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'singleactivity',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
],
|
||||
'Social format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'social',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
],
|
||||
'Weeks format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'weeks',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
],
|
||||
'The unit tests format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'theunittest',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
],
|
||||
// COURSEFORMAT. Test behaviour depending on course formats.
|
||||
yield 'Single activity format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'singleactivity',
|
||||
];
|
||||
yield 'Social format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'social',
|
||||
];
|
||||
yield 'Weeks format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'weeks',
|
||||
];
|
||||
yield 'The unit tests format should work (admin)' => [
|
||||
'role' => 'admin',
|
||||
'format' => 'theunittest',
|
||||
];
|
||||
yield 'Single activity format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'singleactivity',
|
||||
];
|
||||
yield 'Social format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'social',
|
||||
];
|
||||
yield 'Weeks format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'weeks',
|
||||
];
|
||||
yield 'The unit tests format should work (student)' => [
|
||||
'role' => 'student',
|
||||
'format' => 'theunittest',
|
||||
];
|
||||
yield 'Single activity format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'singleactivity',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
];
|
||||
yield 'Social format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'social',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
];
|
||||
yield 'Weeks format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'weeks',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
];
|
||||
yield 'The unit tests format should raise an exception (unenroled)' => [
|
||||
'role' => 'unenroled',
|
||||
'format' => 'theunittest',
|
||||
'expectedexception' => 'moodle_exception',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+1
-7
@@ -28,8 +28,8 @@ use stdClass;
|
||||
* @category test
|
||||
* @copyright 2024 Mikel Martín <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\external\new_module
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(new_module::class)]
|
||||
final class new_module_test extends \core_external\tests\externallib_testcase {
|
||||
#[\Override]
|
||||
public static function setUpBeforeClass(): void {
|
||||
@@ -43,8 +43,6 @@ final class new_module_test extends \core_external\tests\externallib_testcase {
|
||||
|
||||
/**
|
||||
* Test the webservice can execute the new_module action.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -75,8 +73,6 @@ final class new_module_test extends \core_external\tests\externallib_testcase {
|
||||
|
||||
/**
|
||||
* Test the webservice can execute the new_module action with a format override.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute_with_format_override(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -105,8 +101,6 @@ final class new_module_test extends \core_external\tests\externallib_testcase {
|
||||
|
||||
/**
|
||||
* Test the webservice can execute the new_module action with an invalid module.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute_with_invalid_module(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -23,17 +23,17 @@ namespace core_courseformat\external;
|
||||
* @category test
|
||||
* @copyright 2025 Sara Arjona <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_courseformat\external\overviewaction_exporter
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(overviewaction_exporter::class)]
|
||||
final class overviewaction_exporter_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test the export returns the right structure when the content is a string.
|
||||
*
|
||||
* @dataProvider provider_test_export
|
||||
* @param string|null $badgevalue The value of the badge.
|
||||
* @param string|null $badgetitle The title of the badge.
|
||||
* @param \core\output\local\properties\badge|null $badgestyle The style of the badge.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_export')]
|
||||
public function test_export(
|
||||
?string $badgevalue = null,
|
||||
?string $badgetitle = null,
|
||||
@@ -90,29 +90,26 @@ final class overviewaction_exporter_test extends \advanced_testcase {
|
||||
/**
|
||||
* Provider for test_export.
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function provider_test_export(): array {
|
||||
return [
|
||||
'All badge fields' => [
|
||||
'badgevalue' => '5',
|
||||
'badgetitle' => 'New items',
|
||||
'badgestyle' => \core\output\local\properties\badge::SUCCESS,
|
||||
],
|
||||
'No badge' => [
|
||||
],
|
||||
'Badge without value (equivalent to no badge)' => [
|
||||
'badgetitle' => 'New items',
|
||||
'badgestyle' => \core\output\local\properties\badge::SUCCESS,
|
||||
],
|
||||
'Badge without title' => [
|
||||
'badgevalue' => '5',
|
||||
'badgestyle' => \core\output\local\properties\badge::SUCCESS,
|
||||
],
|
||||
'Badge without style (defaults to PRIMARY)' => [
|
||||
'badgevalue' => '5',
|
||||
'badgetitle' => 'New items',
|
||||
],
|
||||
public static function provider_test_export(): \Generator {
|
||||
yield 'All badge fields' => [
|
||||
'badgevalue' => '5',
|
||||
'badgetitle' => 'New items',
|
||||
'badgestyle' => \core\output\local\properties\badge::SUCCESS,
|
||||
];
|
||||
yield 'No badge' => [];
|
||||
yield 'Badge without value (equivalent to no badge)' => [
|
||||
'badgetitle' => 'New items',
|
||||
'badgestyle' => \core\output\local\properties\badge::SUCCESS,
|
||||
];
|
||||
yield 'Badge without title' => [
|
||||
'badgevalue' => '5',
|
||||
'badgestyle' => \core\output\local\properties\badge::SUCCESS,
|
||||
];
|
||||
yield 'Badge without style (defaults to PRIMARY)' => [
|
||||
'badgevalue' => '5',
|
||||
'badgetitle' => 'New items',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+40
-49
@@ -26,8 +26,8 @@ use stdClass;
|
||||
* @category test
|
||||
* @copyright 2021 Sara Arjona ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\external\update_course
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(update_course::class)]
|
||||
final class update_course_test extends \core_external\tests\externallib_testcase {
|
||||
#[\Override]
|
||||
public static function setUpBeforeClass(): void {
|
||||
@@ -40,15 +40,13 @@ final class update_course_test extends \core_external\tests\externallib_testcase
|
||||
/**
|
||||
* Test the webservice can execute a core state action (cm_state).
|
||||
*
|
||||
* @dataProvider execute_course_state_provider
|
||||
* @covers ::execute
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param string $action the state action name
|
||||
* @param array $expected the expected results
|
||||
* @param bool $expectexception if an exception should happen.
|
||||
* @param bool $assertdebug if an debug message should happen.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('execute_course_state_provider')]
|
||||
public function test_execute_course_state(
|
||||
string $format,
|
||||
string $action,
|
||||
@@ -93,50 +91,48 @@ final class update_course_test extends \core_external\tests\externallib_testcase
|
||||
/**
|
||||
* Data provider for test_execute_course_state
|
||||
*
|
||||
* @return array of testing scenarios
|
||||
* @return \Generator of testing scenarios
|
||||
*/
|
||||
public static function execute_course_state_provider(): array {
|
||||
return [
|
||||
'Execute a core state action (cm_state)' => [
|
||||
'format' => 'topics',
|
||||
'action' => 'cm_state',
|
||||
'expected' => [
|
||||
'count' => 2,
|
||||
'action' => 'put',
|
||||
'visible' => 1,
|
||||
],
|
||||
'expectexception' => false,
|
||||
'assertdebug' => false,
|
||||
public static function execute_course_state_provider(): \Generator {
|
||||
yield 'Execute a core state action (cm_state)' => [
|
||||
'format' => 'topics',
|
||||
'action' => 'cm_state',
|
||||
'expected' => [
|
||||
'count' => 2,
|
||||
'action' => 'put',
|
||||
'visible' => 1,
|
||||
],
|
||||
'Formats can override core state actions' => [
|
||||
'format' => 'theunittest',
|
||||
'action' => 'cm_state',
|
||||
'expected' => [
|
||||
'count' => 1,
|
||||
'action' => 'create',
|
||||
'visible' => 1,
|
||||
],
|
||||
'expectexception' => false,
|
||||
'assertdebug' => true,
|
||||
'expectexception' => false,
|
||||
'assertdebug' => false,
|
||||
];
|
||||
yield 'Formats can override core state actions' => [
|
||||
'format' => 'theunittest',
|
||||
'action' => 'cm_state',
|
||||
'expected' => [
|
||||
'count' => 1,
|
||||
'action' => 'create',
|
||||
'visible' => 1,
|
||||
],
|
||||
'Formats can create new state actions' => [
|
||||
'format' => 'theunittest',
|
||||
'action' => 'format_do_something',
|
||||
'expected' => [
|
||||
'count' => 1,
|
||||
'action' => 'remove',
|
||||
'visible' => null,
|
||||
],
|
||||
'expectexception' => false,
|
||||
'assertdebug' => true,
|
||||
],
|
||||
'Innexisting state action' => [
|
||||
'format' => 'topics',
|
||||
'action' => 'Wrong_State_Action_Name',
|
||||
'expected' => [],
|
||||
'expectexception' => true,
|
||||
'assertdebug' => false,
|
||||
'expectexception' => false,
|
||||
'assertdebug' => true,
|
||||
];
|
||||
yield 'Formats can create new state actions' => [
|
||||
'format' => 'theunittest',
|
||||
'action' => 'format_do_something',
|
||||
'expected' => [
|
||||
'count' => 1,
|
||||
'action' => 'remove',
|
||||
'visible' => null,
|
||||
],
|
||||
'expectexception' => false,
|
||||
'assertdebug' => true,
|
||||
];
|
||||
yield 'Innexisting state action' => [
|
||||
'format' => 'topics',
|
||||
'action' => 'Wrong_State_Action_Name',
|
||||
'expected' => [],
|
||||
'expectexception' => true,
|
||||
'assertdebug' => false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -171,9 +167,6 @@ final class update_course_test extends \core_external\tests\externallib_testcase
|
||||
|
||||
/**
|
||||
* Test a wrong course id.
|
||||
*
|
||||
* @covers ::execute
|
||||
*
|
||||
*/
|
||||
public function test_execute_wrong_courseid(): void {
|
||||
|
||||
@@ -194,8 +187,6 @@ final class update_course_test extends \core_external\tests\externallib_testcase
|
||||
|
||||
/**
|
||||
* Test target params are passed to the state actions.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_execute_target_params(): void {
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace core_courseformat;
|
||||
* @package core_courseformat
|
||||
* @copyright 2023 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\formatactions
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(formatactions::class)]
|
||||
final class formatactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -40,11 +40,11 @@ final class formatactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_instance static method.
|
||||
* @dataProvider provider_classname_action
|
||||
* @covers ::instance
|
||||
*
|
||||
* @param string $format
|
||||
* @param array $classnames
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('provider_classname_action')]
|
||||
public function test_instance(string $format, array $classnames): void {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course(['format' => $format]);
|
||||
@@ -66,11 +66,11 @@ final class formatactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the course action instance is created correctly.
|
||||
* @dataProvider provider_classname_action
|
||||
* @covers ::course
|
||||
*
|
||||
* @param string $format
|
||||
* @param array $classnames
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('provider_classname_action')]
|
||||
public function test_course_action_instance(string $format, array $classnames): void {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course(['format' => $format]);
|
||||
@@ -84,12 +84,11 @@ final class formatactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the section action instance is created correctly.
|
||||
* @dataProvider provider_classname_action
|
||||
* @covers ::section
|
||||
*
|
||||
* @param string $format
|
||||
* @param array $classnames
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('provider_classname_action')]
|
||||
public function test_static_sectionactions_instance(string $format, array $classnames): void {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course(['format' => $format]);
|
||||
@@ -103,12 +102,11 @@ final class formatactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the cm action instance is created correctly.
|
||||
* @dataProvider provider_classname_action
|
||||
* @covers ::cm
|
||||
*
|
||||
* @param string $format
|
||||
* @param array $classnames
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('provider_classname_action')]
|
||||
public function test_static_cmactions_instance(string $format, array $classnames): void {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course(['format' => $format]);
|
||||
@@ -122,25 +120,23 @@ final class formatactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for format class names scenarios.
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function provider_classname_action(): array {
|
||||
return [
|
||||
'Topics format' => [
|
||||
'format' => 'topics',
|
||||
'classnames' => [
|
||||
'course' => '\core_courseformat\local\courseactions',
|
||||
'section' => '\core_courseformat\local\sectionactions',
|
||||
'cm' => '\core_courseformat\local\cmactions',
|
||||
],
|
||||
public static function provider_classname_action(): \Generator {
|
||||
yield 'Topics format' => [
|
||||
'format' => 'topics',
|
||||
'classnames' => [
|
||||
'course' => '\core_courseformat\local\courseactions',
|
||||
'section' => '\core_courseformat\local\sectionactions',
|
||||
'cm' => '\core_courseformat\local\cmactions',
|
||||
],
|
||||
'The unit test fixture format' => [
|
||||
'format' => 'theunittest',
|
||||
'classnames' => [
|
||||
'course' => '\format_theunittest\courseformat\courseactions',
|
||||
'section' => '\format_theunittest\courseformat\sectionactions',
|
||||
'cm' => '\format_theunittest\courseformat\cmactions',
|
||||
],
|
||||
];
|
||||
yield 'The unit test fixture format' => [
|
||||
'format' => 'theunittest',
|
||||
'classnames' => [
|
||||
'course' => '\format_theunittest\courseformat\courseactions',
|
||||
'section' => '\format_theunittest\courseformat\sectionactions',
|
||||
'cm' => '\format_theunittest\courseformat\cmactions',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ use cm_info;
|
||||
* @package core_courseformat
|
||||
* @copyright 2023 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\local\baseactions
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(baseactions::class)]
|
||||
final class baseactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Setup to ensure that fixtures are loaded.
|
||||
@@ -51,7 +51,6 @@ final class baseactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_instance static method.
|
||||
* @covers ::get_format
|
||||
*/
|
||||
public function test_get_format(): void {
|
||||
global $DB;
|
||||
@@ -77,7 +76,6 @@ final class baseactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_instance static method.
|
||||
* @covers ::get_section_info
|
||||
*/
|
||||
public function test_get_section_info(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -112,7 +110,6 @@ final class baseactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_instance static method.
|
||||
* @covers ::get_cm_info
|
||||
*/
|
||||
public function test_get_cm_info(): void {
|
||||
global $DB;
|
||||
|
||||
@@ -39,14 +39,12 @@ final class cmactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test renaming a course module.
|
||||
*
|
||||
* @dataProvider provider_test_rename
|
||||
* @covers ::rename
|
||||
* @param string $newname The new name for the course module.
|
||||
* @param bool $expected Whether the course module was renamed.
|
||||
* @param bool $expectexception Whether an exception is expected.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_rename')]
|
||||
public function test_rename(string $newname, bool $expected, bool $expectexception): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['format' => 'topics']);
|
||||
@@ -74,37 +72,33 @@ final class cmactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_rename.
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function provider_test_rename(): array {
|
||||
return [
|
||||
'Empty name' => [
|
||||
'newname' => '',
|
||||
'expected' => false,
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Maximum length' => [
|
||||
'newname' => str_repeat('a', 1333),
|
||||
'expected' => true,
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Beyond maximum length' => [
|
||||
'newname' => str_repeat('a', 1334),
|
||||
'expected' => false,
|
||||
'expectexception' => true,
|
||||
],
|
||||
'Valid name' => [
|
||||
'newname' => 'New name',
|
||||
'expected' => true,
|
||||
'expectexception' => false,
|
||||
],
|
||||
public static function provider_test_rename(): \Generator {
|
||||
yield 'Empty name' => [
|
||||
'newname' => '',
|
||||
'expected' => false,
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Maximum length' => [
|
||||
'newname' => str_repeat('a', 1333),
|
||||
'expected' => true,
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Beyond maximum length' => [
|
||||
'newname' => str_repeat('a', 1334),
|
||||
'expected' => false,
|
||||
'expectexception' => true,
|
||||
];
|
||||
yield 'Valid name' => [
|
||||
'newname' => 'New name',
|
||||
'expected' => true,
|
||||
'expectexception' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test rename an activity also rename the calendar events.
|
||||
*
|
||||
* @covers ::rename
|
||||
*/
|
||||
public function test_rename_calendar_events(): void {
|
||||
global $DB;
|
||||
@@ -173,8 +167,6 @@ final class cmactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test renaming an activity trigger a course update log event.
|
||||
*
|
||||
* @covers ::rename
|
||||
*/
|
||||
public function test_rename_course_module_updated_event(): void {
|
||||
global $DB;
|
||||
@@ -202,7 +194,6 @@ final class cmactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test renaming an activity triggers the after_cm_name_edited hook.
|
||||
* @covers ::rename
|
||||
*/
|
||||
public function test_rename_after_cm_name_edited_hook(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -24,8 +24,8 @@ use stdClass;
|
||||
* @package core_courseformat
|
||||
* @copyright 2023 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\local\sectionactions
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(sectionactions::class)]
|
||||
final class sectionactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Setup to ensure that fixtures are loaded.
|
||||
@@ -38,12 +38,12 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for create_delegated method.
|
||||
* @covers ::create_delegated
|
||||
* @dataProvider create_delegated_provider
|
||||
*
|
||||
* @param string $component the name of the plugin
|
||||
* @param int|null $itemid the id of the delegated section
|
||||
* @param stdClass|null $fields the fields to set on the section
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('create_delegated_provider')]
|
||||
public function test_create_delegated(string $component, ?int $itemid, ?stdClass $fields): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
@@ -64,72 +64,70 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for test_create_delegated.
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function create_delegated_provider(): array {
|
||||
return [
|
||||
'component with no itemid or fields' => [
|
||||
'mod_assign',
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'component with itemid but no fields' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
null,
|
||||
],
|
||||
'component with itemid and empty fields' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
new stdClass(),
|
||||
],
|
||||
'component with itemid and name field' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['name' => 'new name'],
|
||||
],
|
||||
'component with no itemid but name field' => [
|
||||
'mod_assign',
|
||||
null,
|
||||
(object) ['name' => 'new name'],
|
||||
],
|
||||
'component with itemid and summary' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['summary' => 'summary'],
|
||||
],
|
||||
'component with itemid and summary, summaryformat ' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['summary' => 'summary', 'summaryformat' => 1],
|
||||
],
|
||||
'component with itemid and section number' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['section' => 2],
|
||||
],
|
||||
'component with itemid and visible 1' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['visible' => 1],
|
||||
],
|
||||
'component with itemid and visible 0' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['visible' => 0],
|
||||
],
|
||||
public static function create_delegated_provider(): \Generator {
|
||||
yield 'component with no itemid or fields' => [
|
||||
'mod_assign',
|
||||
null,
|
||||
null,
|
||||
];
|
||||
yield 'component with itemid but no fields' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
null,
|
||||
];
|
||||
yield 'component with itemid and empty fields' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
new stdClass(),
|
||||
];
|
||||
yield 'component with itemid and name field' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['name' => 'new name'],
|
||||
];
|
||||
yield 'component with no itemid but name field' => [
|
||||
'mod_assign',
|
||||
null,
|
||||
(object) ['name' => 'new name'],
|
||||
];
|
||||
yield 'component with itemid and summary' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['summary' => 'summary'],
|
||||
];
|
||||
yield 'component with itemid and summary, summaryformat ' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['summary' => 'summary', 'summaryformat' => 1],
|
||||
];
|
||||
yield 'component with itemid and section number' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['section' => 2],
|
||||
];
|
||||
yield 'component with itemid and visible 1' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['visible' => 1],
|
||||
];
|
||||
yield 'component with itemid and visible 0' => [
|
||||
'mod_assign',
|
||||
1,
|
||||
(object) ['visible' => 0],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for create method.
|
||||
* @covers ::create
|
||||
* @dataProvider create_provider
|
||||
*
|
||||
* @param int $sectionnum the name of the plugin
|
||||
* @param bool $skip if the validation should be skipped
|
||||
* @param bool $expectexception if the method should throw an exception
|
||||
* @param int $expected the expected section number
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('create_provider')]
|
||||
public function test_create(int $sectionnum, bool $skip, bool $expectexception, int $expected): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
@@ -148,59 +146,55 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for test_create_delegated.
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function create_provider(): array {
|
||||
return [
|
||||
'section 1' => [
|
||||
'sectionnum' => 1,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 1,
|
||||
],
|
||||
'section 2' => [
|
||||
'sectionnum' => 2,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
],
|
||||
'section 3' => [
|
||||
'sectionnum' => 3,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
],
|
||||
'section 4' => [
|
||||
'sectionnum' => 4,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
],
|
||||
'section 1 with exception' => [
|
||||
'sectionnum' => 1,
|
||||
'skip' => true,
|
||||
'expectexception' => true,
|
||||
'expected' => 0,
|
||||
],
|
||||
'section 2 with skip validation' => [
|
||||
'sectionnum' => 2,
|
||||
'skip' => true,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
],
|
||||
'section 5 with skip validation' => [
|
||||
'sectionnum' => 5,
|
||||
'skip' => true,
|
||||
'expectexception' => false,
|
||||
'expected' => 5,
|
||||
],
|
||||
public static function create_provider(): \Generator {
|
||||
yield 'section 1' => [
|
||||
'sectionnum' => 1,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 1,
|
||||
];
|
||||
yield 'section 2' => [
|
||||
'sectionnum' => 2,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
];
|
||||
yield 'section 3' => [
|
||||
'sectionnum' => 3,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
];
|
||||
yield 'section 4' => [
|
||||
'sectionnum' => 4,
|
||||
'skip' => false,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
];
|
||||
yield 'section 1 with exception' => [
|
||||
'sectionnum' => 1,
|
||||
'skip' => true,
|
||||
'expectexception' => true,
|
||||
'expected' => 0,
|
||||
];
|
||||
yield 'section 2 with skip validation' => [
|
||||
'sectionnum' => 2,
|
||||
'skip' => true,
|
||||
'expectexception' => false,
|
||||
'expected' => 2,
|
||||
];
|
||||
yield 'section 5 with skip validation' => [
|
||||
'sectionnum' => 5,
|
||||
'skip' => true,
|
||||
'expectexception' => false,
|
||||
'expected' => 5,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create sections when there are sections with comonent (delegated sections) in the course.
|
||||
* @covers ::create
|
||||
* @covers ::create_delegated
|
||||
*/
|
||||
public function test_create_with_delegated_sections(): void {
|
||||
global $DB;
|
||||
@@ -238,11 +232,11 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for create_if_missing method.
|
||||
* @covers ::create_if_missing
|
||||
* @dataProvider create_if_missing_provider
|
||||
*
|
||||
* @param array $sectionnums the section numbers to create
|
||||
* @param bool $expected the expected result
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('create_if_missing_provider')]
|
||||
public function test_create_if_missing(array $sectionnums, bool $expected): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
@@ -263,41 +257,37 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for test_create_delegated.
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function create_if_missing_provider(): array {
|
||||
return [
|
||||
'existing section' => [
|
||||
'sectionnums' => [1],
|
||||
'expected' => false,
|
||||
],
|
||||
'unexisting section' => [
|
||||
'sectionnums' => [3],
|
||||
'expected' => true,
|
||||
],
|
||||
'several existing sections' => [
|
||||
'sectionnums' => [1, 2],
|
||||
'expected' => false,
|
||||
],
|
||||
'several unexisting sections' => [
|
||||
'sectionnums' => [3, 4],
|
||||
'expected' => true,
|
||||
],
|
||||
'empty array' => [
|
||||
'sectionnums' => [],
|
||||
'expected' => false,
|
||||
],
|
||||
'existent and unexistent sections' => [
|
||||
'sectionnums' => [1, 2, 3, 4],
|
||||
'expected' => true,
|
||||
],
|
||||
public static function create_if_missing_provider(): \Generator {
|
||||
yield 'existing section' => [
|
||||
'sectionnums' => [1],
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'unexisting section' => [
|
||||
'sectionnums' => [3],
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'several existing sections' => [
|
||||
'sectionnums' => [1, 2],
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'several unexisting sections' => [
|
||||
'sectionnums' => [3, 4],
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'empty array' => [
|
||||
'sectionnums' => [],
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'existent and unexistent sections' => [
|
||||
'sectionnums' => [1, 2, 3, 4],
|
||||
'expected' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create if missing when the course has delegated sections.
|
||||
* @covers ::create_if_missing
|
||||
* @covers ::create_delegated
|
||||
*/
|
||||
public function test_create_if_missing_with_delegated_sections(): void {
|
||||
global $DB;
|
||||
@@ -341,7 +331,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for delete method.
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function test_delete(): void {
|
||||
global $DB;
|
||||
@@ -410,7 +399,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that triggering a course_section_deleted event works as expected.
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function test_section_deleted_event(): void {
|
||||
global $USER, $DB;
|
||||
@@ -448,7 +436,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test async section deletion hook.
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function test_async_section_deletion_hook_implemented(): void {
|
||||
// Async section deletion (provided section contains modules), depends on the 'true' being returned by at least one plugin
|
||||
@@ -546,13 +533,12 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test section update method.
|
||||
*
|
||||
* @covers ::update
|
||||
* @dataProvider update_provider
|
||||
* @param string $fieldname the name of the field to update
|
||||
* @param int|string $value the value to set
|
||||
* @param int|string $expected the expected value after the update ('=' to specify the same value as original field)
|
||||
* @param bool $expectexception if the method should throw an exception
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('update_provider')]
|
||||
public function test_update(
|
||||
string $fieldname,
|
||||
int|string $value,
|
||||
@@ -592,71 +578,67 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for test_update.
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function update_provider(): array {
|
||||
return [
|
||||
'Id will not be updated' => [
|
||||
'fieldname' => 'id',
|
||||
'value' => -1,
|
||||
'expected' => '=',
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Course will not be updated' => [
|
||||
'fieldname' => 'course',
|
||||
'value' => -1,
|
||||
'expected' => '=',
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Section number will not be updated' => [
|
||||
'fieldname' => 'section',
|
||||
'value' => -1,
|
||||
'expected' => '=',
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Sequence will be updated' => [
|
||||
'fieldname' => 'name',
|
||||
'value' => 'new name',
|
||||
'expected' => 'new name',
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Summary can be updated' => [
|
||||
'fieldname' => 'summary',
|
||||
'value' => 'new summary',
|
||||
'expected' => 'new summary',
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Visible can be updated' => [
|
||||
'fieldname' => 'visible',
|
||||
'value' => 0,
|
||||
'expected' => 0,
|
||||
'expectexception' => false,
|
||||
],
|
||||
'component can be updated' => [
|
||||
'fieldname' => 'component',
|
||||
'value' => 'mod_assign',
|
||||
'expected' => 'mod_assign',
|
||||
'expectexception' => false,
|
||||
],
|
||||
'itemid can be updated' => [
|
||||
'fieldname' => 'itemid',
|
||||
'value' => 1,
|
||||
'expected' => 1,
|
||||
'expectexception' => false,
|
||||
],
|
||||
'Long names throws and exception' => [
|
||||
'fieldname' => 'name',
|
||||
'value' => str_repeat('a', 1334),
|
||||
'expected' => '=',
|
||||
'expectexception' => true,
|
||||
],
|
||||
public static function update_provider(): \Generator {
|
||||
yield 'Id will not be updated' => [
|
||||
'fieldname' => 'id',
|
||||
'value' => -1,
|
||||
'expected' => '=',
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Course will not be updated' => [
|
||||
'fieldname' => 'course',
|
||||
'value' => -1,
|
||||
'expected' => '=',
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Section number will not be updated' => [
|
||||
'fieldname' => 'section',
|
||||
'value' => -1,
|
||||
'expected' => '=',
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Sequence will be updated' => [
|
||||
'fieldname' => 'name',
|
||||
'value' => 'new name',
|
||||
'expected' => 'new name',
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Summary can be updated' => [
|
||||
'fieldname' => 'summary',
|
||||
'value' => 'new summary',
|
||||
'expected' => 'new summary',
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Visible can be updated' => [
|
||||
'fieldname' => 'visible',
|
||||
'value' => 0,
|
||||
'expected' => 0,
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'component can be updated' => [
|
||||
'fieldname' => 'component',
|
||||
'value' => 'mod_assign',
|
||||
'expected' => 'mod_assign',
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'itemid can be updated' => [
|
||||
'fieldname' => 'itemid',
|
||||
'value' => 1,
|
||||
'expected' => 1,
|
||||
'expectexception' => false,
|
||||
];
|
||||
yield 'Long names throws and exception' => [
|
||||
'fieldname' => 'name',
|
||||
'value' => str_repeat('a', 1334),
|
||||
'expected' => '=',
|
||||
'expectexception' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test section update method updating several values at once.
|
||||
*
|
||||
* @covers ::update
|
||||
*/
|
||||
public function test_update_multiple_fields(): void {
|
||||
global $DB;
|
||||
@@ -686,8 +668,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test updating a section trigger a course section update log event.
|
||||
*
|
||||
* @covers ::update
|
||||
*/
|
||||
public function test_course_section_updated_event(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -715,8 +695,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test section update change the modified date.
|
||||
*
|
||||
* @covers ::update
|
||||
*/
|
||||
public function test_update_time_modified(): void {
|
||||
global $DB;
|
||||
@@ -752,8 +730,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test section updating visibility will hide or show section activities.
|
||||
*
|
||||
* @covers ::update
|
||||
*/
|
||||
public function test_update_hide_section_activities(): void {
|
||||
global $DB;
|
||||
@@ -866,9 +842,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the preprocess_section_name method can alter the section rename value.
|
||||
*
|
||||
* @covers ::update
|
||||
* @covers ::preprocess_delegated_section_fields
|
||||
*/
|
||||
public function test_preprocess_section_name(): void {
|
||||
global $DB, $CFG;
|
||||
@@ -905,8 +878,6 @@ final class sectionactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the position of a new section in a course with deleghated sections.
|
||||
* @covers ::create
|
||||
* @covers ::create_delegated
|
||||
*/
|
||||
public function test_create_position(): void {
|
||||
global $DB, $CFG;
|
||||
|
||||
@@ -24,17 +24,14 @@ use stdClass;
|
||||
* @package core_courseformat
|
||||
* @copyright 2023 Sara Arjona <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\output\activitybadge
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(activitybadge::class)]
|
||||
final class activitybadge_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the behaviour of create_instance() and export_for_template() attributes.
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @covers ::export_for_template
|
||||
* @covers ::create_instance
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
|
||||
public function test_activitybadge_export_for_template(): void {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@@ -25,8 +25,8 @@ use core_completion\external\completion_info_exporter;
|
||||
* @category test
|
||||
* @copyright 2025 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_courseformat\output\local\content\cm\completion
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(completion::class)]
|
||||
final class completion_test extends \advanced_testcase {
|
||||
#[\Override]
|
||||
public static function setupBeforeClass(): void {
|
||||
|
||||
@@ -26,8 +26,8 @@ use stdClass;
|
||||
* @package core_courseformat
|
||||
* @copyright 2022 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\output\local\state\cm
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(cm::class)]
|
||||
final class cm_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -43,15 +43,13 @@ final class cm_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test the behaviour of state\cm hasavailability attribute.
|
||||
*
|
||||
* @dataProvider hasrestrictions_state_provider
|
||||
* @covers ::export_for_template
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param string $rolename the user role name (editingteacher or student)
|
||||
* @param bool $hasavailability if the activity|section has availability
|
||||
* @param bool $available if the activity availability condition is available or not to the user
|
||||
* @param bool $expected the expected result
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('hasrestrictions_state_provider')]
|
||||
public function test_cm_hasrestrictions_state(
|
||||
string $format = 'topics',
|
||||
string $rolename = 'editingteacher',
|
||||
@@ -149,208 +147,206 @@ final class cm_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_state().
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function hasrestrictions_state_provider(): array {
|
||||
return [
|
||||
// Teacher scenarios (topics).
|
||||
'Teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (weeks).
|
||||
'Teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (mock format).
|
||||
'Teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (topics).
|
||||
'Non editing teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (weeks).
|
||||
'Non editing teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (mock format).
|
||||
'Non editing teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (topics).
|
||||
'Student, Topics, cannot edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student, Topics, cannot edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Student, Topics, cannot edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (weeks).
|
||||
'Student, Weeks, cannot edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student, Weeks, cannot edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Student, Weeks, cannot edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (mock format).
|
||||
'Student, Mock format, cannot edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Student, Mock format, cannot edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Student, Mock format, cannot edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
public static function hasrestrictions_state_provider(): \Generator {
|
||||
// Teacher scenarios (topics).
|
||||
yield 'Teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Teacher scenarios (weeks).
|
||||
yield 'Teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Teacher scenarios (mock format).
|
||||
yield 'Teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Non editing teacher scenarios (topics).
|
||||
yield 'Non editing teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Non editing teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Non editing teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Non editing teacher scenarios (weeks).
|
||||
yield 'Non editing teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Non editing teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Non editing teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Non editing teacher scenarios (mock format).
|
||||
yield 'Non editing teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Non editing teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Non editing teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Student scenarios (topics).
|
||||
yield 'Student, Topics, cannot edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student, Topics, cannot edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Student, Topics, cannot edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Student scenarios (weeks).
|
||||
yield 'Student, Weeks, cannot edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student, Weeks, cannot edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Student, Weeks, cannot edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Student scenarios (mock format).
|
||||
yield 'Student, Mock format, cannot edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Student, Mock format, cannot edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Student, Mock format, cannot edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ use stdClass;
|
||||
* @package core_courseformat
|
||||
* @copyright 2022 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\output\local\state\section
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(section::class)]
|
||||
final class section_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -43,15 +43,13 @@ final class section_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test the behaviour of state\section hasavailability attribute.
|
||||
*
|
||||
* @dataProvider hasrestrictions_state_provider
|
||||
* @covers ::export_for_template
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param string $rolename the user role name (editingteacher or student)
|
||||
* @param bool $hasavailability if the activity|section has availability
|
||||
* @param bool $available if the activity availability condition is available or not to the user
|
||||
* @param bool $expected the expected result
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('hasrestrictions_state_provider')]
|
||||
public function test_section_hasrestrictions_state(
|
||||
string $format = 'topics',
|
||||
string $rolename = 'editingteacher',
|
||||
@@ -141,208 +139,206 @@ final class section_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_state().
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function hasrestrictions_state_provider(): array {
|
||||
return [
|
||||
// Teacher scenarios (topics).
|
||||
'Teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (weeks).
|
||||
'Teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (mock format).
|
||||
'Teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (topics).
|
||||
'Non editing teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (weeks).
|
||||
'Non editing teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (mock format).
|
||||
'Non editing teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (topics).
|
||||
'Topics, cannot edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Topics, cannot edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, cannot edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (weeks).
|
||||
'Weeks, cannot edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Weeks, cannot edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, cannot edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (mock format).
|
||||
'Mock format, cannot edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Mock format, cannot edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, cannot edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
public static function hasrestrictions_state_provider(): \Generator {
|
||||
// Teacher scenarios (topics).
|
||||
yield 'Teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Teacher scenarios (weeks).
|
||||
yield 'Teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Teacher scenarios (mock format).
|
||||
yield 'Teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Non editing teacher scenarios (topics).
|
||||
yield 'Non editing teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non editing teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non editing teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Non editing teacher scenarios (weeks).
|
||||
yield 'Non editing teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non editing teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non editing teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Non editing teacher scenarios (mock format).
|
||||
yield 'Non editing teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non editing teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Non editing teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Student scenarios (topics).
|
||||
yield 'Topics, cannot edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Topics, cannot edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Topics, cannot edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Student scenarios (weeks).
|
||||
yield 'Weeks, cannot edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Weeks, cannot edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Weeks, cannot edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
// Student scenarios (mock format).
|
||||
yield 'Mock format, cannot edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
yield 'Mock format, cannot edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
];
|
||||
yield 'Mock format, cannot edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,13 +40,9 @@ final class state_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test the behaviour of state::export_for_template().
|
||||
*
|
||||
* @dataProvider state_provider
|
||||
* @covers \core_courseformat\output\local\state\course
|
||||
* @covers \core_courseformat\output\local\state\section
|
||||
* @covers \core_courseformat\output\local\state\cm
|
||||
*
|
||||
* @param string $format The course format of the course where the method will be executed.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('state_provider')]
|
||||
public function test_state(string $format = 'topics'): void {
|
||||
global $PAGE;
|
||||
|
||||
@@ -149,23 +145,21 @@ final class state_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_state().
|
||||
*
|
||||
* @return array
|
||||
* @return \Generator
|
||||
*/
|
||||
public static function state_provider(): array {
|
||||
return [
|
||||
// COURSEFORMAT. Test behaviour depending on course formats.
|
||||
'Single activity format' => [
|
||||
'format' => 'singleactivity',
|
||||
],
|
||||
'Social format' => [
|
||||
'format' => 'social',
|
||||
],
|
||||
'Weeks format' => [
|
||||
'format' => 'weeks',
|
||||
],
|
||||
'The unit tests format' => [
|
||||
'format' => 'theunittest',
|
||||
],
|
||||
public static function state_provider(): \Generator {
|
||||
// COURSEFORMAT. Test behaviour depending on course formats.
|
||||
yield 'Single activity format' => [
|
||||
'format' => 'singleactivity',
|
||||
];
|
||||
yield 'Social format' => [
|
||||
'format' => 'social',
|
||||
];
|
||||
yield 'Weeks format' => [
|
||||
'format' => 'weeks',
|
||||
];
|
||||
yield 'The unit tests format' => [
|
||||
'format' => 'theunittest',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,8 @@ use test_component\courseformat\sectiondelegate as testsectiondelegate;
|
||||
* @package core_courseformat
|
||||
* @copyright 2023 Ferran Recio <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_courseformat\sectiondelegate
|
||||
* @coversDefaultClass \core_courseformat\sectiondelegate
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(sectiondelegate::class)]
|
||||
final class sectiondelegate_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -40,7 +39,6 @@ final class sectiondelegate_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the instance method returns the correct class.
|
||||
* @covers ::instance
|
||||
*/
|
||||
public function test_instance(): void {
|
||||
global $DB;
|
||||
@@ -78,8 +76,6 @@ final class sectiondelegate_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the instance method returns null when the delegate class is disabled.
|
||||
*
|
||||
* @covers ::instance
|
||||
*/
|
||||
public function test_instance_disabled(): void {
|
||||
global $DB;
|
||||
@@ -105,8 +101,6 @@ final class sectiondelegate_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test has_delegate_class().
|
||||
*
|
||||
* @covers ::has_delegate_class
|
||||
*/
|
||||
public function test_has_delegate_class(): void {
|
||||
$this->assertFalse(sectiondelegate::has_delegate_class('missing_component'));
|
||||
@@ -116,8 +110,6 @@ final class sectiondelegate_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_section_action_menu().
|
||||
*
|
||||
* @covers ::get_section_action_menu
|
||||
*/
|
||||
public function test_get_section_action_menu(): void {
|
||||
global $DB, $PAGE;
|
||||
@@ -172,8 +164,6 @@ final class sectiondelegate_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_parent_section().
|
||||
*
|
||||
* @covers ::get_parent_section
|
||||
*/
|
||||
public function test_get_parent_section(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -28,8 +28,8 @@ use stdClass;
|
||||
* @category test
|
||||
* @copyright 2021 Sara Arjona ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\stateactions
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(stateactions::class)]
|
||||
final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Helper method to create an activity into a section and add it to the $sections and $activities arrays.
|
||||
@@ -189,11 +189,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test the behaviour course_state.
|
||||
*
|
||||
* @dataProvider get_state_provider
|
||||
* @covers ::course_state
|
||||
* @covers ::section_state
|
||||
* @covers ::cm_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
|
||||
@@ -201,6 +196,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
* @param array $expectedresults List of the course module names expected after calling the method.
|
||||
* @param bool $expectedexception If this call will raise an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('get_state_provider')]
|
||||
public function test_get_state(
|
||||
string $format,
|
||||
string $role,
|
||||
@@ -349,8 +345,8 @@ final class stateactions_test extends \advanced_testcase {
|
||||
$usersections = ['section0', 'section1', 'section2', 'section3'];
|
||||
}
|
||||
|
||||
// Tests for course_state.
|
||||
return [
|
||||
// Tests for course_state.
|
||||
"admin $format course_state" => [
|
||||
'format' => $format,
|
||||
'role' => 'admin',
|
||||
@@ -755,11 +751,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for section_hide
|
||||
*
|
||||
* @covers ::section_hide
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_section_hide(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -782,11 +777,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for section_hide
|
||||
*
|
||||
* @covers ::section_show
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_section_show(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -809,11 +803,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_show
|
||||
*
|
||||
* @covers ::cm_show
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_show(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -836,11 +829,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_hide
|
||||
*
|
||||
* @covers ::cm_hide
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_hide(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -863,11 +855,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_stealth
|
||||
*
|
||||
* @covers ::cm_stealth
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_stealth(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -921,39 +912,36 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for basic role tests.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function basic_role_provider(): array {
|
||||
return [
|
||||
'editingteacher' => [
|
||||
'role' => 'editingteacher',
|
||||
'expectedexception' => false,
|
||||
],
|
||||
'teacher' => [
|
||||
'role' => 'teacher',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'student' => [
|
||||
'role' => 'student',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'guest' => [
|
||||
'role' => 'guest',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
public static function basic_role_provider(): \Generator {
|
||||
yield 'editingteacher' => [
|
||||
'role' => 'editingteacher',
|
||||
'expectedexception' => false,
|
||||
];
|
||||
yield 'teacher' => [
|
||||
'role' => 'teacher',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'student' => [
|
||||
'role' => 'student',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'guest' => [
|
||||
'role' => 'guest',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate course module method.
|
||||
*
|
||||
* @covers ::cm_duplicate
|
||||
* @dataProvider cm_duplicate_provider
|
||||
* @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
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('cm_duplicate_provider')]
|
||||
public function test_cm_duplicate(
|
||||
string $targetsection = '',
|
||||
bool $validcms = true,
|
||||
@@ -1032,75 +1020,72 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Duplicate course module data provider.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function cm_duplicate_provider(): array {
|
||||
return [
|
||||
'valid cms without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => true,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => false,
|
||||
],
|
||||
'valid cms targeting an empty section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => true,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => false,
|
||||
],
|
||||
'valid cms targeting a section with activities' => [
|
||||
'targetsection' => 'section2',
|
||||
'validcms' => true,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => false,
|
||||
],
|
||||
'invalid cms without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => false,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'invalid cms with target section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => false,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'student role with target section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => true,
|
||||
'role' => 'student',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'student role without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => true,
|
||||
'role' => 'student',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'unrenolled user with target section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => true,
|
||||
'role' => 'unenroled',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'unrenolled user without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => true,
|
||||
'role' => 'unenroled',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
public static function cm_duplicate_provider(): \Generator {
|
||||
yield 'valid cms without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => true,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => false,
|
||||
];
|
||||
yield 'valid cms targeting an empty section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => true,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => false,
|
||||
];
|
||||
yield 'valid cms targeting a section with activities' => [
|
||||
'targetsection' => 'section2',
|
||||
'validcms' => true,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => false,
|
||||
];
|
||||
yield 'invalid cms without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => false,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'invalid cms with target section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => false,
|
||||
'role' => 'admin',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'student role with target section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => true,
|
||||
'role' => 'student',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'student role without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => true,
|
||||
'role' => 'student',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'unrenolled user with target section' => [
|
||||
'targetsection' => 'section3',
|
||||
'validcms' => true,
|
||||
'role' => 'unenroled',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'unrenolled user without target section' => [
|
||||
'targetsection' => '',
|
||||
'validcms' => true,
|
||||
'role' => 'unenroled',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for cm_delete
|
||||
*
|
||||
* @covers ::cm_delete
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_delete(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1148,11 +1133,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_moveright
|
||||
*
|
||||
* @covers ::cm_moveright
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_moveright(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1175,11 +1159,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_moveleft
|
||||
*
|
||||
* @covers ::cm_moveleft
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_moveleft(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1202,11 +1185,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_nogroups
|
||||
*
|
||||
* @covers ::cm_nogroups
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_nogroups(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1229,11 +1211,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_visiblegroups
|
||||
*
|
||||
* @covers ::cm_visiblegroups
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_visiblegroups(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1256,11 +1237,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for cm_separategroups
|
||||
*
|
||||
* @covers ::cm_separategroups
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_cm_separategroups(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1283,14 +1263,13 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for section_move_after
|
||||
*
|
||||
* @covers ::section_move_after
|
||||
* @dataProvider section_move_after_provider
|
||||
* @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
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('section_move_after_provider')]
|
||||
public function test_section_move_after(
|
||||
array $sectiontomove,
|
||||
string $targetsection,
|
||||
@@ -1358,108 +1337,105 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Provider for test_section_move_after.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function section_move_after_provider(): array {
|
||||
return [
|
||||
'Move sections down' => [
|
||||
'sectiontomove' => ['section2', 'section4'],
|
||||
'targetsection' => 'section7',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section5',
|
||||
'section6',
|
||||
'section7',
|
||||
'section2',
|
||||
'section4',
|
||||
'section8',
|
||||
],
|
||||
'updatedcms' => ['cm2', 'cm3'],
|
||||
'totalputs' => 12,
|
||||
public static function section_move_after_provider(): \Generator {
|
||||
yield 'Move sections down' => [
|
||||
'sectiontomove' => ['section2', 'section4'],
|
||||
'targetsection' => 'section7',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section5',
|
||||
'section6',
|
||||
'section7',
|
||||
'section2',
|
||||
'section4',
|
||||
'section8',
|
||||
],
|
||||
'Move sections up' => [
|
||||
'sectiontomove' => ['section3', 'section5'],
|
||||
'targetsection' => 'section1',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section5',
|
||||
'section2',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
],
|
||||
'updatedcms' => ['cm0', 'cm1', 'cm4', 'cm5'],
|
||||
'totalputs' => 14,
|
||||
'updatedcms' => ['cm2', 'cm3'],
|
||||
'totalputs' => 12,
|
||||
];
|
||||
yield 'Move sections up' => [
|
||||
'sectiontomove' => ['section3', 'section5'],
|
||||
'targetsection' => 'section1',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section5',
|
||||
'section2',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
],
|
||||
'Move sections in the middle' => [
|
||||
'sectiontomove' => ['section2', 'section5'],
|
||||
'targetsection' => 'section3',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section2',
|
||||
'section5',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
],
|
||||
'updatedcms' => ['cm2', 'cm3', 'cm4', 'cm5'],
|
||||
'totalputs' => 14,
|
||||
'updatedcms' => ['cm0', 'cm1', 'cm4', 'cm5'],
|
||||
'totalputs' => 14,
|
||||
];
|
||||
yield 'Move sections in the middle' => [
|
||||
'sectiontomove' => ['section2', 'section5'],
|
||||
'targetsection' => 'section3',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section3',
|
||||
'section2',
|
||||
'section5',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
],
|
||||
'Move sections on top' => [
|
||||
'sectiontomove' => ['section3', 'section5'],
|
||||
'targetsection' => 'section0',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section3',
|
||||
'section5',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
],
|
||||
'updatedcms' => ['cm4', 'cm5'],
|
||||
'totalputs' => 12,
|
||||
'updatedcms' => ['cm2', 'cm3', 'cm4', 'cm5'],
|
||||
'totalputs' => 14,
|
||||
];
|
||||
yield 'Move sections on top' => [
|
||||
'sectiontomove' => ['section3', 'section5'],
|
||||
'targetsection' => 'section0',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section3',
|
||||
'section5',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
],
|
||||
'Move sections on bottom' => [
|
||||
'sectiontomove' => ['section3', 'section5'],
|
||||
'targetsection' => 'section8',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
'section3',
|
||||
'section5',
|
||||
],
|
||||
'updatedcms' => ['cm4', 'cm5'],
|
||||
'totalputs' => 12,
|
||||
'updatedcms' => ['cm4', 'cm5'],
|
||||
'totalputs' => 12,
|
||||
];
|
||||
yield 'Move sections on bottom' => [
|
||||
'sectiontomove' => ['section3', 'section5'],
|
||||
'targetsection' => 'section8',
|
||||
'finalorder' => [
|
||||
'section0',
|
||||
'section1',
|
||||
'section2',
|
||||
'section4',
|
||||
'section6',
|
||||
'section7',
|
||||
'section8',
|
||||
'section3',
|
||||
'section5',
|
||||
],
|
||||
'updatedcms' => ['cm4', 'cm5'],
|
||||
'totalputs' => 12,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test course module move and subsection move.
|
||||
*
|
||||
* @covers ::cm_move
|
||||
* @dataProvider cm_move_provider
|
||||
* @param string[] $cmtomove the sections to move
|
||||
* @param string $targetsection
|
||||
* @param string[] $expectedcoursetree expected course tree
|
||||
* @param string|null $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('cm_move_provider')]
|
||||
public function test_cm_move(
|
||||
array $cmtomove,
|
||||
string $targetsection,
|
||||
@@ -1577,37 +1553,35 @@ final class stateactions_test extends \advanced_testcase {
|
||||
* 'section4' => [],
|
||||
* ],
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function cm_move_provider(): array {
|
||||
return [
|
||||
'Move module into section2' => [
|
||||
'cmtomove' => ['cm0'],
|
||||
'targetsection' => 'section2',
|
||||
'expectedcoursetree' => [
|
||||
'section0' => [],
|
||||
'section1' => ['subsection1' => ['cm2'], 'subsection2' => []],
|
||||
'section2' => ['cm1', 'cm0'],
|
||||
'section3' => [],
|
||||
'section4' => [],
|
||||
],
|
||||
public static function cm_move_provider(): \Generator {
|
||||
yield 'Move module into section2' => [
|
||||
'cmtomove' => ['cm0'],
|
||||
'targetsection' => 'section2',
|
||||
'expectedcoursetree' => [
|
||||
'section0' => [],
|
||||
'section1' => ['subsection1' => ['cm2'], 'subsection2' => []],
|
||||
'section2' => ['cm1', 'cm0'],
|
||||
'section3' => [],
|
||||
'section4' => [],
|
||||
],
|
||||
'Move subsection into another subsection' => [
|
||||
'cmtomove' => ['subsection1'], // When moving a subsection we actually move the delegated module.
|
||||
'targetsection' => 'subsection2',
|
||||
'expectedcoursetree' => [],
|
||||
'expectedexception' => 'error/subsectionmoveerror',
|
||||
],
|
||||
'Move module into subsection' => [
|
||||
'cmtomove' => ['cm1'],
|
||||
'targetsection' => 'subsection1',
|
||||
'expectedcoursetree' => [
|
||||
'section0' => ['cm0'],
|
||||
'section1' => ['subsection1' => ['cm2', 'cm1'], 'subsection2' => []],
|
||||
'section2' => [],
|
||||
'section3' => [],
|
||||
'section4' => [],
|
||||
],
|
||||
];
|
||||
yield 'Move subsection into another subsection' => [
|
||||
'cmtomove' => ['subsection1'], // When moving a subsection we actually move the delegated module.
|
||||
'targetsection' => 'subsection2',
|
||||
'expectedcoursetree' => [],
|
||||
'expectedexception' => 'error/subsectionmoveerror',
|
||||
];
|
||||
yield 'Move module into subsection' => [
|
||||
'cmtomove' => ['cm1'],
|
||||
'targetsection' => 'subsection1',
|
||||
'expectedcoursetree' => [
|
||||
'section0' => ['cm0'],
|
||||
'section1' => ['subsection1' => ['cm2', 'cm1'], 'subsection2' => []],
|
||||
'section2' => [],
|
||||
'section3' => [],
|
||||
'section4' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -1615,11 +1589,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test for section_move_after capability checks.
|
||||
*
|
||||
* @covers ::section_move_after
|
||||
* @dataProvider basic_role_provider
|
||||
* @param string $role the user role
|
||||
* @param bool $expectedexception if it will expect an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_section_move_after_capabilities(
|
||||
string $role = 'editingteacher',
|
||||
bool $expectedexception = false
|
||||
@@ -1646,8 +1619,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that set_cm_indentation on activities with a delegated section.
|
||||
*
|
||||
* @covers ::set_cm_indentation
|
||||
*/
|
||||
public function test_set_cm_indentation_delegated_section(): void {
|
||||
global $DB;
|
||||
@@ -1727,8 +1698,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for filter_cms_with_section_delegate protected method.
|
||||
*
|
||||
* @covers ::filter_cms_with_section_delegate
|
||||
*/
|
||||
public function test_filter_cms_with_section_delegate(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1758,8 +1727,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for create_module public method.
|
||||
*
|
||||
* @covers ::create_module
|
||||
*/
|
||||
public function test_create_module(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1795,8 +1762,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for create_module public method with no capabilities.
|
||||
*
|
||||
* @covers ::create_module
|
||||
*/
|
||||
public function test_create_module_no_capabilities(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1835,8 +1800,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for create_module public method with targetcmid parameter.
|
||||
*
|
||||
* @covers ::create_module
|
||||
*/
|
||||
public function test_create_module_with_targetcmid(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1886,8 +1849,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for new_module public method.
|
||||
*
|
||||
* @covers ::new_module
|
||||
*/
|
||||
public function test_new_module(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1920,8 +1881,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for new_module public method with no capabilities.
|
||||
*
|
||||
* @covers ::new_module
|
||||
*/
|
||||
public function test_new_module_no_capabilities(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -1953,8 +1912,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for new_module public method with targetcmid parameter.
|
||||
*
|
||||
* @covers ::new_module
|
||||
*/
|
||||
public function test_new_module_with_targetcmid(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -2001,8 +1958,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for section_duplicate public method.
|
||||
*
|
||||
* @covers ::section_duplicate
|
||||
*/
|
||||
public function test_section_duplicate(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -2056,8 +2011,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test duplicating multiple sections.
|
||||
*
|
||||
* @covers ::section_duplicate
|
||||
*/
|
||||
public function test_section_duplicate_multiple(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -2125,8 +2078,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for section_duplicate public method with no capabilities.
|
||||
*
|
||||
* @covers ::section_duplicate
|
||||
*/
|
||||
public function test_section_duplicate_no_capabilities(): void {
|
||||
$this->resetAfterTest();
|
||||
@@ -2152,8 +2103,6 @@ final class stateactions_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for section_duplicate on a delegated section (subsection).
|
||||
*
|
||||
* @covers ::section_duplicate
|
||||
*/
|
||||
public function test_section_duplicate_delegated_section(): void {
|
||||
global $DB;
|
||||
|
||||
@@ -25,18 +25,16 @@ use stdClass;
|
||||
* @category test
|
||||
* @copyright 2021 Sara Arjona ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \core_courseformat\stateupdates
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(stateupdates::class)]
|
||||
final class stateupdates_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for add_course_put.
|
||||
*
|
||||
* @dataProvider add_course_put_provider
|
||||
* @covers ::add_course_put
|
||||
*
|
||||
* @param string $role the user role in the course
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('add_course_put_provider')]
|
||||
public function test_add_course_put(string $role): void {
|
||||
global $PAGE;
|
||||
|
||||
@@ -79,19 +77,17 @@ final class stateupdates_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_add_course_put.
|
||||
*
|
||||
* @return array testing scenarios
|
||||
* @return \Generator testing scenarios
|
||||
*/
|
||||
public static function add_course_put_provider(): array {
|
||||
return [
|
||||
'Admin role' => [
|
||||
'admin',
|
||||
],
|
||||
'Teacher role' => [
|
||||
'editingteacher',
|
||||
],
|
||||
'Student role' => [
|
||||
'student',
|
||||
],
|
||||
public static function add_course_put_provider(): \Generator {
|
||||
yield 'Admin role' => [
|
||||
'admin',
|
||||
];
|
||||
yield 'Teacher role' => [
|
||||
'editingteacher',
|
||||
];
|
||||
yield 'Student role' => [
|
||||
'student',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -127,15 +123,11 @@ final class stateupdates_test extends \advanced_testcase {
|
||||
/**
|
||||
* Add track about a section state update.
|
||||
*
|
||||
* @dataProvider add_section_provider
|
||||
* @covers ::add_section_create
|
||||
* @covers ::add_section_remove
|
||||
* @covers ::add_section_put
|
||||
*
|
||||
* @param string $action the action name
|
||||
* @param string $role the user role name
|
||||
* @param array $expected the expected results
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('add_section_provider')]
|
||||
public function test_add_section(string $action, string $role, array $expected): void {
|
||||
global $PAGE, $DB;
|
||||
|
||||
@@ -244,15 +236,11 @@ final class stateupdates_test extends \advanced_testcase {
|
||||
/**
|
||||
* Add track about a course module state update.
|
||||
*
|
||||
* @dataProvider add_cm_provider
|
||||
* @covers ::add_cm_put
|
||||
* @covers ::add_cm_create
|
||||
* @covers ::add_cm_remove
|
||||
*
|
||||
* @param string $action the action name
|
||||
* @param string $role the user role name
|
||||
* @param array $expected the expected results
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('add_cm_provider')]
|
||||
public function test_add_cm(string $action, string $role, array $expected): void {
|
||||
global $PAGE, $DB;
|
||||
|
||||
@@ -386,7 +374,6 @@ final class stateupdates_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test components can add data to delegated section state updates.
|
||||
* @covers ::add_section_put
|
||||
*/
|
||||
public function test_put_section_state_extra_updates(): void {
|
||||
global $DB, $CFG;
|
||||
|
||||
@@ -51,11 +51,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for section_highlight method.
|
||||
*
|
||||
* @dataProvider basic_role_provider
|
||||
* @covers ::section_highlight
|
||||
* @param string $rolename The role of the user that will execute the method.
|
||||
* @param bool $expectedexception If this call will raise an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_section_highlight(string $rolename, bool $expectedexception = false): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
@@ -119,11 +118,10 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for section_unhighlight method.
|
||||
*
|
||||
* @dataProvider basic_role_provider
|
||||
* @covers ::section_unhighlight
|
||||
* @param string $rolename The role of the user that will execute the method.
|
||||
* @param bool $expectedexception If this call will raise an exception.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('basic_role_provider')]
|
||||
public function test_section_unhighlight(string $rolename, bool $expectedexception = false): void {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
@@ -189,34 +187,32 @@ final class stateactions_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for basic role tests.
|
||||
*
|
||||
* @return array the testing scenarios
|
||||
* @return \Generator the testing scenarios
|
||||
*/
|
||||
public static function basic_role_provider(): array {
|
||||
return [
|
||||
'admin' => [
|
||||
'rolename' => 'admin',
|
||||
'expectedexception' => false,
|
||||
],
|
||||
'editingteacher' => [
|
||||
'rolename' => 'editingteacher',
|
||||
'expectedexception' => false,
|
||||
],
|
||||
'teacher' => [
|
||||
'rolename' => 'teacher',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'student' => [
|
||||
'rolename' => 'student',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'guest' => [
|
||||
'rolename' => 'guest',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
'unenroled' => [
|
||||
'rolename' => 'unenroled',
|
||||
'expectedexception' => true,
|
||||
],
|
||||
public static function basic_role_provider(): \Generator {
|
||||
yield 'admin' => [
|
||||
'rolename' => 'admin',
|
||||
'expectedexception' => false,
|
||||
];
|
||||
yield 'editingteacher' => [
|
||||
'rolename' => 'editingteacher',
|
||||
'expectedexception' => false,
|
||||
];
|
||||
yield 'teacher' => [
|
||||
'rolename' => 'teacher',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'student' => [
|
||||
'rolename' => 'student',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'guest' => [
|
||||
'rolename' => 'guest',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
yield 'unenroled' => [
|
||||
'rolename' => 'unenroled',
|
||||
'expectedexception' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ require_once($CFG->dirroot . '/course/lib.php');
|
||||
* @package format_topics
|
||||
* @copyright 2015 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \format_topics
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(\format_topics::class)]
|
||||
final class format_topics_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -234,8 +234,6 @@ final class format_topics_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_view_url().
|
||||
*
|
||||
* @covers ::get_view_url
|
||||
*/
|
||||
public function test_get_view_url(): void {
|
||||
global $CFG;
|
||||
@@ -269,8 +267,6 @@ final class format_topics_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_required_jsfiles().
|
||||
*
|
||||
* @covers ::get_required_jsfiles
|
||||
*/
|
||||
public function test_get_required_jsfiles(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -29,8 +29,8 @@ require_once($CFG->dirroot . '/course/lib.php');
|
||||
* @package format_weeks
|
||||
* @copyright 2015 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \format_weeks
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(\format_weeks::class)]
|
||||
final class format_weeks_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
@@ -231,8 +231,6 @@ final class format_weeks_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for get_view_url().
|
||||
*
|
||||
* @covers ::get_view_url
|
||||
*/
|
||||
public function test_get_view_url(): void {
|
||||
global $CFG;
|
||||
@@ -266,8 +264,6 @@ final class format_weeks_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_required_jsfiles().
|
||||
*
|
||||
* @covers ::get_required_jsfiles
|
||||
*/
|
||||
public function test_get_required_jsfiles(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
Reference in New Issue
Block a user