LinkRelationsTest.php 2.3 KB

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