4974a74cb7535a205a23a4064123505b13ab1c64
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Entity / EntityLoadByUuidTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Entity;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests loading entities by UUID.
10  *
11  * @group entity
12  */
13 class EntityLoadByUuidTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected static $modules = ['entity_test', 'user'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25
26     $this->installEntitySchema('user');
27     $this->installEntitySchema('entity_test');
28   }
29
30   /**
31    * Ensures that ::loadEntityByUuid() doesn't apply access checking.
32    */
33   public function testLoadEntityByUuidAccessChecking() {
34     \Drupal::state()->set('entity_test_query_access', TRUE);
35     // Create two test entities.
36     $entity_0 = EntityTest::create([
37       'type' => 'entity_test',
38       'name' => 'published entity'
39     ]);
40     $entity_0->save();
41     $entity_1 = EntityTest::create([
42       'type' => 'entity_test',
43       'name' => 'unpublished entity'
44     ]);
45     $entity_1->save();
46
47     /** @var \Drupal\Core\Entity\EntityRepositoryInterface $repository */
48     $repository = \Drupal::service('entity.repository');
49     $this->assertEquals($entity_0->id(), $repository->loadEntityByUuid('entity_test', $entity_0->uuid())->id());
50     $this->assertEquals($entity_1->id(), $repository->loadEntityByUuid('entity_test', $entity_1->uuid())->id());
51   }
52
53 }