function EntityLoadByUuidTest::testLoadEntityByUuidAccessChecking

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php \Drupal\KernelTests\Core\Entity\EntityLoadByUuidTest::testLoadEntityByUuidAccessChecking()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php \Drupal\KernelTests\Core\Entity\EntityLoadByUuidTest::testLoadEntityByUuidAccessChecking()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php \Drupal\KernelTests\Core\Entity\EntityLoadByUuidTest::testLoadEntityByUuidAccessChecking()

Ensures that ::loadEntityByUuid() doesn't apply access checking.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php, line 35

Class

EntityLoadByUuidTest
Tests loading entities by UUID.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testLoadEntityByUuidAccessChecking() : void {
    \Drupal::state()->set('entity_test_query_access', TRUE);
    // Create two test entities.
    $entity_0 = EntityTest::create([
        'type' => 'entity_test',
        'name' => 'published entity',
    ]);
    $entity_0->save();
    $entity_1 = EntityTest::create([
        'type' => 'entity_test',
        'name' => 'unpublished entity',
    ]);
    $entity_1->save();
    
    /** @var \Drupal\Core\Entity\EntityRepositoryInterface $repository */
    $repository = \Drupal::service('entity.repository');
    $this->assertEquals($entity_0->id(), $repository->loadEntityByUuid('entity_test', $entity_0->uuid())
        ->id());
    $this->assertEquals($entity_1->id(), $repository->loadEntityByUuid('entity_test', $entity_1->uuid())
        ->id());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.