Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / tests / src / Functional / CollectionRouteAccessTest.php
1 <?php
2
3 namespace Drupal\Tests\entity\Functional;
4
5 use Drupal\entity_module_test\Entity\EnhancedEntity;
6 use Drupal\Tests\block\Traits\BlockCreationTrait;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests the collection route access check.
11  *
12  * @group entity
13  *
14  * @runTestsInSeparateProcesses
15  *
16  * @preserveGlobalState disabled
17  */
18 class CollectionRouteAccessTest extends BrowserTestBase {
19
20   use BlockCreationTrait;
21
22   /**
23    * Modules to enable.
24    *
25    * @var array
26    */
27   public static $modules = ['entity_module_test', 'user', 'entity', 'block'];
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp() {
33     parent::setUp();
34
35     $this->placeBlock('local_tasks_block');
36     $this->placeBlock('system_breadcrumb_block');
37   }
38
39   /**
40    * Test the collection route access.
41    */
42   public function testCollectionRouteAccess() {
43     $entity = EnhancedEntity::create([
44       'name' => 'rev 1',
45       'type' => 'default',
46     ]);
47     $entity->save();
48
49     // User without any relevant permissions.
50     $account = $this->drupalCreateUser(['access administration pages']);
51     $this->drupalLogin($account);
52
53     $this->drupalGet($entity->toUrl('collection'));
54     $this->assertSession()->statusCodeEquals(403);
55
56     // User with "access overview" permissions.
57     $account = $this->drupalCreateUser(['access entity_test_enhanced overview']);
58     $this->drupalLogin($account);
59
60     $this->drupalGet($entity->toUrl('collection'));
61     $this->assertSession()->statusCodeEquals(200);
62
63     // User with full administration permissions.
64     $account = $this->drupalCreateUser(['administer entity_test_enhanced']);
65     $this->drupalLogin($account);
66
67     $this->drupalGet($entity->toUrl('collection'));
68     $this->assertSession()->statusCodeEquals(200);
69   }
70
71 }