Commit 93a3724d authored by Laurent David's avatar Laurent David
Browse files

MDL-72496 question tests: fix assertTag if tag not found

* The basic_test::assertTag method will issue a warning as $tag is not
found, failing the PHP Unit test that uses this method.
* Add tests to check that assertTag is working
parent 214adb79
......@@ -55,7 +55,7 @@ abstract class base_testcase extends PHPUnit\Framework\TestCase {
public static function assertTag($matcher, $actual, $message = '', $ishtml = true) {
$dom = (new PHPUnit\Util\Xml\Loader)->load($actual, $ishtml);
$tags = self::findNodes($dom, $matcher, $ishtml);
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
$matched = (is_array($tags) && count($tags) > 0) && $tags[0] instanceof DOMNode;
self::assertTrue($matched, $message);
}
......
......@@ -145,6 +145,16 @@ STRING;
$this->testassertexecuted = false;
}
/**
* Test assert Tag
*/
public function test_assert_tag() {
// This should succeed.
self::assertTag(['id' => 'testid'], "<div><span id='testid'></span></div>");
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class);
self::assertTag(['id' => 'testid'], "<div><div>");
}
// Uncomment following tests to see logging of unexpected changes in global state and database.
/*
public function test_db_modification() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment