Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / rdf / tests / src / Kernel / Field / EntityReferenceRdfaTest.php
1 <?php
2
3 namespace Drupal\Tests\rdf\Kernel\Field;
4
5 use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
6 use Drupal\user\Entity\Role;
7 use Drupal\user\RoleInterface;
8
9 /**
10  * Tests the RDFa output of the entity reference field formatter.
11  *
12  * @group rdf
13  */
14 class EntityReferenceRdfaTest extends FieldRdfaTestBase {
15
16   use EntityReferenceTestTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   protected $fieldType = 'entity_reference';
22
23   /**
24    * The entity type used in this test.
25    *
26    * @var string
27    */
28   protected $entityType = 'entity_test';
29
30   /**
31    * The bundle used in this test.
32    *
33    * @var string
34    */
35   protected $bundle = 'entity_test';
36
37   /**
38    * The term for testing.
39    *
40    * @var \Drupal\taxonomy\Entity\Term
41    */
42   protected $targetEntity;
43
44   /**
45    * {@inheritdoc}
46    */
47   public static $modules = ['text', 'filter'];
48
49   protected function setUp() {
50     parent::setUp();
51
52     $this->installEntitySchema('entity_test_rev');
53
54     // Give anonymous users permission to view test entities.
55     $this->installConfig(['user']);
56     Role::load(RoleInterface::ANONYMOUS_ID)
57       ->grantPermission('view test entity')
58       ->save();
59
60     $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);
61
62     // Add the mapping.
63     $mapping = rdf_get_mapping('entity_test', 'entity_test');
64     $mapping->setFieldMapping($this->fieldName, [
65       'properties' => ['schema:knows'],
66     ])->save();
67
68     // Create the entity to be referenced.
69     $this->targetEntity = $this->container->get('entity_type.manager')
70       ->getStorage($this->entityType)
71       ->create(['name' => $this->randomMachineName()]);
72     $this->targetEntity->save();
73
74     // Create the entity that will have the entity reference field.
75     $this->entity = $this->container->get('entity_type.manager')
76       ->getStorage($this->entityType)
77       ->create(['name' => $this->randomMachineName()]);
78     $this->entity->save();
79     $this->entity->{$this->fieldName}->entity = $this->targetEntity;
80     $this->uri = $this->getAbsoluteUri($this->entity);
81   }
82
83   /**
84    * Tests all the entity reference formatters.
85    */
86   public function testAllFormatters() {
87     $entity_uri = $this->getAbsoluteUri($this->targetEntity);
88
89     // Tests the label formatter.
90     $this->assertFormatterRdfa(['type' => 'entity_reference_label'], 'http://schema.org/knows', ['value' => $entity_uri, 'type' => 'uri']);
91     // Tests the entity formatter.
92     $this->assertFormatterRdfa(['type' => 'entity_reference_entity_view'], 'http://schema.org/knows', ['value' => $entity_uri, 'type' => 'uri']);
93   }
94
95 }