You are here

public function AgreementSubscriberTest::testCheckForRedirection in Agreement 8.2

Same name and namespace in other branches
  1. 3.0.x tests/src/Unit/EventSubscriber/AgreementSubscriberTest.php \Drupal\Tests\agreement\Unit\EventSubscriber\AgreementSubscriberTest::testCheckForRedirection()

Asserts that check for redirection method is functional.

@dataProvider checkForRedirectionProvider

Parameters

bool $canBypass: Permission to bypass agreement.

bool $hasAgreement: Whether or not an agreement is "found" in this test.

bool $expected: Whether a redirect is expected or not.

File

tests/src/Unit/EventSubscriber/AgreementSubscriberTest.php, line 32

Class

AgreementSubscriberTest
Tests the agreement route subscriber.

Namespace

Drupal\Tests\agreement\Unit\EventSubscriber

Code

public function testCheckForRedirection($canBypass, $hasAgreement, $expected) {
  $pathProphet = $this
    ->prophesize('\\Drupal\\Core\\Path\\CurrentPathStack');
  $pathProphet
    ->getPath(Argument::any())
    ->willReturn('test');
  $sessionProphet = $this
    ->prophesize('\\Drupal\\Core\\Session\\SessionManagerInterface');
  $kernelProphet = $this
    ->prophesize('\\Drupal\\Core\\DrupalKernelInterface');
  $request = new Request();
  $event = new GetResponseEvent($kernelProphet
    ->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
  $subscriber = new AgreementSubscriber($this
    ->getAgreementHandlerStub($hasAgreement), $pathProphet
    ->reveal(), $sessionProphet
    ->reveal(), $this
    ->getAccountStub($canBypass));
  $subscriber
    ->checkForRedirection($event);
  $isRedirect = $event
    ->getResponse() !== NULL ? $event
    ->getResponse()
    ->isRedirect() : FALSE;
  $this
    ->assertEquals($expected, $isRedirect);
}