public function RestLinkManagerTest::testRestLinkManagers in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/rest/src/Tests/RestLinkManagerTest.php \Drupal\rest\Tests\RestLinkManagerTest::testRestLinkManagers()
Tests that type hooks work as expected.
File
- core/
modules/ rest/ src/ Tests/ RestLinkManagerTest.php, line 35 - Contains \Drupal\rest\Tests\RestLinkManagerTest.
Class
- RestLinkManagerTest
- Tests that REST type and relation link managers work as expected @group rest
Namespace
Drupal\rest\TestsCode
public function testRestLinkManagers() {
\Drupal::moduleHandler()
->invoke('rest', 'install');
/* @var \Drupal\rest\LinkManager\TypeLinkManagerInterface $type_manager */
$type_manager = \Drupal::service('rest.link_manager.type');
$base = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString();
$link = $type_manager
->getTypeUri('node', 'page');
$this
->assertEqual($link, $base . 'rest/type/node/page');
// Now with optional context.
$link = $type_manager
->getTypeUri('node', 'page', [
'rest_test' => TRUE,
]);
$this
->assertEqual($link, 'rest_test_type');
/* @var \Drupal\rest\LinkManager\RelationLinkManagerInterface $relation_manager */
$relation_manager = \Drupal::service('rest.link_manager.relation');
$link = $relation_manager
->getRelationUri('node', 'page', 'field_ref');
$this
->assertEqual($link, $base . 'rest/relation/node/page/field_ref');
// Now with optional context.
$link = $relation_manager
->getRelationUri('node', 'page', 'foobar', [
'rest_test' => TRUE,
]);
$this
->assertEqual($link, 'rest_test_relation');
}