* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\EventListener\FragmentListener; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\UriSigner; class FragmentListenerTest extends TestCase { public function testOnlyTriggeredOnFragmentRoute() { $request = Request::create('http://example.com/foo?_path=foo%3Dbar%26_controller%3Dfoo'); $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $expected = $request->attributes->all(); $listener->onKernelRequest($event); $this->assertEquals($expected, $request->attributes->all()); $this->assertTrue($request->query->has('_path')); } public function testOnlyTriggeredIfControllerWasNotDefinedYet() { $request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'); $request->attributes->set('_controller', 'bar'); $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST); $expected = $request->attributes->all(); $listener->onKernelRequest($event); $this->assertEquals($expected, $request->attributes->all()); } /** * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testAccessDeniedWithNonSafeMethods() { $request = Request::create('http://example.com/_fragment', 'POST'); $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); } /** * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testAccessDeniedWithWrongSignature() { $request = Request::create('http://example.com/_fragment', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); } public function testWithSignature() { $signer = new UriSigner('foo'); $request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); $listener = new FragmentListener($signer); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); $this->assertEquals(array('foo' => 'bar', '_controller' => 'foo'), $request->attributes->get('_route_params')); $this->assertFalse($request->query->has('_path')); } public function testRemovesPathWithControllerDefined() { $request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'); $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST); $listener->onKernelRequest($event); $this->assertFalse($request->query->has('_path')); } public function testRemovesPathWithControllerNotDefined() { $signer = new UriSigner('foo'); $request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); $listener = new FragmentListener($signer); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); $this->assertFalse($request->query->has('_path')); } private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST) { return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, $requestType); } } __halt_compiler();----SIGNATURE:----lBtR62d1imbTGXHExc5ylpGHbVgz6OeloBth8tmnC/5RQpECanGg+68xpnzdhbPpt7d1eTkimR3jVbwaTZ4HwCgG5uCpyqP60tGDWy0P9QAvcQwMGX7o7paAAbPTehyhkJZYwchNDmTVAMg5l1Ui2U31iRtqD2IvGEMsBVb1Qq4Uh1P16KaNMnnQR2mkiTz9ujO8otzJw5GORUv/RQTXTTbj67385M8VedSCbS/4fCLloSdyeGbJ+0/6I931UAmVys0p5I4zPWzjjEvxHOt8IMxsCfcR0q6/4Lhr8W6BJNWvgsoZ2/+/b/D61EMZP/XtnAHu0BKzXoNunZh/ideNA8npZK1NJbT9frPWP5DMKILQW9RkXQb4ycQlC8jkExXhUPU6A5BZeZsq2e57teQavtDEIcj/LozGg2A3CF0dVoHdutvmi9eC3BkW8xD8zYK7Zqm7XJUtdwADnIC7cuQ8pLT6C4dcwd0ZVpIPIuUDlTKMBTmlH71oy47aHf2upoDbYE/gJ/1gj68XbvAS1z5bPmPinj7kb72jwYaXoQf1Agba1J76nAd57/ztg9/hENY7lSrfKpbd6/zKD4EIcxh9rHyUe8foGQcf8/EYZDbCYPdV4rkGY1JL2YtojDYb/iKMWzaDycqqxFSJCrofGaRiHIn4IXsn2ENmK/RtBy2PYL4=----ATTACHMENT:----OTE1NjUzNzQxMjI5NTUyNSAzMjc0Nzg2ODcxODgwMjU1IDI4NTk0NTI4NDk5MzMyNjM=