function ChainResponsePolicyTest::testStopChainOnFirstDeny

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php \Drupal\Tests\Core\PageCache\ChainResponsePolicyTest::testStopChainOnFirstDeny()
  2. 8.9.x core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php \Drupal\Tests\Core\PageCache\ChainResponsePolicyTest::testStopChainOnFirstDeny()
  3. 10 core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php \Drupal\Tests\Core\PageCache\ChainResponsePolicyTest::testStopChainOnFirstDeny()

Asserts that check() returns immediately when a rule returned DENY.

File

core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php, line 118

Class

ChainResponsePolicyTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21PageCache%21ChainResponsePolicy.php/class/ChainResponsePolicy/11.x" title="Implements a compound response policy." class="local">\Drupal\Core\PageCache\ChainResponsePolicy</a> @group PageCache

Namespace

Drupal\Tests\Core\PageCache

Code

public function testStopChainOnFirstDeny() : void {
    $rule1 = $this->createMock('Drupal\\Core\\PageCache\\ResponsePolicyInterface');
    $rule1->expects($this->once())
        ->method('check')
        ->with($this->response, $this->request);
    $this->policy
        ->addPolicy($rule1);
    $deny_rule = $this->createMock('Drupal\\Core\\PageCache\\ResponsePolicyInterface');
    $deny_rule->expects($this->once())
        ->method('check')
        ->with($this->response, $this->request)
        ->willReturn(ResponsePolicyInterface::DENY);
    $this->policy
        ->addPolicy($deny_rule);
    $ignored_rule = $this->createMock('Drupal\\Core\\PageCache\\ResponsePolicyInterface');
    $ignored_rule->expects($this->never())
        ->method('check');
    $this->policy
        ->addPolicy($ignored_rule);
    $actual_result = $this->policy
        ->check($this->response, $this->request);
    $this->assertSame(ResponsePolicyInterface::DENY, $actual_result);
}

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