function EntityUrlTest::testToUrlLinkTemplateAddForm

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateAddForm()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateAddForm()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateAddForm()

Tests the toUrl() method with the 'revision' link template.

@dataProvider providerTestToUrlLinkTemplateAddForm

@covers ::toUrl @covers ::linkTemplates @covers ::urlRouteParameters

Parameters

bool $has_bundle_key: Whether or not the mock entity type should have a bundle key.

string|null $bundle_entity_type: The ID of the bundle entity type of the mock entity type, or NULL if the mock entity type should not have a bundle entity type.

string $bundle_key: The bundle key of the mock entity type or FALSE if the entity type should not have a bundle key.

array $expected_route_parameters: The expected route parameters of the generated URL.

File

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

Class

EntityUrlTest
Tests URL handling of the <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Entity.php/class/Entity/8.9.x" title="Defines a base entity class." class="local">\Drupal\Core\Entity\Entity</a> class.

Namespace

Drupal\Tests\Core\Entity

Code

public function testToUrlLinkTemplateAddForm($has_bundle_key, $bundle_entity_type, $bundle_key, $expected_route_parameters) {
    $values = [
        'id' => $this->entityId,
        'langcode' => $this->langcode,
    ];
    $entity = $this->getEntity(EntityBase::class, $values);
    $this->entityType
        ->hasKey('bundle')
        ->willReturn($has_bundle_key);
    $this->entityType
        ->getBundleEntityType()
        ->willReturn($bundle_entity_type);
    $this->entityType
        ->getKey('bundle')
        ->willReturn($bundle_key);
    $link_template = 'add-form';
    $this->registerLinkTemplate($link_template);
    
    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl($link_template);
    $this->assertUrl('entity.test_entity.add_form', $expected_route_parameters, $entity, FALSE, $url);
}

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