Example #1
0
 /**
  * Test processing gateway with CHECK_ONCE to make sure SESSION gets set.
  *
  * @covers ::handle
  * @covers ::handleGateway
  */
 public function testHandleGatewayWithCheckOnceSuccess()
 {
     $config_factory = $this->getConfigFactoryStub(array('cas.settings' => array('forced_login.enabled' => TRUE, 'forced_login.paths' => array('<front>'), 'gateway.check_frequency' => CasHelper::CHECK_ONCE, 'gateway.paths' => array('<front>'))));
     $cas_subscriber = $this->getMockBuilder('\\Drupal\\cas\\Subscriber\\CasSubscriber')->setConstructorArgs(array($this->requestStack, $this->routeMatcher, $config_factory, $this->currentUser, $this->conditionManager, $this->casHelper))->setMethods(NULL)->getMock();
     $this->event->expects($this->any())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     $request_object = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $attributes = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ParameterBag');
     $request_object->attributes = $attributes;
     $server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
     $request_object->server = $server;
     $condition = $this->getMockBuilder('\\Drupal\\Core\\Condition\\ConditionPluginBase')->disableOriginalConstructor()->getMock();
     $this->conditionManager->expects($this->any())->method('createInstance')->with('request_path')->will($this->returnValue($condition));
     $condition->expects($this->any())->method('setConfiguration')->with(array('<front>'));
     $this->conditionManager->expects($this->any())->method('execute')->with($condition)->will($this->onConsecutiveCalls(FALSE, TRUE));
     $request_object->expects($this->once())->method('isMethod')->with('GET')->will($this->returnValue(TRUE));
     $this->requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request_object));
     $this->casHelper->expects($this->once())->method('getServerLoginUrl')->will($this->returnValue('https://example.com'));
     $this->event->expects($this->once())->method('setResponse');
     $cas_subscriber->handle($this->event);
     $this->assertArrayHasKey('cas_gateway_checked', $_SESSION);
 }