Skip to content

Commit

Permalink
Add test that for more subsequent calls, it doesn't publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Imran92 committed Apr 5, 2024
1 parent bd304e9 commit 45c7eb2
Showing 1 changed file with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function testMaybePublishLessons_WhenFirstPublished_SetsThePublishContinu
}

/**
* When Course is switched to publish state, the flag is set.
* In the first subsequent call, the lessons are published.
*
* @covers Sensei_Course_Pre_Publish_Panel::maybe_publish_lessons
*/
Expand All @@ -169,7 +169,7 @@ public function testMaybePublishLessons_WhenFirstPublished_OnlyTheSubsequentCall
// This mimics a new unsaved lesson that just became a saved one in draft state via the Course structure save call. This needs to get published in the next call.
$unsaved_to_draft_lesson_id = $this->factory->lesson->create(
[
'post_status' => 'publish',
'post_status' => 'draft',
'meta_input' => [
'_lesson_course' => $this->course_id,
],
Expand All @@ -186,4 +186,57 @@ public function testMaybePublishLessons_WhenFirstPublished_OnlyTheSubsequentCall
/* Assert */
$this->assertEquals( 'publish', get_post_status( $unsaved_to_draft_lesson_id ) );
}

/**
* In the first subsequent call, the lessons are published, but not in the second or more subsequent calls.
*
* @covers Sensei_Course_Pre_Publish_Panel::maybe_publish_lessons
*/
public function testMaybePublishLessons_AfterFirstPublishSequence_FartherSubsequentCallsDoNotPublishLessons() {
/* Arrange */
// Check the comments in the previous test for the explanation of the testing.
$this->login_as_admin();
update_post_meta( $this->course_id, 'sensei_course_publish_lessons', true );

Sensei_Course_Pre_Publish_Panel::instance()->maybe_publish_lessons( $this->course_id, null, 'draft' );

$unsaved_to_draft_lesson_id = $this->factory->lesson->create(
[
'post_status' => 'draft',
'meta_input' => [
'_lesson_course' => $this->course_id,
],
]
);
Sensei_Course_Pre_Publish_Panel::instance()->maybe_publish_lessons( $this->course_id, null, 'publish' );

$unsaved_to_draft_lesson_id_2 = $this->factory->lesson->create(
[
'post_status' => 'draft',
'meta_input' => [
'_lesson_course' => $this->course_id,
],
]
);
Sensei_Course_Pre_Publish_Panel::instance()->maybe_publish_lessons( $this->course_id, null, 'publish' );

$unsaved_to_draft_lesson_id_3 = $this->factory->lesson->create(
[
'post_status' => 'draft',
'meta_input' => [
'_lesson_course' => $this->course_id,
],
]
);

/* Act */
// See comments in the previous test for the explanation of the 'old_status'.
Sensei_Course_Pre_Publish_Panel::instance()->maybe_publish_lessons( $this->course_id, null, 'publish' );

/* Assert */
$this->assertEquals( 'publish', get_post_status( $this->lesson_id ) );
$this->assertEquals( 'publish', get_post_status( $unsaved_to_draft_lesson_id ) );
$this->assertEquals( 'draft', get_post_status( $unsaved_to_draft_lesson_id_2 ) );
$this->assertEquals( 'draft', get_post_status( $unsaved_to_draft_lesson_id_3 ) );
}
}

0 comments on commit 45c7eb2

Please sign in to comment.