Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Dec 18, 2024
1 parent 06f239b commit 283dc2f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
48 changes: 18 additions & 30 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,16 @@ protected function get_debug_string() {
* @return string
*/
public static function options_start(int $i) {
switch ($i) {
case 1:
return get_string('datestart', 'availability_relativedate');
case 2:
return get_string('dateend', 'availability_relativedate');
case 3:
return get_string('dateenrol', 'availability_relativedate');
case 4:
return get_string('dateendenrol', 'availability_relativedate');
case 5:
return get_string('dateendafter', 'availability_relativedate');
case 6:
return get_string('datestartbefore', 'availability_relativedate');
case 7:
return get_string('datecompletion', 'availability_relativedate');
}
return '';
return match($i) {
1 => get_string('datestart', 'availability_relativedate'),
2 => get_string('dateend', 'availability_relativedate'),
3 => get_string('dateenrol', 'availability_relativedate'),
4 => get_string('dateendenrol', 'availability_relativedate'),
5 => get_string('dateendafter', 'availability_relativedate'),
6 => get_string('datestartbefore', 'availability_relativedate'),
7 => get_string('datecompletion', 'availability_relativedate'),
default => '',
};
}

/**
Expand All @@ -222,19 +215,14 @@ public static function options_dwm($number = 1) {
* @return string
*/
public static function option_dwm(int $i): string {
switch ($i) {
case 0:
return 'minute';
case 1:
return 'hour';
case 2:
return 'day';
case 3:
return 'week';
case 4:
return 'month';
}
return '';
return match($i) {
0 => 'minute',
1 => 'hour',
2 => 'day',
3 => 'week',
4 => 'month',
default => '',
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/backup_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function test_backup(): void {
$page2 = $pg->create_instance(['course' => $course, 'completion' => COMPLETION_TRACKING_MANUAL]);
$str = '{"op":"|","show":true,"c":[{"type":"relativedate","n":4,"d":4,"s":7,"m":' . $page1->cmid . '}]}';
$DB->set_field('course_modules', 'availability', $str, ['id' => $page0->cmid]);
$str = '{"op":"|","c":[{"type":"relativedate","n":1,"d":1,"s":6,"m":999999}], "show":true}';
$str = '{"op":"|","c":[{"type":"relativedate","n":1,"d":1,"s":7,"m":999999}], "show":true}';
$DB->set_field('course_modules', 'availability', $str, ['id' => $page2->cmid]);
rebuild_course_cache($course->id, true);
$bc = new \backup_controller(
Expand Down
12 changes: 10 additions & 2 deletions tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,16 @@ public function test_get_description(): void {
$this->assertTrue($cond->completion_value_used($this->course, $page1->cmid));

$modinfo = get_fast_modinfo($this->course);
$str = '{"op":"|","show":true,"c":[{"type":"relativedate","n":4,"d":4,"s":7,"m":' . $page0->cmid . '}]}';
$str1 = '{"op":"|","show":true,"c":[{"type":"relativedate","n":4,"d":4,"s":7,"m":' . $page0->cmid . '}]}';
$str2 = '{"op":"|","show":true,"c":[{"type":"relativedate","n":4,"d":4,"s":7,"m":666}]}';
$i = 1;
foreach ($modinfo->get_section_info_all() as $section) {
$DB->set_field('course_sections', 'availability', $str, ['id' => $section->id]);
if (($i % 2) == 0) {
$DB->set_field('course_sections', 'availability', $str1, ['id' => $section->id]);
} else {
$DB->set_field('course_sections', 'availability', $str2, ['id' => $section->id]);
}
$i++;
}
$this->do_cron();
$cond = new condition((object)['type' => 'relativedate', 'n' => 4, 'd' => 4, 's' => 7, 'm' => $page1->cmid]);
Expand Down Expand Up @@ -348,6 +355,7 @@ public function test_reflection_debug_strings(): void {
$result = \phpunit_util::call_internal_method($condition, 'get_debug_string', [], $name);
$this->assertStringContainsString(get_string('missing', 'availability_relativedate'), $result);
$this->assertStringContainsString('alert', $result);
$this->assertStringContainsString('1 day after completion of activity', $result);
}

/**
Expand Down

0 comments on commit 283dc2f

Please sign in to comment.