3 namespace Drupal\Tests\entity\Functional;
5 use Drupal\entity_module_test\Entity\EnhancedEntity;
6 use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
7 use Drupal\Tests\block\Traits\BlockCreationTrait;
8 use Drupal\Tests\BrowserTestBase;
11 * Tests the collection route access check.
15 * @runTestsInSeparateProcesses
17 * @preserveGlobalState disabled
19 class CollectionRouteAccessTest extends BrowserTestBase {
21 use BlockCreationTrait;
28 public static $modules = ['entity_module_test', 'user', 'entity', 'block'];
33 protected function setUp() {
36 EnhancedEntityBundle::create([
41 $this->placeBlock('local_tasks_block');
42 $this->placeBlock('system_breadcrumb_block');
46 * Test the collection route access.
48 public function testCollectionRouteAccess() {
49 $entity = EnhancedEntity::create([
55 // User without any relevant permissions.
56 $account = $this->drupalCreateUser(['access administration pages']);
57 $this->drupalLogin($account);
59 $this->drupalGet($entity->toUrl('collection'));
60 $this->assertSession()->statusCodeEquals(403);
62 // User with "access overview" permissions.
63 $account = $this->drupalCreateUser(['access entity_test_enhanced overview']);
64 $this->drupalLogin($account);
66 $this->drupalGet($entity->toUrl('collection'));
67 $this->assertSession()->statusCodeEquals(200);
69 // User with full administration permissions.
70 $account = $this->drupalCreateUser(['administer entity_test_enhanced']);
71 $this->drupalLogin($account);
73 $this->drupalGet($entity->toUrl('collection'));
74 $this->assertSession()->statusCodeEquals(200);