You are here

public function ChainResponsePolicyTest::testStopChainOnFirstDeny in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 117
Contains \Drupal\Tests\Core\PageCache\ChainResponsePolicyTest.

Class

ChainResponsePolicyTest
@coversDefaultClass \Drupal\Core\PageCache\ChainResponsePolicy @group PageCache

Namespace

Drupal\Tests\Core\PageCache

Code

public function testStopChainOnFirstDeny() {
  $rule1 = $this
    ->getMock('Drupal\\Core\\PageCache\\ResponsePolicyInterface');
  $rule1
    ->expects($this
    ->once())
    ->method('check')
    ->with($this->response, $this->request);
  $this->policy
    ->addPolicy($rule1);
  $deny_rule = $this
    ->getMock('Drupal\\Core\\PageCache\\ResponsePolicyInterface');
  $deny_rule
    ->expects($this
    ->once())
    ->method('check')
    ->with($this->response, $this->request)
    ->will($this
    ->returnValue(ResponsePolicyInterface::DENY));
  $this->policy
    ->addPolicy($deny_rule);
  $ignored_rule = $this
    ->getMock('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);
}