Commit 2384dc7d authored by victor's avatar victor 🙇
Browse files

Merge branch 'MDL-72496-master_assert_tag' of https://github.com/call-learning/moodle

parents 23a5ce9a 93a3724d
...@@ -55,7 +55,7 @@ abstract class base_testcase extends PHPUnit\Framework\TestCase { ...@@ -55,7 +55,7 @@ abstract class base_testcase extends PHPUnit\Framework\TestCase {
public static function assertTag($matcher, $actual, $message = '', $ishtml = true) { public static function assertTag($matcher, $actual, $message = '', $ishtml = true) {
$dom = (new PHPUnit\Util\Xml\Loader)->load($actual, $ishtml); $dom = (new PHPUnit\Util\Xml\Loader)->load($actual, $ishtml);
$tags = self::findNodes($dom, $matcher, $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); self::assertTrue($matched, $message);
} }
......
...@@ -145,6 +145,16 @@ STRING; ...@@ -145,6 +145,16 @@ STRING;
$this->testassertexecuted = false; $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. // Uncomment following tests to see logging of unexpected changes in global state and database.
/* /*
public function test_db_modification() { 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