3 namespace Drupal\KernelTests\Core\Http;
5 use Drupal\Core\Http\LinkRelationType;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests link relationships in Drupal.
13 class LinkRelationsTest extends KernelTestBase {
16 * Tests correct Link Relations are returned from the Link Relation Type Manager.
18 public function testAvailableLinkRelationships() {
19 /** @var \Drupal\Core\Http\LinkRelationTypeManager $link_relation_type_manager */
20 $link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type');
22 // An link relation type of the "registered" kind.
23 /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
24 $canonical = $link_relation_type_manager->createInstance('canonical');
25 $this->assertInstanceOf(LinkRelationType::class, $canonical);
26 $this->assertTrue($canonical->isRegistered());
27 $this->assertFalse($canonical->isExtension());
28 $this->assertSame('canonical', $canonical->getRegisteredName());
29 $this->assertNull($canonical->getExtensionUri());
30 $this->assertEquals('[RFC6596]', $canonical->getReference());
31 $this->assertEquals('Designates the preferred version of a resource (the IRI and its contents).', $canonical->getDescription());
32 $this->assertEquals('', $canonical->getNotes());
34 // An link relation type of the "extension" kind.
35 /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
36 $add_form = $link_relation_type_manager->createInstance('add-form');
37 $this->assertInstanceOf(LinkRelationType::class, $add_form);
38 $this->assertFalse($add_form->isRegistered());
39 $this->assertTrue($add_form->isExtension());
40 $this->assertNull($add_form->getRegisteredName());
41 $this->assertSame('https://drupal.org/link-relations/add-form', $add_form->getExtensionUri());
42 $this->assertEquals('', $add_form->getReference());
43 $this->assertEquals('A form where a resource of this type can be created.', $add_form->getDescription());
44 $this->assertEquals('', $add_form->getNotes());
46 // Test a couple of examples.
47 $this->assertContains('about', array_keys($link_relation_type_manager->getDefinitions()));
48 $this->assertContains('original', array_keys($link_relation_type_manager->getDefinitions()));
49 $this->assertContains('type', array_keys($link_relation_type_manager->getDefinitions()));