mirror of
https://github.com/moodle/moodle.git
synced 2025-04-05 08:23:01 +02:00
MDL-82351 core_courseformat: fix social format phpunits
This commit is contained in:
parent
ab5b390a77
commit
694edcf76b
@ -217,6 +217,15 @@ final class stateactions_test extends \advanced_testcase {
|
||||
// Create and enrol user using given role.
|
||||
$this->set_test_user_by_role($course, $role);
|
||||
|
||||
// Some formats, like social, can create some initial activity.
|
||||
$modninfo = course_modinfo::instance($course);
|
||||
$cms = $modninfo->get_cms();
|
||||
$count = 0;
|
||||
foreach ($cms as $cm) {
|
||||
$references["initialcm{$count}"] = $cm->id;
|
||||
$count++;
|
||||
}
|
||||
|
||||
// Add some activities to the course. One visible and one hidden in both sections 1 and 2.
|
||||
$references["cm0"] = $this->create_activity($course->id, 'assign', 1, true);
|
||||
$references["cm1"] = $this->create_activity($course->id, 'book', 1, false);
|
||||
@ -271,6 +280,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
static::course_state_provider('weeks'),
|
||||
static::course_state_provider('topics'),
|
||||
static::course_state_provider('social'),
|
||||
static::course_state_provider('singleactivity'),
|
||||
static::section_state_provider('weeks', 'admin'),
|
||||
static::section_state_provider('weeks', 'editingteacher'),
|
||||
static::section_state_provider('weeks', 'student'),
|
||||
@ -280,6 +290,9 @@ final class stateactions_test extends \advanced_testcase {
|
||||
static::section_state_provider('social', 'admin'),
|
||||
static::section_state_provider('social', 'editingteacher'),
|
||||
static::section_state_provider('social', 'student'),
|
||||
static::section_state_provider('singleactivity', 'admin'),
|
||||
static::section_state_provider('singleactivity', 'editingteacher'),
|
||||
static::section_state_provider('singleactivity', 'student'),
|
||||
static::cm_state_provider('weeks', 'admin'),
|
||||
static::cm_state_provider('weeks', 'editingteacher'),
|
||||
static::cm_state_provider('weeks', 'student'),
|
||||
@ -289,6 +302,9 @@ final class stateactions_test extends \advanced_testcase {
|
||||
static::cm_state_provider('social', 'admin'),
|
||||
static::cm_state_provider('social', 'editingteacher'),
|
||||
static::cm_state_provider('social', 'student'),
|
||||
static::cm_state_provider('singleactivity', 'admin'),
|
||||
static::cm_state_provider('singleactivity', 'editingteacher'),
|
||||
static::cm_state_provider('singleactivity', 'student'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -299,7 +315,15 @@ final class stateactions_test extends \advanced_testcase {
|
||||
* @return array the testing scenarios
|
||||
*/
|
||||
public static function course_state_provider(string $format): array {
|
||||
$expectedexception = ($format === 'social');
|
||||
$expectedexception = ($format === 'singleactivity');
|
||||
|
||||
$cms = ['cm0', 'cm1', 'cm2', 'cm3'];
|
||||
$studentcms = ['cm0'];
|
||||
if ($format === 'social') {
|
||||
$cms = ['initialcm0', 'cm0', 'cm1', 'cm2', 'cm3'];
|
||||
$studentcms = ['initialcm0', 'cm0'];
|
||||
}
|
||||
|
||||
return [
|
||||
// Tests for course_state.
|
||||
"admin $format course_state" => [
|
||||
@ -312,7 +336,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
'expectedresults' => [
|
||||
'course' => ['course'],
|
||||
'section' => ['section0', 'section1', 'section2', 'section3'],
|
||||
'cm' => ['cm0', 'cm1', 'cm2', 'cm3'],
|
||||
'cm' => $cms,
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
],
|
||||
@ -326,7 +350,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
'expectedresults' => [
|
||||
'course' => ['course'],
|
||||
'section' => ['section0', 'section1', 'section2', 'section3'],
|
||||
'cm' => ['cm0', 'cm1', 'cm2', 'cm3'],
|
||||
'cm' => $cms,
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
],
|
||||
@ -340,7 +364,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
'expectedresults' => [
|
||||
'course' => ['course'],
|
||||
'section' => ['section0', 'section1', 'section3'],
|
||||
'cm' => ['cm0'],
|
||||
'cm' => $studentcms,
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
],
|
||||
@ -357,7 +381,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
public static function section_state_provider(string $format, string $role): array {
|
||||
// Social format will raise an exception and debug messages because it does not
|
||||
// use sections and it does not provide a renderer.
|
||||
$expectedexception = ($format === 'social');
|
||||
$expectedexception = ($format === 'singleactivity');
|
||||
|
||||
// All sections and cms that the user can access to.
|
||||
$usersections = ['section0', 'section1', 'section2', 'section3'];
|
||||
@ -366,6 +390,9 @@ final class stateactions_test extends \advanced_testcase {
|
||||
$usersections = ['section0', 'section1', 'section3'];
|
||||
$usercms = ['cm0'];
|
||||
}
|
||||
if ($format === 'social') {
|
||||
$usercms = ['initialcm0', ...$usercms];
|
||||
}
|
||||
|
||||
return [
|
||||
"$role $format section_state no section" => [
|
||||
@ -388,7 +415,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
'expectedresults' => [
|
||||
'course' => [],
|
||||
'section' => array_intersect(['section0'], $usersections),
|
||||
'cm' => [],
|
||||
'cm' => ($format == 'social') ? ['initialcm0'] : [],
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
],
|
||||
@ -490,6 +517,9 @@ final class stateactions_test extends \advanced_testcase {
|
||||
$usersections = ['section0', 'section1', 'section3'];
|
||||
$usercms = ['cm0'];
|
||||
}
|
||||
if ($format === 'social') {
|
||||
$usercms = ['initialcm0', ...$usercms];
|
||||
}
|
||||
|
||||
return [
|
||||
"$role $format cm_state no cms" => [
|
||||
@ -556,7 +586,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
'section' => array_intersect(['section1', 'section2'], $usersections),
|
||||
'cm' => array_intersect(['cm0'], $usercms),
|
||||
],
|
||||
'expectedexception' => ($format === 'social'),
|
||||
'expectedexception' => ($format === 'singleactivity'),
|
||||
],
|
||||
"$role $format cm_state using targetcm" => [
|
||||
'format' => $format,
|
||||
|
@ -65,7 +65,7 @@ class targets_test extends \advanced_testcase {
|
||||
'coursenosections' => [
|
||||
'params' => [
|
||||
'enablecompletion' => 1,
|
||||
'format' => 'social',
|
||||
'format' => 'singleactivity',
|
||||
'students' => true
|
||||
],
|
||||
'isvalid' => get_string('nocoursesections', 'course')
|
||||
|
Loading…
x
Reference in New Issue
Block a user