function EntityUrlTest::testToUrlLinkTemplateAddForm

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateAddForm()
  2. 8.9.x 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|false $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 311

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testToUrlLinkTemplateAddForm(bool $has_bundle_key, ?string $bundle_entity_type, string|false $bundle_key, array $expected_route_parameters) : void {
    $values = [
        'id' => static::ENTITY_ID,
        'langcode' => $this->langcode,
    ];
    $entity = $this->getEntity(UrlTestEntity::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.