/** * @return ParameterBag|PHPUnit_Framework_MockObject_MockObject */ protected function getRequestAttributesMock() { if (!isset($this->requestAttributesMock)) { $this->requestAttributesMock = $this->getMock('Symfony\\Component\\HttpFoundation\\ParameterBag'); $this->requestAttributesMock->expects($this->once())->method('get')->with('is_rest_request')->will($this->returnValue($this->isRestRequest)); } return $this->requestAttributesMock; }
/** * Test the generation of multiple breadcrumbs */ public function testMultipleBreadcrumbs() { $label1 = 'foo'; $route1 = 'bar'; $label2 = 'baz'; $route2 = 'qux'; $this->requestAttributes->expects($this->any())->method('get')->will($this->returnValue(array(array('label' => $label1, 'route' => $route1), array('label' => $label2, 'route' => $route2)))); $this->provider->onKernelRequest($this->responseEvent); $result = $this->provider->getBreadcrumbs(); $this->assertCount(2, $result->getAll()); $this->assertEquals($label1, $result->getAll()[0]->getLabel()); $this->assertEquals($route1, $result->getAll()[0]->getRoute()); $this->assertEquals($label2, $result->getAll()[1]->getLabel()); $this->assertEquals($route2, $result->getAll()[1]->getRoute()); }
/** * Tests that if access is granted, AccessSubscriber will not throw an exception. */ public function testAccessSubscriberDoesNotAlterRequestIfAccessManagerGrantsAccess() { $this->parameterBag->expects($this->once())->method('has')->with(RouteObjectInterface::ROUTE_OBJECT)->will($this->returnValue(TRUE)); $this->parameterBag->expects($this->once())->method('get')->with(RouteObjectInterface::ROUTE_OBJECT)->will($this->returnValue($this->route)); $this->accessManager->expects($this->once())->method('check')->with($this->equalTo($this->route))->will($this->returnValue(TRUE)); $subscriber = new AccessSubscriber($this->accessManager, $this->currentUser); // We're testing that no exception is thrown in this case. There is no // return. $subscriber->onKernelRequestAccessCheck($this->event); }
/** * Test FieldNameSearchListener::onVisitNode() with context * * @return void */ public function testOnVisitNodeWithContext() { $fieldMapping = ['route.id' => ['array' => '$array', 'array.0' => '$array.0', 'array.0.field' => '$array.0.$field', 'array.0.field.ref' => '$array.0.$field.$ref']]; $fieldValue = 'field-value'; $this->requestAttrs->expects($this->once())->method('get')->with('_route')->willReturn('route.id'); $node = new EqNode('$field.$ref', $fieldValue); $context = new \SplStack(); $context->push(new ElemMatchNode('$array', $node)); $builder = $this->getMockBuilder(Builder::class)->disableOriginalConstructor()->getMock(); $event = new VisitNodeEvent($node, $builder, $context); $listener = $this->createListener($fieldMapping); $listener->onVisitNode($event); $this->assertNotSame($node, $event->getNode()); $this->assertSame($builder, $event->getBuilder()); $this->assertEquals(new EqNode('field.ref', $fieldValue), $event->getNode()); }
/** * Test ExtReferenceSearchListener::onVisitNode() with context * * @return void */ public function testOnVisitNodeWithContext() { $extrefMapping = ['route.id' => ['array.0.field.$ref']]; $extrefUrl = 'extref.url'; $extrefValue = ExtReference::create('Ref', 'id'); $dbRefValue = \MongoDBRef::create($extrefValue->getRef(), $extrefValue->getId()); $this->requestAttrs->expects($this->once())->method('get')->with('_route')->willReturn('route.id'); $this->converter->expects($this->once())->method('getExtReference')->with($extrefUrl)->willReturn($extrefValue); $node = new EqNode('field.$ref', $extrefUrl); $context = new \SplStack(); $context->push(new ElemMatchNode('array', $node)); $builder = $this->getMockBuilder('Doctrine\\ODM\\MongoDB\\Query\\Builder')->disableOriginalConstructor()->getMock(); $event = new VisitNodeEvent($node, $builder, $context); $listener = $this->createListener($extrefMapping); $listener->onVisitNode($event); $this->assertNotSame($node, $event->getNode()); $this->assertSame($builder, $event->getBuilder()); $this->assertEquals(new EqNode('field.$ref', $dbRefValue), $event->getNode()); }