Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / tests / src / Kernel / QueryAccess / QueryAccessEventTest.php
1 <?php
2
3 namespace Drupal\Tests\entity\Kernel\QueryAccess;
4
5 use Drupal\entity\QueryAccess\QueryAccessHandler;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
7
8 /**
9  * Tests the query access event.
10  *
11  * @group entity
12  */
13 class QueryAccessEventTest extends EntityKernelTestBase {
14
15   /**
16    * The query access handler.
17    *
18    * @var \Drupal\entity\QueryAccess\QueryAccessHandler
19    */
20   protected $handler;
21
22   /**
23    * {@inheritdoc}
24    */
25   public static $modules = [
26     'entity',
27     'entity_module_test',
28   ];
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp() {
34     parent::setUp();
35
36     $this->installEntitySchema('entity_test_enhanced');
37
38     // Create uid: 1 here so that it's skipped in test cases.
39     $admin_user = $this->createUser();
40
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);
44   }
45
46   /**
47    * Tests the event.
48    */
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']);
54
55     $conditions = $this->handler->getConditions('view', $first_user);
56     $this->assertTrue($conditions->isAlwaysFalse());
57
58     $conditions = $this->handler->getConditions('view', $second_user);
59     $this->assertFalse($conditions->isAlwaysFalse());
60   }
61
62 }