public function HalLinkManagerTest::providerTestGetRelationUri in Drupal 8
Same name and namespace in other branches
- 9 core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php \Drupal\Tests\hal\Kernel\HalLinkManagerTest::providerTestGetRelationUri()
File
- core/
modules/ hal/ tests/ src/ Kernel/ HalLinkManagerTest.php, line 175
Class
- HalLinkManagerTest
- @coversDefaultClass \Drupal\hal\LinkManager\LinkManager @group hal @group legacy
Namespace
Drupal\Tests\hal\KernelCode
public function providerTestGetRelationUri() {
$serialization_context_collecting_cacheability = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata(),
];
$expected_serialization_context_cacheability_url_site = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())
->setCacheContexts([
'url.site',
]),
];
$field_name = $this
->randomMachineName();
$base_test_case = [
'link_domain' => NULL,
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => $field_name,
];
return [
'site URL' => $base_test_case + [
'context' => [],
'link_domain' => NULL,
'expected return' => 'BASE_URL/rest/relation/node/page/' . $field_name,
'expected context' => [],
],
'site URL, with optional context to collect cacheability metadata' => $base_test_case + [
'context' => $serialization_context_collecting_cacheability,
'expected return' => 'BASE_URL/rest/relation/node/page/' . $field_name,
'expected context' => $expected_serialization_context_cacheability_url_site,
],
// Test hook_hal_relation_uri_alter().
'site URL, with optional context, to test hook_hal_relation_uri_alter()' => $base_test_case + [
'context' => [
'hal_test' => TRUE,
],
'expected return' => 'hal_test_relation',
'expected context' => [
'hal_test' => TRUE,
],
],
'site URL, with optional context, to test hook_hal_relation_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
'context' => [
'hal_test' => TRUE,
] + $serialization_context_collecting_cacheability,
'expected return' => 'hal_test_relation',
// No cacheability metadata bubbled.
'expected context' => [
'hal_test' => TRUE,
] + $serialization_context_collecting_cacheability,
],
// Test hook_rest_relation_uri_alter() — for backwards compatibility.
'site URL, with optional context, to test hook_rest_relation_uri_alter()' => $base_test_case + [
'context' => [
'rest_test' => TRUE,
],
'expected return' => 'rest_test_relation',
'expected context' => [
'rest_test' => TRUE,
],
],
'site URL, with optional context, to test hook_rest_relation_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
'context' => [
'rest_test' => TRUE,
] + $serialization_context_collecting_cacheability,
'expected return' => 'rest_test_relation',
// No cacheability metadata bubbled.
'expected context' => [
'rest_test' => TRUE,
] + $serialization_context_collecting_cacheability,
],
'configured URL' => [
'link_domain' => 'http://llamas-rock.com/for-real/',
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => $field_name,
'context' => [],
'expected return' => 'http://llamas-rock.com/for-real/rest/relation/node/page/' . $field_name,
'expected context' => [],
],
'configured URL, with optional context to collect cacheability metadata' => [
'link_domain' => 'http://llamas-rock.com/for-real/',
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => $field_name,
'context' => $serialization_context_collecting_cacheability,
'expected return' => 'http://llamas-rock.com/for-real/rest/relation/node/page/' . $field_name,
'expected context' => [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())
->setCacheTags([
'config:hal.settings',
]),
],
],
];
}