function MarkupInterfaceComparator::assertEquals

Same name in other branches
  1. 9 core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php \Drupal\TestTools\Comparator\MarkupInterfaceComparator::assertEquals()
  2. 8.9.x core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php \Drupal\TestTools\Comparator\MarkupInterfaceComparator::assertEquals()
  3. 10 core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php \Drupal\TestTools\Comparator\MarkupInterfaceComparator::assertEquals()

File

core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php, line 29

Class

MarkupInterfaceComparator
Compares MarkupInterface objects for equality.

Namespace

Drupal\TestTools\Comparator

Code

public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = FALSE, $ignoreCase = FALSE) : void {
    if (is_scalar($expected) && is_scalar($actual)) {
        throw new \LogicException(__METHOD__ . '() should not be called directly. Use TestCase::assertEquals() instead');
    }
    if (is_array($expected) || is_array($actual)) {
        throw new \InvalidArgumentException('Expected and actual arguments passed to ' . __METHOD__ . '() must not be arrays');
    }
    $expected_safe = (string) $expected;
    $actual_safe = (string) $actual;
    $expected_safe_stripped = strip_tags($expected_safe);
    $actual_safe_stripped = strip_tags($actual_safe);
    if (!($expected instanceof MarkupInterface && $actual instanceof MarkupInterface)) {
        if ($expected_safe !== $expected_safe_stripped && $actual_safe !== $actual_safe_stripped) {
            throw new \RuntimeException("Cannot compare markup between MarkupInterface objects and plain strings");
        }
    }
    $comparator = $this->factory()
        ->getComparatorFor($expected_safe_stripped, $actual_safe_stripped);
    $comparator->assertEquals($expected_safe_stripped, $actual_safe_stripped, $delta, $canonicalize, $ignoreCase);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.