public function EntityUrlTest::testUrl 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::testUrl()
Tests the url() method.
@covers ::url
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php, line 291 - Contains \Drupal\Tests\Core\Entity\EntityUrlTest.
Class
- EntityUrlTest
- @coversDefaultClass \Drupal\Core\Entity\Entity @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testUrl() {
$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));
$invalid_entity = $this
->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(
array(),
'test_entity_type',
));
$this
->assertSame('', $invalid_entity
->url());
$no_link_entity = $this
->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(
array(
'id' => 'test_entity_id',
),
'test_entity_type',
));
$this
->assertSame('', $no_link_entity
->url('banana'));
$valid_entity = $this
->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(
array(
'id' => 'test_entity_id',
),
'test_entity_type',
));
$language = new Language(array(
'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->urlGenerator
->expects($this
->any())
->method('generateFromRoute')
->willReturnCallback(function ($route_name, $route_parameters, $options) use ($language) {
if ($route_name === 'entity.test_entity_type.canonical' && $route_parameters === array(
'test_entity_type' => 'test_entity_id',
) && array_keys($options) === [
'entity_type',
'entity',
'language',
] && $options['language'] == $language) {
return '/entity/test_entity_type/test_entity_id';
}
if ($route_name === 'entity.test_entity_type.canonical' && $route_parameters === array(
'test_entity_type' => 'test_entity_id',
) && array_keys($options) === [
'absolute',
'entity_type',
'entity',
'language',
] && $options['language'] == $language) {
return 'http://drupal/entity/test_entity_type/test_entity_id';
}
});
$this
->assertSame('/entity/test_entity_type/test_entity_id', $valid_entity
->url());
$this
->assertSame('http://drupal/entity/test_entity_type/test_entity_id', $valid_entity
->url('canonical', array(
'absolute' => TRUE,
)));
}