示例#1
0
 /**
  * Test passing through isNotNormalRequest when user agent is not a bot.
  *
  * @covers ::handle
  * @covers ::isNotNormalRequest
  * @covers ::__construct
  * @covers ::isIgnoreableRoute
  */
 public function testHandleIsNotNormalRequestPassThrough()
 {
     $config_factory = $this->getConfigFactoryStub();
     $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));
     $this->routeMatcher->expects($this->once())->method('getRouteName')->will($this->returnValue('not_cas.service'));
     $request_object = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
     $request_object->server = $server;
     $this->requestStack->expects($this->once())->method('getCurrentRequest')->will($this->returnValue($request_object));
     $server->expects($this->any())->method('get')->will($this->returnValue('NotAKnownBot'));
     // We want to check that we've gotten past this point.
     $_SESSION['cas_temp_disable'] = TRUE;
     $cas_subscriber->handle($this->event);
 }
示例#2
0
 /**
  * Tests that web crawlers do not trigger gateway mode.
  * 
  * @covers ::handle
  * @covers ::handleGateway
  * @covers ::isCrawlerRequest
  */
 public function testGatewayModeIgnoredWhenWebCrawlerRequest()
 {
     $config_factory = $this->getConfigFactoryStub(array('cas.settings' => array('forced_login.enabled' => FALSE, 'gateway.check_frequency' => CasHelper::CHECK_ALWAYS, '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));
     $this->routeMatcher->expects($this->once())->method('getRouteName')->will($this->returnValue('not_cas.service'));
     $request_object = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
     $request_object->server = $server;
     $request_object->expects($this->any())->method('getSession')->will($this->returnValue($this->session));
     $this->requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request_object));
     $map = array(array('HTTP_USER_AGENT', NULL, FALSE, 'gsa-crawler'));
     $server->expects($this->any())->method('get')->will($this->returnValueMap($map));
     $this->event->expects($this->never())->method('setResponse');
     $cas_subscriber->handle($this->event);
 }
示例#3
0
 /**
  * @covers ::getTasksBuild
  */
 public function testGetTasksBuildWithCacheabilityMetadata()
 {
     $definitions = $this->getLocalTaskFixtures();
     $this->pluginDiscovery->expects($this->once())->method('getDefinitions')->will($this->returnValue($definitions));
     // Set up some cacheablity metadata and ensure its merged together.
     $definitions['menu_local_task_test_tasks_settings']['cache_tags'] = ['tag.example1'];
     $definitions['menu_local_task_test_tasks_settings']['cache_contexts'] = ['context.example1'];
     $definitions['menu_local_task_test_tasks_edit']['cache_tags'] = ['tag.example2'];
     $definitions['menu_local_task_test_tasks_edit']['cache_contexts'] = ['context.example2'];
     // Test the cacheability metadata of access checking.
     $definitions['menu_local_task_test_tasks_view_child1']['access'] = AccessResult::allowed()->addCacheContexts(['user.permissions']);
     $this->setupFactoryAndLocalTaskPlugins($definitions, 'menu_local_task_test_tasks_view');
     $this->setupLocalTaskManager();
     $this->controllerResolver->expects($this->any())->method('getArguments')->willReturn([]);
     $this->routeMatch->expects($this->any())->method('getRouteName')->willReturn('menu_local_task_test_tasks_view');
     $this->routeMatch->expects($this->any())->method('getRawParameters')->willReturn(new ParameterBag());
     $cacheability = new CacheableMetadata();
     $local_tasks = $this->manager->getTasksBuild('menu_local_task_test_tasks_view', $cacheability);
     // Ensure that all cacheability metadata is merged together.
     $this->assertEquals(['tag.example1', 'tag.example2'], $cacheability->getCacheTags());
     $this->assertEquals(['context.example1', 'context.example2', 'route', 'user.permissions'], $cacheability->getCacheContexts());
 }