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
This commit is contained in:
Laurent David
2021-09-30 13:14:51 +02:00
parent 0360329c46
commit 5d5cd02239
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ abstract class base_testcase extends PHPUnit\Framework\TestCase {
public static function assertTag($matcher, $actual, $message = '', $ishtml = true) {
$dom = PHPUnit\Util\XML::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);
}