function LinkFormatterTest::testFormatterLinkItemUrlUnexpectedException
Same name and namespace in other branches
- 11.x core/modules/link/tests/src/Unit/LinkFormatterTest.php \Drupal\Tests\link\Unit\LinkFormatterTest::testFormatterLinkItemUrlUnexpectedException()
- 10 core/modules/link/tests/src/Unit/LinkFormatterTest.php \Drupal\Tests\link\Unit\LinkFormatterTest::testFormatterLinkItemUrlUnexpectedException()
- 9 core/modules/link/tests/src/Unit/LinkFormatterTest.php \Drupal\Tests\link\Unit\LinkFormatterTest::testFormatterLinkItemUrlUnexpectedException()
Tests when LinkItem::getUrl throws an unexpected exception.
File
-
core/
modules/ link/ tests/ src/ Unit/ LinkFormatterTest.php, line 62
Class
- LinkFormatterTest
- Tests the Field Formatter for the link field type.
Namespace
Drupal\Tests\link\UnitCode
public function testFormatterLinkItemUrlUnexpectedException() : void {
$linkItem = $this->createMock(LinkItemInterface::class);
$linkItem->expects($this->once())
->method('getUrl')
->willThrowException(new \Exception('Unexpected!!!'));
$fieldDefinition = $this->createStub(FieldDefinitionInterface::class);
$fieldList = new FieldItemList($fieldDefinition, '', $linkItem);
$fieldTypePluginManager = $this->createMock(FieldTypePluginManagerInterface::class);
$fieldTypePluginManager->expects($this->once())
->method('createFieldItem')
->willReturn($linkItem);
$container = new ContainerBuilder();
$container->set('plugin.manager.field.field_type', $fieldTypePluginManager);
\Drupal::setContainer($container);
$fieldList->setValue([
$linkItem,
]);
$pathValidator = $this->createStub(PathValidatorInterface::class);
$linkFormatter = new LinkFormatter('', [], $fieldDefinition, [], '', '', [], $pathValidator);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Unexpected!!!');
$linkFormatter->viewElements($fieldList, 'fr');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.