function HalLinkManagerTest::testHalLinkManagersSetLinkDomain
Same name in other branches
- 8.9.x core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php \Drupal\Tests\hal\Kernel\HalLinkManagerTest::testHalLinkManagersSetLinkDomain()
@covers ::setLinkDomain
File
-
core/
modules/ hal/ tests/ src/ Kernel/ HalLinkManagerTest.php, line 241
Class
- HalLinkManagerTest
- @coversDefaultClass \Drupal\hal\LinkManager\LinkManager @group hal @group legacy
Namespace
Drupal\Tests\hal\KernelCode
public function testHalLinkManagersSetLinkDomain() {
$serialization_context = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(),
];
/** @var \Drupal\hal\LinkManager\LinkManager $link_manager */
$link_manager = \Drupal::service('hal.link_manager');
/** @var \Drupal\hal\LinkManager\TypeLinkManager $type_link_manager */
$type_link_manager = \Drupal::service('hal.link_manager.type');
/** @var \Drupal\hal\LinkManager\RelationLinkManager $relation_link_manager */
$relation_link_manager = \Drupal::service('hal.link_manager.relation');
// One Drupal installation can serve multiple domains, protocols or ports.
foreach ([
'http://example.com/',
'https://example.com/',
'https://example.com:443/',
'http://drupal.org/',
] as $domain) {
$link_manager->setLinkDomain($domain);
$link = $link_manager->getTypeUri('node', 'page', $serialization_context);
$this->assertEquals($domain . 'rest/type/node/page', $link);
$this->assertEquals($serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY], new CacheableMetadata());
$type_ids = $type_link_manager->getTypeInternalIds($link, $serialization_context);
$this->assertEquals([
'entity_type' => 'node',
'bundle' => 'page',
], $type_ids);
$link = $link_manager->getRelationUri('node', 'page', 'field_ref', $serialization_context);
$this->assertEquals($domain . 'rest/relation/node/page/field_ref', $link);
$this->assertEquals($serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY], new CacheableMetadata());
$relation_ids = $relation_link_manager->getRelationInternalIds($link, $serialization_context);
$this->assertEquals([
'entity_type_id' => 'node',
'bundle' => 'page',
'field_name' => 'field_ref',
], $relation_ids);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.