You are here

public function EntityUrlTest::testLinkTemplates 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::testLinkTemplates()

Tests the retrieval of link templates.

@covers ::hasLinkTemplate @covers ::linkTemplates

@dataProvider providerTestLinkTemplates

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testLinkTemplates($override_templates, $expected) {
  $entity_type = $this
    ->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
  $entity_type
    ->expects($this
    ->any())
    ->method('getLinkTemplates')
    ->will($this
    ->returnValue(array(
    'canonical' => 'test_entity_type.view',
  )));
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with('test_entity_type')
    ->will($this
    ->returnValue($entity_type));
  $entity = $this
    ->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(
    array(
      'id' => 'test_entity_id',
    ),
    'test_entity_type',
  ), '', TRUE, TRUE, TRUE, array(
    'linkTemplates',
  ));
  $entity
    ->expects($this
    ->any())
    ->method('linkTemplates')
    ->will($this
    ->returnCallback(function () use ($entity_type, $override_templates) {
    $templates = $entity_type
      ->getLinkTemplates();
    if ($override_templates) {
      $templates['bananas'] = 'test_entity_type.bananas';
    }
    return $templates;
  }));
  $this
    ->assertSame($expected['canonical'], $entity
    ->hasLinkTemplate('canonical'));
  $this
    ->assertSame($expected['bananas'], $entity
    ->hasLinkTemplate('bananas'));
}