MDL-81581 phpunit: Move multiple assert_same_xml() to common one

This commit is contained in:
Eloy Lafuente (stronk7) 2024-04-17 16:17:27 +02:00
parent 792698af00
commit 17237b824d
No known key found for this signature in database
GPG Key ID: 53487A05E6228820
5 changed files with 13 additions and 32 deletions

View File

@ -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)
);
}
}

View File

@ -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();

View File

@ -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.
*

View File

@ -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();

View File

@ -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());