Skip to content

Commit 9fdfda5

Browse files
committed
test: grant anonymous access content
1 parent c6a1ee2 commit 9fdfda5

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/src/Kernel/MenuEndpointTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Drupal\node\Entity\NodeType;
1212
use Drupal\system\Entity\Menu;
1313
use Drupal\user\Entity\User;
14+
use Drupal\user\Entity\Role;
15+
use Drupal\user\RoleInterface;
1416
use Symfony\Component\HttpFoundation\Request;
1517

1618
/**
@@ -59,6 +61,18 @@ protected function setUp(): void {
5961
$this->installSchema('node', ['node_access']);
6062
$this->installConfig(['jsonapi_frontend']);
6163

64+
// Allow anonymous users to access published content, so menu access checks
65+
// treat node links as accessible.
66+
$anonymous = Role::load(RoleInterface::ANONYMOUS_ID);
67+
if (!$anonymous) {
68+
$anonymous = Role::create([
69+
'id' => RoleInterface::ANONYMOUS_ID,
70+
'label' => 'Anonymous',
71+
]);
72+
}
73+
$anonymous->grantPermission('access content');
74+
$anonymous->save();
75+
6276
$admin = User::create([
6377
'name' => 'admin',
6478
'status' => 1,

0 commit comments

Comments
 (0)