3 namespace Drupal\Tests\entity\Functional;
5 use Drupal\entity_module_test\Entity\EnhancedEntity;
6 use Drupal\Tests\block\Traits\BlockCreationTrait;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests the collection route access check.
14 * @runTestsInSeparateProcesses
16 * @preserveGlobalState disabled
18 class CollectionRouteAccessTest extends BrowserTestBase {
20 use BlockCreationTrait;
27 public static $modules = ['entity_module_test', 'user', 'entity', 'block'];
32 protected function setUp() {
35 $this->placeBlock('local_tasks_block');
36 $this->placeBlock('system_breadcrumb_block');
40 * Test the collection route access.
42 public function testCollectionRouteAccess() {
43 $entity = EnhancedEntity::create([
49 // User without any relevant permissions.
50 $account = $this->drupalCreateUser(['access administration pages']);
51 $this->drupalLogin($account);
53 $this->drupalGet($entity->toUrl('collection'));
54 $this->assertSession()->statusCodeEquals(403);
56 // User with "access overview" permissions.
57 $account = $this->drupalCreateUser(['access entity_test_enhanced overview']);
58 $this->drupalLogin($account);
60 $this->drupalGet($entity->toUrl('collection'));
61 $this->assertSession()->statusCodeEquals(200);
63 // User with full administration permissions.
64 $account = $this->drupalCreateUser(['administer entity_test_enhanced']);
65 $this->drupalLogin($account);
67 $this->drupalGet($entity->toUrl('collection'));
68 $this->assertSession()->statusCodeEquals(200);