function ConditionAccessResolverTraitTest::testResolveConditions

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php \Drupal\Tests\Core\Condition\ConditionAccessResolverTraitTest::testResolveConditions()
  2. 8.9.x core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php \Drupal\Tests\Core\Condition\ConditionAccessResolverTraitTest::testResolveConditions()
  3. 11.x core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php \Drupal\Tests\Core\Condition\ConditionAccessResolverTraitTest::testResolveConditions()

Tests the resolveConditions() method.

@covers ::resolveConditions

@dataProvider providerTestResolveConditions

File

core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php, line 23

Class

ConditionAccessResolverTraitTest
@coversDefaultClass \Drupal\Core\Condition\ConditionAccessResolverTrait @group Condition

Namespace

Drupal\Tests\Core\Condition

Code

public function testResolveConditions($conditions, $logic, $expected) : void {
    $mocks['true'] = $this->createMock('Drupal\\Core\\Condition\\ConditionInterface');
    $mocks['true']->expects($this->any())
        ->method('execute')
        ->willReturn(TRUE);
    $mocks['false'] = $this->createMock('Drupal\\Core\\Condition\\ConditionInterface');
    $mocks['false']->expects($this->any())
        ->method('execute')
        ->willReturn(FALSE);
    $mocks['exception'] = $this->createMock('Drupal\\Core\\Condition\\ConditionInterface');
    $mocks['exception']->expects($this->any())
        ->method('execute')
        ->will($this->throwException(new ContextException()));
    $mocks['exception']->expects($this->any())
        ->method('isNegated')
        ->willReturn(FALSE);
    $mocks['negated'] = $this->createMock('Drupal\\Core\\Condition\\ConditionInterface');
    $mocks['negated']->expects($this->any())
        ->method('execute')
        ->will($this->throwException(new ContextException()));
    $mocks['negated']->expects($this->any())
        ->method('isNegated')
        ->willReturn(TRUE);
    $conditions = array_map(fn($id) => $mocks[$id], $conditions);
    $trait_object = new TestConditionAccessResolverTrait();
    $this->assertEquals($expected, $trait_object->resolveConditions($conditions, $logic));
}

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