diff --git a/lib/phpunit/classes/base_testcase.php b/lib/phpunit/classes/base_testcase.php index f24c5624e2f..3fb2b9ac6c3 100644 --- a/lib/phpunit/classes/base_testcase.php +++ b/lib/phpunit/classes/base_testcase.php @@ -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); } diff --git a/lib/phpunit/tests/basic_test.php b/lib/phpunit/tests/basic_test.php index 04b75c5caee..ab862042938 100644 --- a/lib/phpunit/tests/basic_test.php +++ b/lib/phpunit/tests/basic_test.php @@ -146,6 +146,16 @@ STRING; $this->testassertexecuted = false; } + /** + * Test assert Tag + */ + public function test_assert_tag() { + // This should succeed. + self::assertTag(['id' => 'testid'], "
"); + $this->expectException(\PHPUnit\Framework\ExpectationFailedException::class); + self::assertTag(['id' => 'testid'], "
"); + } + // Uncomment following tests to see logging of unexpected changes in global state and database. /* public function test_db_modification() {