From 898f3d0a829eacefe859d09d1420c99076f1fe36 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 3 Mar 2022 11:09:59 +0800 Subject: [PATCH] MDL-73996 reportbuilder: Assert task log contains expected strings * Ordering issues from \core_reportbuilder\local\helpers\schedule's get_schedule_report_users() method won't guarantee that the expected task log output will always be the same as user two can be fetched first before user one which will cause the message to be sent to user two first. So just get the task log's output string and make sure it contains the expected log strings. --- reportbuilder/tests/task/send_schedule_test.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/reportbuilder/tests/task/send_schedule_test.php b/reportbuilder/tests/task/send_schedule_test.php index ed3e279f496..1170194a19e 100644 --- a/reportbuilder/tests/task/send_schedule_test.php +++ b/reportbuilder/tests/task/send_schedule_test.php @@ -109,14 +109,17 @@ class send_schedule_test extends advanced_testcase { // Send the schedule, catch emails in sink. $sink = $this->redirectEmails(); - $this->expectOutputRegex("/^Sending schedule: My schedule\n" . - " Sending to: " . fullname($userone) . "\n" . - " Sending to: " . fullname($usertwo) . "\n" . - "Sending schedule complete\n/" - ); + ob_start(); $sendschedule = new send_schedule(); $sendschedule->set_custom_data(['reportid' => $report->get('id'), 'scheduleid' => $schedule->get('id')]); $sendschedule->execute(); + $output = ob_get_clean(); + + // Assert the output contains the following messages. + $this->assertStringContainsString("Sending schedule: My schedule", $output); + $this->assertStringContainsString("Sending to: " . fullname($userone), $output); + $this->assertStringContainsString("Sending to: " . fullname($usertwo), $output); + $this->assertStringContainsString("Sending schedule complete", $output); $messages = $sink->get_messages(); $this->assertCount(2, $messages);