Skip to content

Fix: tables-based lesson progress ignores pass_required for failed quiz status#8005

Open
thisismyurl wants to merge 4 commits into
Automattic:trunkfrom
thisismyurl:fix/tables-based-lesson-progress-pass-required
Open

Fix: tables-based lesson progress ignores pass_required for failed quiz status#8005
thisismyurl wants to merge 4 commits into
Automattic:trunkfrom
thisismyurl:fix/tables-based-lesson-progress-pass-required

Conversation

@thisismyurl

Copy link
Copy Markdown
Contributor

What this fixes

When a lesson's quiz has Pass Required disabled, a learner who submits a failed quiz should still have the lesson marked complete — they only need to have attempted the quiz, not passed it.

The Comments_Based_Lesson_Progress::get_status() already handles this correctly. The HPPS equivalent, Tables_Based_Lesson_Progress, inherits a bare get_status() from Lesson_Progress_Abstract that simply returns $this->status verbatim — so a 'failed' internal status is returned as 'failed' (maps to STATUS_IN_PROGRESS) regardless of the _pass_required setting on the quiz.

This is the root cause of #7943.

What changed

includes/internal/student-progress/lesson-progress/models/class-tables-based-lesson-progress.php

  • Added get_status() override that mirrors Comments_Based_Lesson_Progress::get_status(), including the _pass_required check for the 'failed' case
  • passed / graded statuses correctly return STATUS_COMPLETE
  • failed + pass_required disabled → STATUS_COMPLETE
  • failed + pass_required enabled → STATUS_IN_PROGRESS
  • All other statuses delegate to STATUS_IN_PROGRESS

tests/unit-tests/internal/student-progress/lesson-progress/models/test-class-tables-based-lesson-progress.php

  • testGetStatus_ConstructedWithFailedStatusAndPassNotRequired_ReturnsComplete
  • testGetStatus_ConstructedWithFailedStatusAndPassRequired_ReturnsInProgress

Testing

phpunit --filter Tables_Based_Lesson_Progress

Both new tests should pass. Existing tests in this file are unaffected.

Related

Resolves #7943


This PR was developed with AI assistance (research, implementation, and test generation). All code was reviewed and validated before submission.

…iz status

The Tables_Based_Lesson_Progress::get_status() method was missing the
pass_required check that Comments_Based_Lesson_Progress correctly implements.
When a lesson quiz has pass_required disabled, a learner who submits a
failed quiz should still have the lesson marked complete — they only need
to have attempted the quiz, not passed it.

Mirrors the logic in Comments_Based_Lesson_Progress::get_status(), including
the handling of passed/graded statuses that should map to STATUS_COMPLETE.

Resolves: Automattic#7943
…t_status()

Two integration tests exercising the fix introduced in the prior commit:
- failed quiz + pass_required disabled => STATUS_COMPLETE
- failed quiz + pass_required enabled  => STATUS_IN_PROGRESS
Copilot AI review requested due to automatic review settings June 11, 2026 15:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds logic to Tables_Based_Lesson_Progress so a failed quiz can still count as lesson completion when the lesson quiz doesn’t require passing (matching the comments-based progress behavior).

Changes:

  • Implemented Tables_Based_Lesson_Progress::get_status() with special handling for failed + _pass_required disabled.
  • Added unit tests covering failed status behavior for both pass-required and not-pass-required quizzes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tests/unit-tests/internal/student-progress/lesson-progress/models/test-class-tables-based-lesson-progress.php Adds unit tests asserting status mapping for failed quizzes depending on _pass_required.
includes/internal/student-progress/lesson-progress/models/class-tables-based-lesson-progress.php Implements status normalization for tables-based lesson progress, including _pass_required lookup for failed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*
* @internal
*
* @since $next-version$
*
* @return string|null
*/
public function get_status(): ?string {
Comment on lines +43 to +55
case 'failed':
// This may be 'completed' depending on...
// Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson.
$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $this->lesson_id );
if ( $lesson_quiz_id ) {
// ...the quiz pass setting.
$pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true );
if ( empty( $pass_required ) ) {
// We just require the user to have done the quiz, not to have passed.
return self::STATUS_COMPLETE;
}
}
return self::STATUS_IN_PROGRESS;
return self::STATUS_COMPLETE;

case 'failed':
// This may be 'completed' depending on...
@thisismyurl

Copy link
Copy Markdown
Contributor Author

Thanks for the automated review — wanted to address each point:

@since $next-version$ — This is intentional. That's Sensei's conventional placeholder token; the release tooling fills it with the actual version at release time. I left it to match the pattern used throughout the codebase (e.g. Comments_Based_Lesson_Progress::get_status() uses the same placeholder on its own method additions). Happy to remove it if the maintainers prefer a concrete version, but I'd expect the same tooling to fill it in on merge.

Return type ?string vs string — Valid observation. I left it as ?string to stay covariant with the parent class signature (Lesson_Progress_Abstract::get_status(): ?string). Tightening the concrete implementation to : string would work — PHP allows that — but it would diverge from the parent and could cause confusion when reading both side by side. That's a project-wide decision I'd defer to the maintainers on.

N+1 query concern — Noted. The implementation mirrors Comments_Based_Lesson_Progress::get_status() which has the same pattern (quiz ID lookup + meta read per call). If the maintainers want a static cache added here, happy to add it — but I didn't want to diverge from the existing implementation without a signal that consistency isn't the priority.

Comment wording ('completed' vs 'complete') — Good catch. I pushed a follow-up commit that corrects the comment to 'complete' to match STATUS_COMPLETE.

Let me know if anything else needs addressing.

@thisismyurl

Copy link
Copy Markdown
Contributor Author

Added a changelog entry to resolve the Changelogger CI failure — pushed changelog/fix-tables-based-lesson-progress-pass-required with Significance: patch / Type: fixed.

The other failing check (Check Milestone) needs a maintainer to assign a milestone, so leaving that one with you.

(full disclosure: AI helped me identify the issue and verify my work)

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.

HPPS: Tables-based lesson progress does not account for pass_required in is_complete()

3 participants