94f7f24dac13d1932031f0d1c3b2b5bc30cdbe39
[yaffs-website] / web / core / modules / rdf / tests / src / Kernel / Field / FieldRdfaDatatypeCallbackTest.php
1 <?php
2
3 namespace Drupal\Tests\rdf\Kernel\Field;
4
5 use Drupal\entity_test\Entity\EntityTest;
6
7 /**
8  * Tests the RDFa output of a text field formatter with a datatype callback.
9  *
10  * @group rdf
11  */
12 class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected $fieldType = 'text';
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['text', 'filter'];
23
24   protected function setUp() {
25     parent::setUp();
26
27     $this->createTestField();
28
29     $this->installConfig(['filter']);
30
31     // Add the mapping.
32     $mapping = rdf_get_mapping('entity_test', 'entity_test');
33     $mapping->setFieldMapping($this->fieldName, [
34       'properties' => ['schema:interactionCount'],
35       'datatype_callback' => [
36         'callable' => 'Drupal\rdf\Tests\Field\TestDataConverter::convertFoo',
37       ],
38     ])->save();
39
40     // Set up test values.
41     $this->testValue = $this->randomMachineName();
42     $this->entity = EntityTest::create();
43     $this->entity->{$this->fieldName}->value = $this->testValue;
44     $this->entity->save();
45
46     $this->uri = $this->getAbsoluteUri($this->entity);
47   }
48
49   /**
50    * Tests the default formatter.
51    */
52   public function testDefaultFormatter() {
53     // Expected value is the output of the datatype callback, not the raw value.
54     $this->assertFormatterRdfa(['type' => 'text_default'], 'http://schema.org/interactionCount', ['value' => 'foo' . $this->testValue]);
55   }
56
57 }