/**
  * Tests the breadcrumb for a user path.
  *
  * @covers ::build()
  * @covers ::getRequestForPath()
  */
 public function testBuildWithUserPath()
 {
     $this->context->expects($this->once())->method('getPathInfo')->will($this->returnValue('/user/1/edit'));
     $this->setupStubPathProcessor();
     $route_1 = new Route('/user/1');
     $this->requestMatcher->expects($this->exactly(1))->method('matchRequest')->will($this->returnCallback(function (Request $request) use($route_1) {
         if ($request->getPathInfo() == '/user/1') {
             return array(RouteObjectInterface::ROUTE_NAME => 'user_page', RouteObjectInterface::ROUTE_OBJECT => $route_1, '_raw_variables' => new ParameterBag(array()));
         }
     }));
     $this->setupAccessManagerToAllow();
     $this->titleResolver->expects($this->once())->method('getTitle')->with($this->anything(), $route_1)->will($this->returnValue('Admin'));
     $links = $this->builder->build($this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
     $this->assertEquals(array(0 => new Link('Home', new Url('<front>')), 1 => new Link('Admin', new Url('user_page'))), $links);
 }
コード例 #2
0
 /**
  * Tests the breadcrumb for a user path.
  *
  * @covers ::build()
  * @covers ::getRequestForPath()
  */
 public function testBuildWithUserPath()
 {
     $this->context->expects($this->once())->method('getPathInfo')->will($this->returnValue('/user/1/edit'));
     $this->setupStubPathProcessor();
     $route_1 = new Route('/user/1');
     $this->requestMatcher->expects($this->exactly(1))->method('matchRequest')->will($this->returnCallback(function (Request $request) use($route_1) {
         if ($request->getPathInfo() == '/user/1') {
             return array(RouteObjectInterface::ROUTE_NAME => 'user_page', RouteObjectInterface::ROUTE_OBJECT => $route_1, '_raw_variables' => new ParameterBag(array()));
         }
     }));
     $link_user = '******';
     $link_front = '<a href="/">Home</a>';
     $this->linkGenerator->expects($this->at(0))->method('generate')->with('Admin', 'user_page', array(), array('html' => TRUE))->will($this->returnValue($link_user));
     $this->linkGenerator->expects($this->at(1))->method('generate')->with('Home', '<front>', array(), array())->will($this->returnValue($link_front));
     $this->setupAccessManagerWithTrue();
     $this->titleResolver->expects($this->once())->method('getTitle')->with($this->anything(), $route_1)->will($this->returnValue('Admin'));
     $links = $this->builder->build($this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
     $this->assertEquals(array(0 => '<a href="/">Home</a>', 1 => $link_user), $links);
 }
コード例 #3
0
 /**
  * @param string $method
  * @dataProvider getLinkMethods
  */
 public function testProducedLinks($method)
 {
     $listener = $this->getListener();
     $event = $this->getEvent();
     $urlParams = ['foo' => 'bar'];
     $this->urlMatcher->expects($this->exactly(3))->method('match')->willReturn($urlParams);
     $event->getRequest()->setMethod($method);
     $event->getRequest()->headers->set('Link', 'link1,link2, link3');
     $this->context->method('getMethod')->willReturn('METHOD');
     $this->context->expects($this->exactly(2))->method('setMethod')->withConsecutive(['GET'], ['METHOD']);
     $listener->onKernelRequest($event);
     $this->assertTrue($event->getRequest()->attributes->has('links'));
     /** @var LinkHeader[] $links */
     $links = $event->getRequest()->attributes->get('links');
     $this->assertEquals(3, count($links));
     $this->assertEquals('link1', $links[0]->getOriginalHeader());
     $this->assertEquals($urlParams, $links[0]->getUrlParameters());
     $this->assertEquals('link2', $links[1]->getOriginalHeader());
     $this->assertEquals('link3', $links[2]->getOriginalHeader());
 }