/**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->requestContext = $this->getMockBuilder('Drupal\\Core\\Routing\\RequestContext')->disableOriginalConstructor()->getMock();
     $this->requestContext->expects($this->any())->method('getCompleteBaseUrl')->willReturn('http://example.com/drupal');
     $this->urlAssembler = $this->getMock(UnroutedUrlAssemblerInterface::class);
     $this->urlAssembler->expects($this->any())->method('assemble')->willReturnMap([['base:test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/test'], ['base:example.com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example.com'], ['base:example:com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example:com'], ['base:javascript:alert(0)', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/javascript:alert(0)']]);
     $container = new Container();
     $container->set('router.request_context', $this->requestContext);
     \Drupal::setContainer($container);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->urlAssembler = $this->getMock('Drupal\\Core\\Utility\\UnroutedUrlAssemblerInterface');
     $this->urlAssembler->expects($this->any())->method('assemble')->will($this->returnArgument(0));
     $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
     $container = new ContainerBuilder();
     $container->set('router.no_access_checks', $this->router);
     $container->set('unrouted_url_assembler', $this->urlAssembler);
     \Drupal::setContainer($container);
 }
예제 #3
0
 /**
  * Tests the generate() method with an external URL.
  *
  * The set_active_class option is set to TRUE to ensure this does not cause
  * an error together with an external URL.
  *
  * @covers ::generate
  */
 public function testGenerateExternal()
 {
     $this->urlAssembler->expects($this->once())->method('assemble')->with('http://drupal.org', array('set_active_class' => TRUE, 'external' => TRUE) + $this->defaultOptions)->will($this->returnArgument(0));
     $this->moduleHandler->expects($this->once())->method('alter')->with('link', $this->isType('array'));
     $this->urlAssembler->expects($this->once())->method('assemble')->with('http://drupal.org', array('set_active_class' => TRUE, 'external' => TRUE) + $this->defaultOptions)->willReturnArgument(0);
     $url = Url::fromUri('http://drupal.org');
     $url->setUrlGenerator($this->urlGenerator);
     $url->setUnroutedUrlAssembler($this->urlAssembler);
     $url->setOption('set_active_class', TRUE);
     $result = $this->linkGenerator->generate('Drupal', $url);
     $this->assertLink(array('attributes' => array('href' => 'http://drupal.org'), 'content' => 'Drupal'), $result);
 }
예제 #4
0
 /**
  * Tests the generate() method with a url containing double quotes.
  *
  * @covers ::generate
  */
 public function testGenerateUrlWithQuotes()
 {
     $this->urlAssembler->expects($this->once())->method('assemble')->with('base:example', array('query' => array('foo' => '"bar"', 'zoo' => 'baz')) + $this->defaultOptions)->willReturn((new GeneratedUrl())->setGeneratedUrl('/example?foo=%22bar%22&zoo=baz'));
     $path_validator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface');
     $container_builder = new ContainerBuilder();
     $container_builder->set('path.validator', $path_validator);
     \Drupal::setContainer($container_builder);
     $path = '/example?foo="bar"&zoo=baz';
     $url = Url::fromUserInput($path);
     $url->setUrlGenerator($this->urlGenerator);
     $url->setUnroutedUrlAssembler($this->urlAssembler);
     $result = $this->linkGenerator->generate('Drupal', $url);
     $this->assertLink(array('attributes' => array('href' => '/example?foo=%22bar%22&zoo=baz'), 'content' => 'Drupal'), $result, 1);
 }
예제 #5
0
 /**
  * Tests the redirectForm() method when no redirect is expected.
  *
  * @covers ::redirectForm
  */
 public function testRedirectWithoutResult()
 {
     $form_submitter = $this->getFormSubmitter();
     $this->urlGenerator->expects($this->never())->method('generateFromRoute');
     $this->unroutedUrlAssembler->expects($this->never())->method('assemble');
     $container = new ContainerBuilder();
     $container->set('url_generator', $this->urlGenerator);
     $container->set('unrouted_url_assembler', $this->unroutedUrlAssembler);
     \Drupal::setContainer($container);
     $form_state = $this->getMock('Drupal\\Core\\Form\\FormStateInterface');
     $form_state->expects($this->once())->method('getRedirect')->willReturn(FALSE);
     $redirect = $form_submitter->redirectForm($form_state);
     $this->assertNull($redirect);
 }