Skip to content

Commit

Permalink
Few tests modified
Browse files Browse the repository at this point in the history
  • Loading branch information
shahariaazam committed Jun 6, 2020
1 parent dc21de9 commit ad8d278
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/Controller/AuthControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ public static function getAuthenticatedClient(User $user = null, $client = null)
return $client;
}

/**
* @param KernelBrowser $client
* @param $path
*
* @param array $roles
* @return int
*/
public static function checkPathIsAccessibleByRoles(KernelBrowser $client, $path, array $roles)
{
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$userRepository = $em->getRepository(User::class);

$user = $userRepository->findOneBy(['email' => 'admin@example.com']);
$user->setRoles($roles);

$client = AuthControllerTest::getAuthenticatedClient($user, $client);
$client->request('GET', $path);

return $client->getResponse()->getStatusCode();
}

public function testResetPasswordShouldRedirectToChangePasswordIfUserAlreadyLoggedIn()
{
$client = $this->getAuthenticatedClient();
Expand Down
7 changes: 7 additions & 0 deletions tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

class UsersControllerTest extends WebTestCase
{
public function testWithoutAdminNobodyCanAccessTheseRoutes()
{
$client = static::createClient();
$statusCode = AuthControllerTest::checkPathIsAccessibleByRoles($client, '/admin/users', ['ROLE_USER']);
$this->assertEquals(403, $statusCode);
}

public function testIndex()
{
$client = AuthControllerTest::getAuthenticatedClient();
Expand Down

0 comments on commit ad8d278

Please sign in to comment.