function HalLinkManagerTest::providerTestGetTypeUri

Same name and namespace in other branches
  1. 8.9.x core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php \Drupal\Tests\hal\Kernel\HalLinkManagerTest::providerTestGetTypeUri()

File

core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php, line 78

Class

HalLinkManagerTest
@coversDefaultClass \Drupal\hal\LinkManager\LinkManager[[api-linebreak]] @group hal @group legacy

Namespace

Drupal\Tests\hal\Kernel

Code

public function providerTestGetTypeUri() {
  $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',
    ]),
  ];
  $base_test_case = [
    'link_domain' => NULL,
    'entity_type' => 'node',
    'bundle' => 'page',
  ];
  return [
    'site URL' => $base_test_case + [
      'context' => [],
      'link_domain' => NULL,
      'expected return' => 'BASE_URL/rest/type/node/page',
      'expected context' => [],
    ],
    'site URL, with optional context to collect cacheability metadata' => $base_test_case + [
      'context' => $serialization_context_collecting_cacheability,
      'expected return' => 'BASE_URL/rest/type/node/page',
      'expected context' => $expected_serialization_context_cacheability_url_site,
    ],
    // Test hook_hal_type_uri_alter().
'site URL, with optional context, to test hook_hal_type_uri_alter()' => $base_test_case + [
      'context' => [
        'hal_test' => TRUE,
      ],
      'expected return' => 'hal_test_type',
      'expected context' => [
        'hal_test' => TRUE,
      ],
    ],
    'site URL, with optional context, to test hook_hal_type_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
      'context' => [
        'hal_test' => TRUE,
      ] + $serialization_context_collecting_cacheability,
      'expected return' => 'hal_test_type',
      // No cacheability metadata bubbled.
'expected context' => [
        'hal_test' => TRUE,
      ] + $serialization_context_collecting_cacheability,
    ],
    'configured URL' => [
      'link_domain' => 'http://llamas-rock.com/for-real/',
      'entity_type' => 'node',
      'bundle' => 'page',
      'context' => [],
      'expected return' => 'http://llamas-rock.com/for-real/rest/type/node/page',
      'expected context' => [],
    ],
    'configured URL, with optional context to collect cacheability metadata' => [
      'link_domain' => 'http://llamas-rock.com/for-real/',
      'entity_type' => 'node',
      'bundle' => 'page',
      'context' => $serialization_context_collecting_cacheability,
      'expected return' => 'http://llamas-rock.com/for-real/rest/type/node/page',
      'expected context' => [
        CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheTags([
          'config:hal.settings',
        ]),
      ],
    ],
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.