public function EntityUrlTest::testToUrl in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrl()
 
Tests the toUrl() method.
@covers ::toUrl
@dataProvider providerTestToUrl
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php, line 90  - Contains \Drupal\Tests\Core\Entity\EntityUrlTest.
 
Class
- EntityUrlTest
 - @coversDefaultClass \Drupal\Core\Entity\Entity @group Entity
 
Namespace
Drupal\Tests\Core\EntityCode
public function testToUrl($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
    ->getTestToUrl($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());
    }
  }
}