Skip to content

Commit

Permalink
WIP: try to fix phpunit test for postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed May 28, 2024
1 parent f207468 commit 730b256
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions tests/review_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ private function create_post($options) {
list(, $teacherpost) = $this->generator->post_to_forum($moodleoverflow, $this->teacher);
list(, $studentpost) = $this->generator->post_to_forum($moodleoverflow, $this->student);

// Explicitly setting the fields
$teacherpost->mailed = MOODLEOVERFLOW_MAILED_PENDING;
$teacherpost->reviewed = 0;
$teacherpost->timereviewed = null;

$studentpost->mailed = MOODLEOVERFLOW_MAILED_PENDING;
$studentpost->reviewed = 0;
$studentpost->timereviewed = null;

return ['teacherpost' => $teacherpost, 'studentpost' => $studentpost];
}

Expand All @@ -297,20 +306,24 @@ private function create_post($options) {
private function check_mail_records($teacherpost, $studentpost, $review1, $review2, $mailed) {
global $DB;

$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING,
'reviewed' => $review1, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id]));
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING,
'reviewed' => $review2, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id]));
// Fetch the posts directly after creation
$teacherpostDB = $DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id]);
$studentpostDB = $DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id]);

// Assert initial state
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING, 'reviewed' => $review1, 'timereviewed' => null], $teacherpostDB);
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING, 'reviewed' => $review2, 'timereviewed' => null], $studentpostDB);

$this->run_send_mails();
$this->run_send_mails(); // Execute twice to ensure no duplicate mails.

$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_SUCCESS,
'reviewed' => $review1, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id]));
$this->assert_matches_properties(['mailed' => $mailed, 'reviewed' => $review2, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id]));
// Fetch the posts after mailing
$teacherpostDB = $DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id]);
$studentpostDB = $DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id]);

// Assert post-mail state
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_SUCCESS, 'reviewed' => $review1, 'timereviewed' => null], $teacherpostDB);
$this->assert_matches_properties(['mailed' => $mailed, 'reviewed' => $review2, 'timereviewed' => null], $studentpostDB);
}

}

0 comments on commit 730b256

Please sign in to comment.