예제 #1
0
 /**
  * Tests an unbanned IP.
  */
 public function testUnbannedIp()
 {
     $unbanned_ip = '18.0.0.2';
     $this->banManager->expects($this->once())->method('isBanned')->with($unbanned_ip)->willReturn(FALSE);
     $request = Request::create('/test-path');
     $request->server->set('REMOTE_ADDR', $unbanned_ip);
     $expected_response = new Response(200);
     $this->kernel->expects($this->once())->method('handle')->with($request, HttpKernelInterface::MASTER_REQUEST, TRUE)->willReturn($expected_response);
     $response = $this->banMiddleware->handle($request);
     $this->assertSame($expected_response, $response);
 }
 /**
  * Tests onHandleException with a GET request.
  */
 public function testHandleWithGetRequest()
 {
     $request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
     $this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
         return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
     }));
     $event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new \Exception('foo'));
     $this->exceptionListener->onKernelException($event);
     $response = $event->getResponse();
     $this->assertEquals('GET name=druplicon&pass=12345 ', $response->getContent() . " " . UrlHelper::buildQuery($request->request->all()));
 }
    public function testOnKernelRequestForward()
    {
        $queryParameters = array( 'some' => 'thing' );
        $cookieParameters = array( 'cookie' => 'value' );
        $request = Request::create( '/test_sa/foo/bar', 'GET', $queryParameters, $cookieParameters );
        $semanticPathinfo = '/foo/something';
        $request->attributes->set( 'semanticPathinfo', $semanticPathinfo );
        $request->attributes->set( 'needsForward', true );
        $request->attributes->set( 'someAttribute', 'someValue' );

        $expectedForwardRequest = Request::create( $semanticPathinfo, 'GET', $queryParameters, $cookieParameters );
        $expectedForwardRequest->attributes->set( 'semanticPathinfo', $semanticPathinfo );
        $expectedForwardRequest->attributes->set( 'someAttribute', 'someValue' );

        $response = new Response( 'Success!' );
        $this->httpKernel
            ->expects( $this->once() )
            ->method( 'handle' )
            ->with( $this->equalTo( $expectedForwardRequest ) )
            ->will( $this->returnValue( $response ) );

        $event = new GetResponseEvent( $this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST );
        $this->requestEventListener->onKernelRequestForward( $event );
        $this->assertSame( $response, $event->getResponse() );
        $this->assertTrue( $event->isPropagationStopped() );
    }
 /**
  * Tests onHandleException with a GET request.
  */
 public function testHandleWithGetRequest()
 {
     $request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
     $this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
         return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
     }));
     $event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
     $this->customPageSubscriber->onException($event);
     $response = $event->getResponse();
     $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
     $this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
 }
 /**
  * Tests onHandleException with a GET request.
  */
 public function testHandleWithGetRequest()
 {
     $request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
     $request->attributes->set(AccessAwareRouterInterface::ACCESS_RESULT, AccessResult::forbidden()->addCacheTags(['druplicon']));
     $request_context = new RequestContext();
     $request_context->fromRequest($request);
     $this->accessUnawareRouter->expects($this->any())->method('getContext')->willReturn($request_context);
     $this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
         return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
     }));
     $event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
     $this->customPageSubscriber->onException($event);
     $response = $event->getResponse();
     $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
     $this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
     $this->assertEquals(AccessResult::forbidden()->addCacheTags(['druplicon', 'foo', 'bar']), $request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
 }