Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / field / tests / src / Kernel / String / UuidFormatterTest.php
1 <?php
2
3 namespace Drupal\Tests\field\Kernel\String;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests the output of a UUID field.
10  *
11  * @group field
12  */
13 class UuidFormatterTest extends KernelTestBase {
14
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['field', 'entity_test', 'system', 'user'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28
29     $this->installConfig(['system', 'field']);
30     \Drupal::service('router.builder')->rebuild();
31     $this->installEntitySchema('entity_test');
32   }
33
34   /**
35    * Tests string formatter output.
36    */
37   public function testUuidStringFormatter() {
38     $entity = EntityTest::create([]);
39     $entity->save();
40
41     $uuid_field = $entity->get('uuid');
42
43     // Verify default render.
44     $render_array = $uuid_field->view([]);
45     $this->assertIdentical($render_array[0]['#context']['value'], $entity->uuid(), 'The rendered UUID matches the entity UUID.');
46     $this->assertTrue(strpos($this->render($render_array), $entity->uuid()), 'The rendered UUID found.');
47
48     // Verify customized render.
49     $render_array = $uuid_field->view(['settings' => ['link_to_entity' => TRUE]]);
50     $this->assertIdentical($render_array[0]['#type'], 'link');
51     $this->assertIdentical($render_array[0]['#title']['#context']['value'], $entity->uuid());
52     $this->assertIdentical($render_array[0]['#url']->toString(), $entity->url());
53     $rendered = $this->render($render_array);
54     $this->assertTrue(strpos($rendered, $entity->uuid()), 'The rendered UUID found.');
55     $this->assertTrue(strpos($rendered, $entity->url()), 'The rendered entity URL found.');
56   }
57
58 }