3 namespace Drupal\Tests\entity\Kernel\QueryAccess;
5 use Drupal\entity\QueryAccess\QueryAccessHandler;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
9 * Tests the query access event.
13 class QueryAccessEventTest extends EntityKernelTestBase {
16 * The query access handler.
18 * @var \Drupal\entity\QueryAccess\QueryAccessHandler
25 public static $modules = [
33 protected function setUp() {
36 $this->installEntitySchema('entity_test_enhanced');
38 // Create uid: 1 here so that it's skipped in test cases.
39 $admin_user = $this->createUser();
41 $entity_type_manager = $this->container->get('entity_type.manager');
42 $entity_type = $entity_type_manager->getDefinition('entity_test_enhanced');
43 $this->handler = QueryAccessHandler::createInstance($this->container, $entity_type);
49 public function testEvent() {
50 // By default, the first user should have full access, and the second
51 // user should have no access. The QueryAccessSubscriber flips that.
52 $first_user = $this->createUser(['mail' => 'user1@example.com'], ['administer entity_test_enhanced']);
53 $second_user = $this->createUser(['mail' => 'user2@example.com']);
55 $conditions = $this->handler->getConditions('view', $first_user);
56 $this->assertTrue($conditions->isAlwaysFalse());
58 $conditions = $this->handler->getConditions('view', $second_user);
59 $this->assertFalse($conditions->isAlwaysFalse());