LinkFormatter example

$urlGenerator->expects($this->once())
      ->method('generateFromRoute')
      ->with('<none>', [][], FALSE)
      ->willReturn('http://example.com');
    $container = new ContainerBuilder();
    $container->set('plugin.manager.field.field_type', $fieldTypePluginManager);
    $container->set('url_generator', $urlGenerator);
    \Drupal::setContainer($container);
    $fieldList->setValue([$linkItem]);

    $pathValidator = $this->createMock(PathValidatorInterface::class);
    $linkFormatter = new LinkFormatter('', []$fieldDefinition[], '', '', []$pathValidator);
    $elements = $linkFormatter->viewElements($fieldList, 'es');
    $this->assertEquals('link', $elements[0]['#type']);
  }

  /** * Tests when LinkItem::getUrl throws an unexpected exception. */
  public function testFormatterLinkItemUrlUnexpectedException() {
    $exception = new \Exception('Unexpected!!!');

    $linkItem = $this->createMock(LinkItemInterface::class);
    
Home | Imprint | This part of the site doesn't use cookies.