function HTMLRestrictionsTest::testOperations

Same name and namespace in other branches
  1. 10 core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testOperations()
  2. 11.x core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testOperations()

@covers ::diff() @covers ::intersect() @covers ::merge() @dataProvider providerOperands

File

core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php, line 879

Class

HTMLRestrictionsTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21ckeditor5%21src%21HTMLRestrictions.php/class/HTMLRestrictions/9" title="Represents a set of HTML restrictions." class="local">\Drupal\ckeditor5\HTMLRestrictions</a> @group ckeditor5

Namespace

Drupal\Tests\ckeditor5\Unit

Code

public function testOperations(HTMLRestrictions $a, HTMLRestrictions $b, $expected_diff, $expected_intersection, $expected_union) : void {
    // This looks more complicated than it is: it applies the same processing to
    // all three of the expected operation results.
    foreach ([
        'diff',
        'intersection',
        'union',
    ] as $op) {
        $parameter = "expected_{$op}";
        // Ensure that the operation expectation is 'a' or 'b' whenever possible.
        if ($a == ${$parameter}) {
            throw new \LogicException("List 'a' as the expected {$op} rather than specifying it in full, to keep the tests legible.");
        }
        else {
            if ($b == ${$parameter}) {
                throw new \LogicException("List 'b' as the expected {$op} rather than specifying it in full, to keep the tests legible.");
            }
        }
        // Map any expected 'a' or 'b' string value to the corresponding operand.
        if (${$parameter} === 'a') {
            ${$parameter} = $a;
        }
        elseif (${$parameter} === 'b') {
            ${$parameter} = $b;
        }
        assert(${$parameter} instanceof HTMLRestrictions);
    }
    $this->assertEquals($expected_diff, $a->diff($b));
    $this->assertEquals($expected_intersection, $a->intersect($b));
    $this->assertEquals($expected_union, $a->merge($b));
}

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