You are here

public function EntityUrlTest::testUrlInfo in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testUrlInfo()

Tests the urlInfo() method.

Note that urlInfo() is a deprecated alias for toUrl(). See testToUrl().

@covers ::urlInfo

@dataProvider providerTestToUrl

File

core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php, line 62
Contains \Drupal\Tests\Core\Entity\EntityUrlTest.

Class

EntityUrlTest
@coversDefaultClass \Drupal\Core\Entity\Entity @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testUrlInfo($entity_class, $link_template, $expected, $langcode = NULL) {

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this
    ->getMockForAbstractClass($entity_class, array(
    array(
      'id' => 'test_entity_id',
    ),
    'test_entity_type',
  ));
  $uri = $this
    ->getTestUrlInfo($entity, $link_template, [], $langcode);
  $this
    ->assertSame($expected, $uri
    ->getRouteName());
  $this
    ->assertSame($entity, $uri
    ->getOption('entity'));
  if ($langcode) {
    $this
      ->assertEquals($langcode, $uri
      ->getOption('language')
      ->getId());
  }
  else {
    if ($entity instanceof ConfigEntityInterface) {

      // Config entities do not provide a language with their URIs.
      $this
        ->assertEquals(NULL, $uri
        ->getOption('language'));
    }
    else {
      $this
        ->assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED, $uri
        ->getOption('language')
        ->getId());
    }
  }
}