Skip to content

Commit 864615a

Browse files
committed
Create functional tests for user roles/permissions
Signed-off-by: Tim Goudriaan <tim@codedmonkey.com>
1 parent c5f4a89 commit 864615a

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace CodedMonkey\Dirigent\Tests\FunctionalTests\Controller\Dashboard;
4+
5+
use CodedMonkey\Dirigent\Kernel;
6+
use CodedMonkey\Dirigent\Tests\Helper\WebTestCaseTrait;
7+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
class DashboardRootControllerPermissionsTest extends WebTestCase
11+
{
12+
use WebTestCaseTrait;
13+
14+
public function testAdministratorHasAdminMenu(): void
15+
{
16+
$client = static::createClient();
17+
$this->loginUser('admin');
18+
19+
$client->request('GET', '/');
20+
21+
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
22+
23+
$this->assertAnySelectorTextSame('.menu-item-label', 'Administration');
24+
}
25+
26+
public function testUserDoesNotHaveAdminMenu(): void
27+
{
28+
$client = static::createClient();
29+
$this->loginUser();
30+
31+
$client->request('GET', '/');
32+
33+
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
34+
35+
$this->assertAnySelectorTextNotContains('.menu-item-label', 'Administration');
36+
}
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace CodedMonkey\Dirigent\Tests\FunctionalTests\Controller\Dashboard;
4+
5+
use CodedMonkey\Dirigent\Kernel;
6+
use CodedMonkey\Dirigent\Tests\Helper\WebTestCaseTrait;
7+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
class DashboardUserControllerTest extends WebTestCase
11+
{
12+
use WebTestCaseTrait;
13+
14+
public function testUserDoesNotHaveAccess(): void
15+
{
16+
$client = static::createClient();
17+
$this->loginUser();
18+
19+
$client->request('GET', '/users');
20+
21+
$this->assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
22+
}
23+
}

0 commit comments

Comments
 (0)