Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StudentQuiz: There are some issues of Add completion criteria #732619 #474

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

BruceGoodGuy
Copy link
Contributor

No description provided.

@BruceGoodGuy
Copy link
Contributor Author

BruceGoodGuy commented Oct 27, 2023

Hi @timhunt,
I have made a necessary changes to fix the issue with Studentquiz.
Could you help me to review my code changes? thanks so much.
Commit ID: 7b1dd5d05f46892afa92fb8d10bb09172beaefe0

*/
public static function update_state(stdClass $course, $cm, ?int $userid = null): void {
public static function update_state(stdClass $course, $cm, ?int $userid = null): bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea to change the return type just for unit testing. Your unit test should verify the real outcome, not some artificial thing.

*/
public static function update_state(stdClass $course, $cm, ?int $userid = null): void {
public static function update_state(stdClass $course, $cm, ?int $userid = null): bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think update_state is not a very accurate name for what this function does. Would trigger_completion_state_update be more accurate?

$cm = cm_info::create(get_coursemodule_from_id('studentquiz', $studentquiz->cmid));
$completioninfo = new \completion_info($course);
$customcompletion = new custom_completion($cm, $user->id, $completioninfo->get_core_completion_state($cm, $user->id));
$status = $customcompletion::update_state($course, $cm, $user->id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a static method. The call should be custom_completion::update_state, with no need to create an instance.

false,
],
'Students can manually mark the activity as completed' => [
1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using magic numbers here, and not the constants like COMPLETION_TRACKING_MANUAL ?

@BruceGoodGuy
Copy link
Contributor Author

Hi @timhunt ,

Thanks for your feedback.

In this commit, I have made two changes:

  1. Rename the function update_state to trigger_completion_state_update.

  2. Rewrite unit-test for the function trigger_completion_state_update.
    Could you help me to review it again? Thanks so much.
    Commit ID: 43e361d85e74fad36a4dee561fd338004a757326

@timhunt timhunt merged commit f4aaf49 into studentquiz:main Nov 1, 2023
0 of 4 checks passed
@timhunt
Copy link
Member

timhunt commented Nov 1, 2023

Thanks. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants