From 802dbbf882bfba3112bbb18e9450534e7299705c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 8 May 2015 15:36:10 +0800 Subject: [PATCH] MDL-50153 messageinbound: Normalise line endings instead of rtrim --- lib/tests/messageinbound_test.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/tests/messageinbound_test.php b/lib/tests/messageinbound_test.php index 83091c32236..8baf461623c 100644 --- a/lib/tests/messageinbound_test.php +++ b/lib/tests/messageinbound_test.php @@ -50,9 +50,10 @@ class core_messageinbound_testcase extends advanced_testcase { $messagedata->html = ''; list($message, $format) = test_handler::remove_quoted_text($messagedata); + list ($message, $expectedplain) = preg_replace("#\r\n#", "\n", array($message, $expectedplain)); - // Trim both the expected and the actual - we are not concerned about trailing whitespace. - $this->assertEquals(rtrim($expectedplain), rtrim($message)); + // Normalise line endings on both strings. + $this->assertEquals($expectedplain, $message); $this->assertEquals(FORMAT_PLAIN, $format); } @@ -63,8 +64,9 @@ class core_messageinbound_testcase extends advanced_testcase { list($message, $format) = test_handler::remove_quoted_text($messagedata); - // Trim both the expected and the actual - we are not concerned about trailing whitespace. - $this->assertEquals(rtrim($expectedhtml), rtrim($message)); + // Normalise line endings on both strings. + list ($message, $expectedhtml) = preg_replace("#\r\n#", "\n", array($message, $expectedhtml)); + $this->assertEquals($expectedhtml, $message); $this->assertEquals(FORMAT_PLAIN, $format); } } @@ -107,7 +109,9 @@ class core_messageinbound_testcase extends advanced_testcase { protected function read_test_file(\SplFileInfo $file, $fixturesdir) { // Break on the --[TOKEN]-- tags in the file. - $tokens = preg_split('#(?:^|[\r]?\n*)----([A-Z]+)----[\r]?\n#', file_get_contents($file->getRealPath()), + $content = file_get_contents($file->getRealPath()); + $content = preg_replace("#\r\n#", "\n", $content); + $tokens = preg_split('#(?:^|\n*)----([A-Z]+)----\n#', file_get_contents($file->getRealPath()), null, PREG_SPLIT_DELIM_CAPTURE); $sections = array( // Key => Required.