From 894ee17f5323b602694cfadaeca8a7744783f2ec Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Wed, 17 Apr 2024 16:17:27 +0200 Subject: [PATCH] MDL-81581 phpunit: Move multiple assert_same_xml() to common one --- question/engine/tests/helpers.php | 13 +++++++++++++ question/format/xml/tests/xmlformat_test.php | 5 ----- question/type/ddwtos/tests/question_type_test.php | 5 ----- .../type/gapselect/tests/question_type_test.php | 11 ----------- question/type/ordering/tests/questiontype_test.php | 11 ----------- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/question/engine/tests/helpers.php b/question/engine/tests/helpers.php index f83d9697a41..1e4ec1a38d1 100644 --- a/question/engine/tests/helpers.php +++ b/question/engine/tests/helpers.php @@ -602,6 +602,19 @@ abstract class question_testcase extends advanced_testcase { } return; } + + /** + * Check that 2 XML strings are the same, ignoring differences in line endings. + * + * @param string $expectedxml The expected XML string + * @param string $xml The XML string to check + */ + public function assert_same_xml($expectedxml, $xml) { + $this->assertEquals( + str_replace("\r\n", "\n", $expectedxml), + str_replace("\r\n", "\n", $xml) + ); + } } diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php index fd8138819c7..7362a1b2295 100644 --- a/question/format/xml/tests/xmlformat_test.php +++ b/question/format/xml/tests/xmlformat_test.php @@ -47,11 +47,6 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class xmlformat_test extends \question_testcase { - public function assert_same_xml($expectedxml, $xml) { - $this->assertEquals(str_replace("\r\n", "\n", $expectedxml), - str_replace("\r\n", "\n", $xml)); - } - public function make_test_question() { global $USER; $q = new \stdClass(); diff --git a/question/type/ddwtos/tests/question_type_test.php b/question/type/ddwtos/tests/question_type_test.php index 16de9a09e35..347bc169260 100644 --- a/question/type/ddwtos/tests/question_type_test.php +++ b/question/type/ddwtos/tests/question_type_test.php @@ -47,11 +47,6 @@ class question_type_test extends \question_testcase { $this->qtype = null; } - public function assert_same_xml($expectedxml, $xml) { - $this->assertEquals(str_replace("\r\n", "\n", $expectedxml), - str_replace("\r\n", "\n", $xml)); - } - /** * Get some test question data. * diff --git a/question/type/gapselect/tests/question_type_test.php b/question/type/gapselect/tests/question_type_test.php index 019542fc56f..0ad8b3b40af 100644 --- a/question/type/gapselect/tests/question_type_test.php +++ b/question/type/gapselect/tests/question_type_test.php @@ -46,17 +46,6 @@ class question_type_test extends \question_testcase { $this->qtype = null; } - /** - * Asserts that two strings containing XML are the same ignoring the line-endings. - * - * @param string $expectedxml - * @param string $xml - */ - public function assert_same_xml($expectedxml, $xml) { - $this->assertEquals(str_replace("\r\n", "\n", $expectedxml), - str_replace("\r\n", "\n", $xml)); - } - public function test_save_question() { $this->resetAfterTest(); diff --git a/question/type/ordering/tests/questiontype_test.php b/question/type/ordering/tests/questiontype_test.php index e9b98b3795f..c82f9ee8066 100644 --- a/question/type/ordering/tests/questiontype_test.php +++ b/question/type/ordering/tests/questiontype_test.php @@ -72,17 +72,6 @@ final class questiontype_test extends \question_testcase { ]; } - /** - * Asserts that two XML strings are the same, ignoring differences in line endings. - * - * @param string $expectedxml - * @param string $xml - */ - public function assert_same_xml(string $expectedxml, string $xml): void { - $this->assertEquals(str_replace("\r\n", "\n", $expectedxml), - str_replace("\r\n", "\n", $xml)); - } - public function test_name(): void { $ordering = new qtype_ordering(); $this->assertEquals('ordering', $ordering->name());