From c377d42d8773f6f458b772a23effd223049ffde0 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Thu, 4 Dec 2025 08:54:04 +0700 Subject: [PATCH] MDL-72744 table: Improve PHPUnit test --- lib/tests/tablelib_test.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/tests/tablelib_test.php b/lib/tests/tablelib_test.php index c04fcf9acd9..ebbc84cfbba 100644 --- a/lib/tests/tablelib_test.php +++ b/lib/tests/tablelib_test.php @@ -835,7 +835,7 @@ final class tablelib_test extends \advanced_testcase { public function test_table_exports_escaped_formulas(): void { $table = new flexible_table('tablelib_test_export'); $table->define_baseurl('/invalid.php'); - $table->define_columns(['c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8']); + $table->define_columns(['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6']); ob_start(); $table->is_downloadable(true); @@ -843,19 +843,19 @@ final class tablelib_test extends \advanced_testcase { $table->setup(); $table->add_data([ - 'column0' => "\t=SUM(1+1)", // With tab. - 'column1' => "\r=SUM(1+1)", // With carriage return. - 'column2' => "\n=SUM(1+1)", // With new line. - 'column3' => "=SUM(1+1)", - 'column4' => "=1+1", - 'column5' => "+1+1", - 'column6' => "-1+1", - 'column7' => "@A1", - 'column8' => "-", // Single dash (should not be escaped). + 'column0' => " =SUM(1+1)", // With spaces. + 'column1' => "=SUM(1+1)", + 'column2' => "=1+1", + 'column3' => "+1+1", + 'column4' => "-1+1", + 'column5' => "@A1", + 'column6' => "-", // Single dash (should not be escaped). ]); + $output = ob_get_contents(); ob_end_clean(); - $this->assertEquals("\n'=SUM(1+1),'=SUM(1+1),'=SUM(1+1),'=SUM(1+1),'=1+1,'+1+1,'-1+1,'@A1,-\n", substr($output, 3)); + $matchregex = "/\"?' =SUM\(1\+1\)\"?,'=SUM\(1\+1\),'=1\+1,'\+1\+1,'-1\+1,'@A1,-/"; + $this->assertMatchesRegularExpression($matchregex, $output); } }