Skip to content

Commit

Permalink
MDL-81581 phpunit: Move multiple assert_same_xml() to common one
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 25, 2024
1 parent 792698a commit 17237b8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
13 changes: 13 additions & 0 deletions question/engine/tests/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,19 @@ public function assert_select_options($expectation, $html) {
}
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)
);
}
}


Expand Down
5 changes: 0 additions & 5 deletions question/format/xml/tests/xmlformat_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
* @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();
Expand Down
5 changes: 0 additions & 5 deletions question/type/ddwtos/tests/question_type_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ protected function tearDown(): void {
$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.
*
Expand Down
11 changes: 0 additions & 11 deletions question/type/gapselect/tests/question_type_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ protected function tearDown(): void {
$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();

Expand Down
11 changes: 0 additions & 11 deletions question/type/ordering/tests/questiontype_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ private static function expectedimport(): object {
];
}

/**
* 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());
Expand Down

0 comments on commit 17237b8

Please sign in to comment.