EntityLoadByUuidTest.php in Drupal 8
File
core/tests/Drupal/KernelTests/Core/Entity/EntityLoadByUuidTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
class EntityLoadByUuidTest extends KernelTestBase {
protected static $modules = [
'entity_test',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_test');
}
public function testLoadEntityByUuidAccessChecking() {
\Drupal::state()
->set('entity_test_query_access', TRUE);
$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();
$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());
}
}