function EntityUrlTest::testToUrlDefaultException

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlDefaultException()

Tests the toUrl() method without specifying the $rel parameter.

It should throw an exception when neither canonical and edit-form link templates exist if no parameters are passed in.

@covers ::toUrl

File

core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php, line 113

Class

EntityUrlTest
Tests URL handling of the \Drupal\Core\Entity\EntityBase class.

Namespace

Drupal\Tests\Core\Entity

Code

public function testToUrlDefaultException() : void {
    $values = [
        'id' => static::ENTITY_ID,
    ];
    $entity = $this->getEntity(StubEntityBase::class, $values);
    $this->entityType
        ->getUriCallback()
        ->willReturn(NULL);
    $this->expectException(UndefinedLinkTemplateException::class);
    $this->expectExceptionMessage("Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the '" . static::ENTITY_TYPE_ID . "' entity type");
    $entity->toUrl();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.