-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7675 from Automattic/fix/timed-quiz-input-not-sto…
…pping-when-time-ends Fix timed quiz still working for students even after time ends
- Loading branch information
Showing
7 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.sensei-quiz-action--hidden { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Timed quiz not stopping when time ends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
tests/unit-tests/blocks/course-theme/test-class-quiz-actions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the Quiz_Actions_Test class. | ||
* | ||
* @package sensei | ||
*/ | ||
|
||
use Sensei\Blocks\Course_Theme\Quiz_Actions; | ||
|
||
/** | ||
* Tests for Quiz_Actions class. | ||
* | ||
* @covers Sensei\Blocks\Course_Theme\Quiz_Actions | ||
*/ | ||
class Quiz_Actions_Test extends WP_UnitTestCase { | ||
|
||
use Sensei_Course_Enrolment_Test_Helpers; | ||
use Sensei_Course_Enrolment_Manual_Test_Helpers; | ||
|
||
/** | ||
* Sensei factory instance. | ||
* | ||
* @var $factory | ||
*/ | ||
protected $factory; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->factory = new Sensei_Factory(); | ||
|
||
self::resetEnrolmentProviders(); | ||
} | ||
|
||
public function tearDown(): void { | ||
parent::tearDown(); | ||
$this->factory->tearDown(); | ||
|
||
// Remove all lessons. | ||
$lessons = get_posts( 'post_type=lesson' ); | ||
foreach ( $lessons as $index => $lesson ) { | ||
wp_delete_post( $lesson->ID, true ); | ||
} | ||
|
||
// Remove all quizzes. | ||
$quizzes = get_posts( 'post_type=quiz' ); | ||
foreach ( $quizzes as $index => $quiz ) { | ||
wp_delete_post( $quiz->ID, true ); | ||
} | ||
WP_Block_Supports::$block_to_render = null; | ||
|
||
self::resetEnrolmentProviders(); | ||
} | ||
|
||
public function testRender_WhenPaginationIsShown_AlwaysRendersQuizCompleteButton() { | ||
/* Arrange */ | ||
global $post, $sensei_question_loop; | ||
|
||
$this->addEnrolmentProvider( Sensei_Test_Enrolment_Provider_Always_Provides::class ); | ||
$this->prepareEnrolmentManager(); | ||
|
||
$user_id = $this->factory->user->create(); | ||
wp_set_current_user( $user_id ); | ||
|
||
$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 ); | ||
$post = get_post( $quiz_id ); | ||
|
||
$this->factory->question->create_many( 10, [ 'quiz_id' => $quiz_id ] ); | ||
|
||
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id ); | ||
$course_enrolment->enrol( $user_id ); | ||
|
||
update_post_meta( | ||
$quiz_id, | ||
'_pagination', | ||
wp_json_encode( [ 'pagination_number' => 2 ] ) | ||
); | ||
|
||
$this->go_to( get_permalink( $quiz_id ) ); | ||
|
||
WP_Block_Supports::$block_to_render = [ | ||
'attrs' => [], | ||
'blockName' => 'sensei-lms/quiz-actions', | ||
]; | ||
|
||
Sensei_Quiz::start_quiz_questions_loop(); | ||
|
||
/* Act */ | ||
$result_for_other_pages = ( new Quiz_Actions() )->render(); | ||
$sensei_question_loop['current_page'] = $sensei_question_loop['total_pages']; | ||
$result_for_last_page = ( new Quiz_Actions() )->render(); | ||
|
||
/* Assert */ | ||
$this->assertStringContainsString( 'sensei-quiz-action--hidden', $result_for_other_pages ); | ||
$this->assertStringNotContainsString( 'sensei-quiz-action--hidden', $result_for_last_page ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters