You are here

public function ChainRequestPolicyTest::testStopChainOnFirstDeny in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php \Drupal\Tests\Core\PageCache\ChainRequestPolicyTest::testStopChainOnFirstDeny()

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

File

core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php, line 141
Contains \Drupal\Tests\Core\PageCache\ChainRequestPolicyTest.

Class

ChainRequestPolicyTest
@coversDefaultClass \Drupal\Core\PageCache\ChainRequestPolicy @group PageCache

Namespace

Drupal\Tests\Core\PageCache

Code

public function testStopChainOnFirstDeny() {
  $rule1 = $this
    ->getMock('Drupal\\Core\\PageCache\\RequestPolicyInterface');
  $rule1
    ->expects($this
    ->once())
    ->method('check')
    ->with($this->request)
    ->will($this
    ->returnValue(RequestPolicyInterface::ALLOW));
  $this->policy
    ->addPolicy($rule1);
  $deny_rule = $this
    ->getMock('Drupal\\Core\\PageCache\\RequestPolicyInterface');
  $deny_rule
    ->expects($this
    ->once())
    ->method('check')
    ->with($this->request)
    ->will($this
    ->returnValue(RequestPolicyInterface::DENY));
  $this->policy
    ->addPolicy($deny_rule);
  $ignored_rule = $this
    ->getMock('Drupal\\Core\\PageCache\\RequestPolicyInterface');
  $ignored_rule
    ->expects($this
    ->never())
    ->method('check');
  $this->policy
    ->addPolicy($ignored_rule);
  $actual_result = $this->policy
    ->check($this->request);
  $this
    ->assertsame(RequestPolicyInterface::DENY, $actual_result);
}