From 8f0b645b3b24f3fb5fbf408ceeeda2e09dfee40a Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 13:58:15 +0600 Subject: [PATCH 01/25] Add button for awaiting grade quiz --- includes/class-sensei-quiz.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/class-sensei-quiz.php b/includes/class-sensei-quiz.php index 956830da92..3a5d750021 100755 --- a/includes/class-sensei-quiz.php +++ b/includes/class-sensei-quiz.php @@ -1857,6 +1857,17 @@ public static function action_buttons() { $is_quiz_completed = self::is_quiz_completed(); $is_reset_allowed = self::is_reset_allowed( $lesson_id ); $has_actions = $is_reset_allowed || ! $is_quiz_completed; + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); + $is_learning_mode = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); + $is_awaiting_grade = false; + + $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); + + if ( $lesson_status ) { + $lesson_status = is_array( $lesson_status ) ? $lesson_status[0] : $lesson_status; + + $is_awaiting_grade = 'ungraded' === $lesson_status->comment_approved; + } $wrapper_attributes = get_block_wrapper_attributes( [ @@ -1898,6 +1909,12 @@ class="wp-block-button__link button quiz-submit complete sensei-course-theme__bu + + + +
From 1122e7db28cd0af440bba05d07b67a1346211af3 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 13:59:03 +0600 Subject: [PATCH 02/25] Add disabled button opacity for course theme --- assets/css/3rd-party/themes/course/quiz.scss | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assets/css/3rd-party/themes/course/quiz.scss b/assets/css/3rd-party/themes/course/quiz.scss index 8cb5b9aa2f..e61bcbb7f7 100644 --- a/assets/css/3rd-party/themes/course/quiz.scss +++ b/assets/css/3rd-party/themes/course/quiz.scss @@ -12,6 +12,13 @@ } } } + +.wp-block-sensei-lms-quiz-actions { + button:disabled { + opacity: 0.4; + } +} + .quiz { .sensei-course-theme__quiz { &__main-content { From 3cf618a425f4f987c5eeaf688a043fa611a2fefa Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 13:59:34 +0600 Subject: [PATCH 03/25] Add disabled button opacity in compat themes --- assets/css/sensei-course-theme/quiz-compat.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/css/sensei-course-theme/quiz-compat.scss b/assets/css/sensei-course-theme/quiz-compat.scss index f8a2189bb5..2bcf9107ed 100644 --- a/assets/css/sensei-course-theme/quiz-compat.scss +++ b/assets/css/sensei-course-theme/quiz-compat.scss @@ -53,6 +53,12 @@ $textColor: #1E1E1E; } } +.wp-block-sensei-lms-quiz-actions { + button:disabled { + opacity: 0.6; + } +} + .quiz { form { #sensei-quiz-list { From 7315515bdaa70dc30680841353b3e826ad24619a Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 13:59:53 +0600 Subject: [PATCH 04/25] Add stylings for disabled button in footer --- assets/css/sensei-course-theme/quiz.scss | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/assets/css/sensei-course-theme/quiz.scss b/assets/css/sensei-course-theme/quiz.scss index d32b6f9d4b..f8fc7e3f27 100644 --- a/assets/css/sensei-course-theme/quiz.scss +++ b/assets/css/sensei-course-theme/quiz.scss @@ -201,6 +201,14 @@ $vertical-spacing-desktop: 80px; text-decoration: none; } +.wp-block-sensei-lms-quiz-actions { + button:disabled { + cursor: not-allowed; + pointer-events: none; + width: auto; + } +} + .sensei-progress-bar { &__bar { height: 12px; From 20541f4bb3f6318cbe8d18083a3ae413430f9618 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 14:05:07 +0600 Subject: [PATCH 05/25] Change decorations for Quiz restart button --- assets/css/frontend.scss | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/assets/css/frontend.scss b/assets/css/frontend.scss index 246eb7c661..36abc5fcc8 100644 --- a/assets/css/frontend.scss +++ b/assets/css/frontend.scss @@ -521,6 +521,11 @@ div.sensei-quiz-actions { .sensei-quiz-action { .button, button { @include button-link; + text-decoration: none; + + &:hover { + text-decoration: underline; + } } } } From 0d61148845739031aa143b7e379ca398442074df Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 14:26:47 +0600 Subject: [PATCH 06/25] Change text from Reset quiz to restart quiz --- includes/class-sensei-quiz.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-sensei-quiz.php b/includes/class-sensei-quiz.php index 3a5d750021..1665779d30 100755 --- a/includes/class-sensei-quiz.php +++ b/includes/class-sensei-quiz.php @@ -1918,8 +1918,8 @@ class="wp-block-button__link button quiz-submit complete sensei-course-theme__bu
- From d3195aaf85dafaf79774cd59667bb73a7a8762ae Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 14:27:16 +0600 Subject: [PATCH 07/25] Update color of reset quiz button --- assets/css/sensei-course-theme/quiz-compat.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/css/sensei-course-theme/quiz-compat.scss b/assets/css/sensei-course-theme/quiz-compat.scss index 2bcf9107ed..8a03fb098c 100644 --- a/assets/css/sensei-course-theme/quiz-compat.scss +++ b/assets/css/sensei-course-theme/quiz-compat.scss @@ -57,6 +57,12 @@ $textColor: #1E1E1E; button:disabled { opacity: 0.6; } + + .sensei-quiz-actions-secondary { + .sensei-course-theme__button.is-link { + color: var(--sensei-primary-color); + } + } } .quiz { From b6210bc81ab61f6b9c4dea588726b4107f04bc91 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 15:10:56 +0600 Subject: [PATCH 08/25] Don't render lesson actions when in quiz awaiting grade --- .../blocks/course-theme/class-lesson-actions.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/includes/blocks/course-theme/class-lesson-actions.php b/includes/blocks/course-theme/class-lesson-actions.php index b6fef5d555..ff7bc66790 100644 --- a/includes/blocks/course-theme/class-lesson-actions.php +++ b/includes/blocks/course-theme/class-lesson-actions.php @@ -161,6 +161,21 @@ public function render( array $attributes = [] ): string { $course_id = Sensei()->lesson->get_course_id( $lesson_id ); + $is_learning_mode = \Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); + $is_awaiting_grade = false; + + $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); + + if ( $lesson_status ) { + $lesson_status = is_array( $lesson_status ) ? $lesson_status[0] : $lesson_status; + + $is_awaiting_grade = 'ungraded' === $lesson_status->comment_approved; + } + + if ( $is_learning_mode && $is_awaiting_grade && 'quiz' === get_post_type() ) { + return ''; + } + if ( ! Sensei_Course::is_user_enrolled( $course_id ) ) { From dd1ec86986f95a7fbd9bb65b7042db9418c35c9b Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 15:11:15 +0600 Subject: [PATCH 09/25] Show pending grade button when reset is not allowed --- includes/class-sensei-quiz.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/class-sensei-quiz.php b/includes/class-sensei-quiz.php index 1665779d30..ee7b71b341 100755 --- a/includes/class-sensei-quiz.php +++ b/includes/class-sensei-quiz.php @@ -1856,7 +1856,6 @@ public static function action_buttons() { $lesson_id = Sensei()->quiz->get_lesson_id(); $is_quiz_completed = self::is_quiz_completed(); $is_reset_allowed = self::is_reset_allowed( $lesson_id ); - $has_actions = $is_reset_allowed || ! $is_quiz_completed; $course_id = Sensei()->lesson->get_course_id( $lesson_id ); $is_learning_mode = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); $is_awaiting_grade = false; @@ -1869,12 +1868,16 @@ public static function action_buttons() { $is_awaiting_grade = 'ungraded' === $lesson_status->comment_approved; } + $show_grade_pending_button = $is_learning_mode && $is_awaiting_grade; + $wrapper_attributes = get_block_wrapper_attributes( [ 'class' => 'sensei-quiz-actions', ] ); + $has_actions = $is_reset_allowed || ! $is_quiz_completed || $show_grade_pending_button; + if ( ! $has_actions ) { return; } From 66dc7c944a8bd1f39dc21264ca2b05e7741959b2 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 15:21:25 +0600 Subject: [PATCH 10/25] Fix spacing above footer for course theme --- assets/css/3rd-party/themes/course/quiz.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/css/3rd-party/themes/course/quiz.scss b/assets/css/3rd-party/themes/course/quiz.scss index e61bcbb7f7..e3c59c6eea 100644 --- a/assets/css/3rd-party/themes/course/quiz.scss +++ b/assets/css/3rd-party/themes/course/quiz.scss @@ -19,6 +19,10 @@ } } +#sensei-quiz-list { + margin: 0 0 clamp(3.75rem, 2.5rem + 3.333vw, 5rem) 0 +} + .quiz { .sensei-course-theme__quiz { &__main-content { From 036ce14935bb252e02c5e6177f3dffccad33205e Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 15:22:09 +0600 Subject: [PATCH 11/25] Fix spacing above footer for all compat themes --- assets/css/frontend.scss | 1 - assets/css/sensei-course-theme/quiz-compat.scss | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/css/frontend.scss b/assets/css/frontend.scss index 36abc5fcc8..20d0cef130 100644 --- a/assets/css/frontend.scss +++ b/assets/css/frontend.scss @@ -302,7 +302,6 @@ a.sensei-certificate-link { .quiz { form { #sensei-quiz-list { - margin: 0 0 1.618em 0; list-style-position: inside; list-style-type: none; padding-inline-start: 0; diff --git a/assets/css/sensei-course-theme/quiz-compat.scss b/assets/css/sensei-course-theme/quiz-compat.scss index 8a03fb098c..61a08b79ba 100644 --- a/assets/css/sensei-course-theme/quiz-compat.scss +++ b/assets/css/sensei-course-theme/quiz-compat.scss @@ -65,6 +65,10 @@ $textColor: #1E1E1E; } } +#sensei-quiz-list { + margin: 0 0 3.75rem 0 +} + .quiz { form { #sensei-quiz-list { From 940917ccfd9cc9f3f5b857d8f844c3377e077a54 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 17:39:41 +0600 Subject: [PATCH 12/25] Add semicolons in stylesheet --- assets/css/3rd-party/themes/course/quiz.scss | 2 +- assets/css/sensei-course-theme/quiz-compat.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/css/3rd-party/themes/course/quiz.scss b/assets/css/3rd-party/themes/course/quiz.scss index e3c59c6eea..f097b62c34 100644 --- a/assets/css/3rd-party/themes/course/quiz.scss +++ b/assets/css/3rd-party/themes/course/quiz.scss @@ -20,7 +20,7 @@ } #sensei-quiz-list { - margin: 0 0 clamp(3.75rem, 2.5rem + 3.333vw, 5rem) 0 + margin: 0 0 clamp(3.75rem, 2.5rem + 3.333vw, 5rem) 0; } .quiz { diff --git a/assets/css/sensei-course-theme/quiz-compat.scss b/assets/css/sensei-course-theme/quiz-compat.scss index 61a08b79ba..0cae783e0a 100644 --- a/assets/css/sensei-course-theme/quiz-compat.scss +++ b/assets/css/sensei-course-theme/quiz-compat.scss @@ -66,7 +66,7 @@ $textColor: #1E1E1E; } #sensei-quiz-list { - margin: 0 0 3.75rem 0 + margin: 0 0 3.75rem 0; } .quiz { From 5a50962673497cee5b2f982af9054a7ee0b4b03b Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 17:39:55 +0600 Subject: [PATCH 13/25] Remove extra specificity --- assets/css/3rd-party/themes/course/quiz.scss | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/assets/css/3rd-party/themes/course/quiz.scss b/assets/css/3rd-party/themes/course/quiz.scss index f097b62c34..462c203e2b 100644 --- a/assets/css/3rd-party/themes/course/quiz.scss +++ b/assets/css/3rd-party/themes/course/quiz.scss @@ -30,19 +30,18 @@ margin-bottom: 3.75rem; } } - &__footer { - .sensei-quiz-actions { - .sensei-quiz-action { - button { - padding: 1rem 32px; - } - } - .sensei-quiz-actions-secondary { - .sensei-quiz-action { - button { - font-family: var( --wp--preset--font-family--body ); - } - } + } + + .sensei-quiz-actions { + .sensei-quiz-action { + button { + padding: 1rem 32px; + } + } + .sensei-quiz-actions-secondary { + .sensei-quiz-action { + button { + font-family: var( --wp--preset--font-family--body ); } } } From 4a9df227b30b8d4e3d6d64afe2d4c69421742977 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Wed, 27 Sep 2023 17:52:44 +0600 Subject: [PATCH 14/25] Add changelog --- changelog/add-stylings-for-footer-in-awaiting-grade-quiz-lm | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/add-stylings-for-footer-in-awaiting-grade-quiz-lm diff --git a/changelog/add-stylings-for-footer-in-awaiting-grade-quiz-lm b/changelog/add-stylings-for-footer-in-awaiting-grade-quiz-lm new file mode 100644 index 0000000000..a0c99e63ee --- /dev/null +++ b/changelog/add-stylings-for-footer-in-awaiting-grade-quiz-lm @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Changed footer style for quizzes awaiting grading From a1986f9a44be64cb7df66931f18b591443eec991 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 11:35:31 +0600 Subject: [PATCH 15/25] return array of comments to fix psalm --- includes/class-sensei-utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-sensei-utils.php b/includes/class-sensei-utils.php index 486c98b300..c5fd748b7c 100644 --- a/includes/class-sensei-utils.php +++ b/includes/class-sensei-utils.php @@ -1690,7 +1690,7 @@ public static function user_course_status( $course_id = 0, $user_id = 0 ) { * @since 1.7.0 * @param int $lesson_id * @param int $user_id - * @return WP_Comment|false + * @return WP_Comment|WP_Comment[]|false */ public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { From d37ebc33974698530e7dd9c71266d14b53cf7021 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 11:51:59 +0600 Subject: [PATCH 16/25] Remove comment array return type --- includes/class-sensei-utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-sensei-utils.php b/includes/class-sensei-utils.php index c5fd748b7c..486c98b300 100644 --- a/includes/class-sensei-utils.php +++ b/includes/class-sensei-utils.php @@ -1690,7 +1690,7 @@ public static function user_course_status( $course_id = 0, $user_id = 0 ) { * @since 1.7.0 * @param int $lesson_id * @param int $user_id - * @return WP_Comment|WP_Comment[]|false + * @return WP_Comment|false */ public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { From 58f0a411463850f512a7fa3c2cbfbc4daf423267 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 11:57:49 +0600 Subject: [PATCH 17/25] Remove unnecessary array checks for graded lesson status --- includes/blocks/course-theme/class-lesson-actions.php | 11 ++--------- includes/class-sensei-quiz.php | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/includes/blocks/course-theme/class-lesson-actions.php b/includes/blocks/course-theme/class-lesson-actions.php index ff7bc66790..5c6d6ebc23 100644 --- a/includes/blocks/course-theme/class-lesson-actions.php +++ b/includes/blocks/course-theme/class-lesson-actions.php @@ -162,15 +162,8 @@ public function render( array $attributes = [] ): string { $course_id = Sensei()->lesson->get_course_id( $lesson_id ); $is_learning_mode = \Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); - $is_awaiting_grade = false; - - $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); - - if ( $lesson_status ) { - $lesson_status = is_array( $lesson_status ) ? $lesson_status[0] : $lesson_status; - - $is_awaiting_grade = 'ungraded' === $lesson_status->comment_approved; - } + $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); + $is_awaiting_grade = $lesson_status && 'ungraded' === $lesson_status->comment_approved; if ( $is_learning_mode && $is_awaiting_grade && 'quiz' === get_post_type() ) { return ''; diff --git a/includes/class-sensei-quiz.php b/includes/class-sensei-quiz.php index ee7b71b341..56a6ca263a 100755 --- a/includes/class-sensei-quiz.php +++ b/includes/class-sensei-quiz.php @@ -1858,15 +1858,8 @@ public static function action_buttons() { $is_reset_allowed = self::is_reset_allowed( $lesson_id ); $course_id = Sensei()->lesson->get_course_id( $lesson_id ); $is_learning_mode = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); - $is_awaiting_grade = false; - - $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); - - if ( $lesson_status ) { - $lesson_status = is_array( $lesson_status ) ? $lesson_status[0] : $lesson_status; - - $is_awaiting_grade = 'ungraded' === $lesson_status->comment_approved; - } + $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); + $is_awaiting_grade = $lesson_status && 'ungraded' === $lesson_status->comment_approved; $show_grade_pending_button = $is_learning_mode && $is_awaiting_grade; From 80468287581c5d9d5f9638f270e23dc4fa85d41c Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 12:33:49 +0600 Subject: [PATCH 18/25] Add function to check quiz awaiting status --- includes/class-sensei-quiz.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/class-sensei-quiz.php b/includes/class-sensei-quiz.php index 56a6ca263a..ff04274722 100755 --- a/includes/class-sensei-quiz.php +++ b/includes/class-sensei-quiz.php @@ -1858,8 +1858,7 @@ public static function action_buttons() { $is_reset_allowed = self::is_reset_allowed( $lesson_id ); $course_id = Sensei()->lesson->get_course_id( $lesson_id ); $is_learning_mode = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); - $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); - $is_awaiting_grade = $lesson_status && 'ungraded' === $lesson_status->comment_approved; + $is_awaiting_grade = self::is_quiz_awaiting_grade_for_user( $lesson_id, get_current_user_id() ); $show_grade_pending_button = $is_learning_mode && $is_awaiting_grade; @@ -2392,6 +2391,32 @@ public function maybe_create_quiz_progress( $quiz_id = '', $user_id = '' ): void $quiz_progress_repository->create( $quiz_id, $user_id ); } + + /** + * Check if the quiz is in ungraded state for a user. + * + * @param ?int $lesson_id The lesson ID. + * @param ?int $user_id The user ID. + * + * @return bool True if the quiz is in ungraded state for the user, false otherwise. + */ + public static function is_quiz_awaiting_grade_for_user( $lesson_id = null, $user_id = null ) { + if ( empty( $lesson_id ) ) { + $quiz_id = Sensei()->quiz->get_lesson_id(); + } + + if ( empty( $user_id ) ) { + $user_id = get_current_user_id(); + } + + if ( empty( $quiz_id ) || empty( $user_id ) || 'quiz' !== get_post_type( $quiz_id ) ) { + return false; + } + + $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); + + return $lesson_status && 'ungraded' === $lesson_status->comment_approved; + } } /** From 2b37b709ece75ecd963ede073dcc071cbb0ca05b Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 12:50:58 +0600 Subject: [PATCH 19/25] Use awaiting grade check function in lesson action --- includes/blocks/course-theme/class-lesson-actions.php | 3 +-- includes/class-sensei-quiz.php | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/blocks/course-theme/class-lesson-actions.php b/includes/blocks/course-theme/class-lesson-actions.php index 5c6d6ebc23..89fb2f30d4 100644 --- a/includes/blocks/course-theme/class-lesson-actions.php +++ b/includes/blocks/course-theme/class-lesson-actions.php @@ -162,8 +162,7 @@ public function render( array $attributes = [] ): string { $course_id = Sensei()->lesson->get_course_id( $lesson_id ); $is_learning_mode = \Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ); - $lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); - $is_awaiting_grade = $lesson_status && 'ungraded' === $lesson_status->comment_approved; + $is_awaiting_grade = \Sensei_Quiz::is_quiz_awaiting_grade_for_user( $lesson_id, $user_id ); if ( $is_learning_mode && $is_awaiting_grade && 'quiz' === get_post_type() ) { return ''; diff --git a/includes/class-sensei-quiz.php b/includes/class-sensei-quiz.php index ff04274722..2f72d5ab5e 100755 --- a/includes/class-sensei-quiz.php +++ b/includes/class-sensei-quiz.php @@ -2402,14 +2402,14 @@ public function maybe_create_quiz_progress( $quiz_id = '', $user_id = '' ): void */ public static function is_quiz_awaiting_grade_for_user( $lesson_id = null, $user_id = null ) { if ( empty( $lesson_id ) ) { - $quiz_id = Sensei()->quiz->get_lesson_id(); + $lesson_id = Sensei()->quiz->get_lesson_id(); } if ( empty( $user_id ) ) { $user_id = get_current_user_id(); } - if ( empty( $quiz_id ) || empty( $user_id ) || 'quiz' !== get_post_type( $quiz_id ) ) { + if ( empty( $lesson_id ) || empty( $user_id ) || 'lesson' !== get_post_type( $lesson_id ) ) { return false; } From 7b3920f624c732010d5eae79f7a181a8f42352ec Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 13:48:18 +0600 Subject: [PATCH 20/25] Add test to check pending grade is rendered --- tests/unit-tests/test-class-quiz.php | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/unit-tests/test-class-quiz.php b/tests/unit-tests/test-class-quiz.php index c6927e3b23..e898fc57da 100644 --- a/tests/unit-tests/test-class-quiz.php +++ b/tests/unit-tests/test-class-quiz.php @@ -60,7 +60,7 @@ public function tearDown(): void { foreach ( $quizzes as $index => $quiz ) { wp_delete_post( $quiz->ID, true ); } - + WP_Block_Supports::$block_to_render = null; } /** @@ -1950,4 +1950,42 @@ public function testMaybeCreateQuizProgress_WhenTablesBasedProgressFeatureIsDisa $actual = $quiz_progress_repository->has( $quiz_id, $user_id ); $this->assertFalse( $actual ); } + + public function testQuizFooterActions_WhenAwaitingGradeInLearningMode_RendersAwaitingGradeButton() { + /* Arrange */ + $user_id = $this->factory->user->create(); + $course_id = $this->factory->course->create(); + $lesson_id = $this->factory->lesson->create( + [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ] + ); + + $quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id ); + $course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id ); + $course_enrolment->enrol( $user_id ); + + wp_set_current_user( $user_id ); + + // Enable course theme; + update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME ); + + + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'ungraded' ); + + $this->go_to( get_permalink( $quiz_id ) ); + + WP_Block_Supports::$block_to_render = [ + 'attrs' => [], + 'blockName' => 'sensei-lms/quiz-actions', + ]; + + /* Act */ + $result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render(); + + /* Assert */ + $this->assertStringContainsString( 'Pending teacher grade', $result ); + } } From 1c3ff858d83bd05c16190a46b23d3ee71e74e197 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 13:48:59 +0600 Subject: [PATCH 21/25] Add test to check pending button not rendered for non LM --- tests/unit-tests/test-class-quiz.php | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/unit-tests/test-class-quiz.php b/tests/unit-tests/test-class-quiz.php index e898fc57da..9bbb03b8fb 100644 --- a/tests/unit-tests/test-class-quiz.php +++ b/tests/unit-tests/test-class-quiz.php @@ -1988,4 +1988,39 @@ public function testQuizFooterActions_WhenAwaitingGradeInLearningMode_RendersAwa /* Assert */ $this->assertStringContainsString( 'Pending teacher grade', $result ); } + + public function testQuizFooterActions_WhenAwaitingGradeButNotInLearningMode_DoesNotRenderAwaitingGradeButton() { + /* Arrange */ + $user_id = $this->factory->user->create(); + $course_id = $this->factory->course->create(); + $lesson_id = $this->factory->lesson->create( + [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ] + ); + + $quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id ); + $course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id ); + $course_enrolment->enrol( $user_id ); + + wp_set_current_user( $user_id ); + + + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'ungraded' ); + + $this->go_to( get_permalink( $quiz_id ) ); + + WP_Block_Supports::$block_to_render = [ + 'attrs' => [], + 'blockName' => 'sensei-lms/quiz-actions', + ]; + + /* Act */ + $result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render(); + + /* Assert */ + $this->assertStringNotContainsString( 'Pending teacher grade', $result ); + } } From fb0544a2fb302f72ddadb45955bcf1ebabac308a Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 13:50:02 +0600 Subject: [PATCH 22/25] Test that pending button is not rendered when lesson passed --- tests/unit-tests/test-class-quiz.php | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/unit-tests/test-class-quiz.php b/tests/unit-tests/test-class-quiz.php index 9bbb03b8fb..f815dc108b 100644 --- a/tests/unit-tests/test-class-quiz.php +++ b/tests/unit-tests/test-class-quiz.php @@ -2023,4 +2023,41 @@ public function testQuizFooterActions_WhenAwaitingGradeButNotInLearningMode_Does /* Assert */ $this->assertStringNotContainsString( 'Pending teacher grade', $result ); } + + public function testQuizFooterActions_WhenPassedButInLearningMode_DoesNotRenderAwaitingGradeButton() { + /* Arrange */ + $user_id = $this->factory->user->create(); + $course_id = $this->factory->course->create(); + $lesson_id = $this->factory->lesson->create( + [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ] + ); + + $quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id ); + $course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id ); + $course_enrolment->enrol( $user_id ); + + wp_set_current_user( $user_id ); + + // Enable course theme; + update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME ); + + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'passed' ); + + $this->go_to( get_permalink( $quiz_id ) ); + + WP_Block_Supports::$block_to_render = [ + 'attrs' => [], + 'blockName' => 'sensei-lms/quiz-actions', + ]; + + /* Act */ + $result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render(); + + /* Assert */ + $this->assertStringNotContainsString( 'Pending teacher grade', $result ); + } } From 7836ed97ddf1d5c3c554dd6f671248c8f7d9a4fd Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 13:50:32 +0600 Subject: [PATCH 23/25] Test that pending button is not rendered when in progress --- tests/unit-tests/test-class-quiz.php | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/unit-tests/test-class-quiz.php b/tests/unit-tests/test-class-quiz.php index f815dc108b..5cb1f21cf5 100644 --- a/tests/unit-tests/test-class-quiz.php +++ b/tests/unit-tests/test-class-quiz.php @@ -2060,4 +2060,42 @@ public function testQuizFooterActions_WhenPassedButInLearningMode_DoesNotRenderA /* Assert */ $this->assertStringNotContainsString( 'Pending teacher grade', $result ); } + + public function testQuizFooterActions_WhenInProgressButInLearningMode_DoesNotRenderAwaitingGradeButton() { + /* Arrange */ + $user_id = $this->factory->user->create(); + $course_id = $this->factory->course->create(); + $lesson_id = $this->factory->lesson->create( + [ + 'meta_input' => [ + '_lesson_course' => $course_id, + ], + ] + ); + + $quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id ); + $course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id ); + $course_enrolment->enrol( $user_id ); + + wp_set_current_user( $user_id ); + + // Enable course theme; + update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME ); + + // Explicitly set the lesson status to in-progress just to make sure. + Sensei_Utils::update_lesson_status( $user_id, $lesson_id ); + + $this->go_to( get_permalink( $quiz_id ) ); + + WP_Block_Supports::$block_to_render = [ + 'attrs' => [], + 'blockName' => 'sensei-lms/quiz-actions', + ]; + + /* Act */ + $result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render(); + + /* Assert */ + $this->assertStringNotContainsString( 'Pending teacher grade', $result ); + } } From 5c867a1fd75bfa79996e0179b9ea0901c01703ec Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 13:56:46 +0600 Subject: [PATCH 24/25] Remove extra line --- tests/unit-tests/test-class-quiz.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit-tests/test-class-quiz.php b/tests/unit-tests/test-class-quiz.php index 5cb1f21cf5..ef219e53bf 100644 --- a/tests/unit-tests/test-class-quiz.php +++ b/tests/unit-tests/test-class-quiz.php @@ -2007,7 +2007,6 @@ public function testQuizFooterActions_WhenAwaitingGradeButNotInLearningMode_Does wp_set_current_user( $user_id ); - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'ungraded' ); $this->go_to( get_permalink( $quiz_id ) ); From 1a279798fd9048141db52b7d26f4b9923d9c82a8 Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Mon, 2 Oct 2023 13:58:23 +0600 Subject: [PATCH 25/25] Fix lint issue --- tests/unit-tests/test-class-quiz.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit-tests/test-class-quiz.php b/tests/unit-tests/test-class-quiz.php index ef219e53bf..6a896a45d7 100644 --- a/tests/unit-tests/test-class-quiz.php +++ b/tests/unit-tests/test-class-quiz.php @@ -1972,7 +1972,6 @@ public function testQuizFooterActions_WhenAwaitingGradeInLearningMode_RendersAwa // Enable course theme; update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME ); - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'ungraded' ); $this->go_to( get_permalink( $quiz_id ) );