Skip to content

Commit

Permalink
MDL-82351 core_courseformat: fix social format phpunits
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranrecio committed Nov 22, 2024
1 parent ab5b390 commit 694edcf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
44 changes: 37 additions & 7 deletions course/format/tests/stateactions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ public function test_get_state(
// 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);
Expand Down Expand Up @@ -271,6 +280,7 @@ public static function get_state_provider(): array {
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'),
Expand All @@ -280,6 +290,9 @@ public static function get_state_provider(): array {
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'),
Expand All @@ -289,6 +302,9 @@ public static function get_state_provider(): array {
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'),
);
}

Expand All @@ -299,7 +315,15 @@ public static function get_state_provider(): array {
* @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" => [
Expand All @@ -312,7 +336,7 @@ public static function course_state_provider(string $format): array {
'expectedresults' => [
'course' => ['course'],
'section' => ['section0', 'section1', 'section2', 'section3'],
'cm' => ['cm0', 'cm1', 'cm2', 'cm3'],
'cm' => $cms,
],
'expectedexception' => $expectedexception,
],
Expand All @@ -326,7 +350,7 @@ public static function course_state_provider(string $format): array {
'expectedresults' => [
'course' => ['course'],
'section' => ['section0', 'section1', 'section2', 'section3'],
'cm' => ['cm0', 'cm1', 'cm2', 'cm3'],
'cm' => $cms,
],
'expectedexception' => $expectedexception,
],
Expand All @@ -340,7 +364,7 @@ public static function course_state_provider(string $format): array {
'expectedresults' => [
'course' => ['course'],
'section' => ['section0', 'section1', 'section3'],
'cm' => ['cm0'],
'cm' => $studentcms,
],
'expectedexception' => $expectedexception,
],
Expand All @@ -357,7 +381,7 @@ public static function course_state_provider(string $format): array {
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'];
Expand All @@ -366,6 +390,9 @@ public static function section_state_provider(string $format, string $role): arr
$usersections = ['section0', 'section1', 'section3'];
$usercms = ['cm0'];
}
if ($format === 'social') {
$usercms = ['initialcm0', ...$usercms];
}

return [
"$role $format section_state no section" => [
Expand All @@ -388,7 +415,7 @@ public static function section_state_provider(string $format, string $role): arr
'expectedresults' => [
'course' => [],
'section' => array_intersect(['section0'], $usersections),
'cm' => [],
'cm' => ($format == 'social') ? ['initialcm0'] : [],
],
'expectedexception' => $expectedexception,
],
Expand Down Expand Up @@ -490,6 +517,9 @@ public static function cm_state_provider(string $format, string $role): array {
$usersections = ['section0', 'section1', 'section3'];
$usercms = ['cm0'];
}
if ($format === 'social') {
$usercms = ['initialcm0', ...$usercms];
}

return [
"$role $format cm_state no cms" => [
Expand Down Expand Up @@ -556,7 +586,7 @@ public static function cm_state_provider(string $format, string $role): array {
'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,
Expand Down
2 changes: 1 addition & 1 deletion course/tests/targets_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function analysable_provider(): array {
'coursenosections' => [
'params' => [
'enablecompletion' => 1,
'format' => 'social',
'format' => 'singleactivity',
'students' => true
],
'isvalid' => get_string('nocoursesections', 'course')
Expand Down

0 comments on commit 694edcf

Please sign in to comment.