Test on index controller
This commit is contained in:
parent
2d0eddaf51
commit
86ef5fa6f6
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Tests\Functional\AbstractFunctionalTest;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
|
||||
class IndexControllerTest extends AbstractFunctionalTest
|
||||
{
|
||||
|
||||
//Region dashboard tests
|
||||
|
||||
//endregion
|
||||
|
||||
//region index tests
|
||||
|
||||
#[Test]
|
||||
public function test_index_successful_super_admin(): void
|
||||
{
|
||||
$admin = $this->createUser('sAdmin@test.com', ['ROLE_SUPER_ADMIN']);
|
||||
$this->client->loginUser($admin);
|
||||
$this->client->request('GET', '/');
|
||||
|
||||
self::assertResponseRedirects('/organization/');
|
||||
$this->client->followRedirect();
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_index_successful_admin_single_org(): void
|
||||
{
|
||||
$admin = $this->createUser('admin@test.com', ['ROLE_ADMIN']);
|
||||
$this->client->loginUser($admin);
|
||||
$org = $this->createOrganization('Test Org');
|
||||
$app = $this->createApp('Test App');
|
||||
$app -> addOrganization($org);
|
||||
$uo = $this->createUOLink($admin, $org);
|
||||
$role = $this->createRole('ADMIN');
|
||||
$uoa = $this->createUOALink($uo , $app, $role);
|
||||
|
||||
$this->client->request('GET', '/');
|
||||
self::assertResponseRedirects('/organization/');
|
||||
|
||||
|
||||
$this->client->followRedirect();
|
||||
|
||||
|
||||
self::assertResponseRedirects('/organization/view/' . $org->getId());
|
||||
|
||||
|
||||
$this->client->followRedirect();
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_index_successful_admin_mutiple_org(): void
|
||||
{
|
||||
$admin = $this->createUser('admin@test.com', ['ROLE_ADMIN']);
|
||||
$this->client->loginUser($admin);
|
||||
$org = $this->createOrganization('Test Org');
|
||||
$org2 = $this->createOrganization('Test Org2');
|
||||
$app = $this->createApp('Test App');
|
||||
$app -> addOrganization($org);
|
||||
$uo = $this->createUOLink($admin, $org);
|
||||
$uo2 = $this->createUOLink($admin, $org2);
|
||||
$role = $this->createRole('ADMIN');
|
||||
$uoa = $this->createUOALink($uo , $app, $role);
|
||||
$uoa2 = $this->createUOALink($uo2 , $app, $role);
|
||||
|
||||
$this->client->request('GET', '/');
|
||||
self::assertResponseRedirects('/organization/');
|
||||
$this->client->followRedirect();
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_index_successful_user(): void
|
||||
{
|
||||
$user = $this->createUser('user@test.com', ['ROLE_USER']);
|
||||
$this->client->loginUser($user);
|
||||
$org = $this->createOrganization('Test Org');
|
||||
$app = $this->createApp('Test App');
|
||||
$app -> addOrganization($org);
|
||||
$uo = $this->createUOLink($user, $org);
|
||||
$role = $this->createRole('USER');
|
||||
$uoa = $this->createUOALink($uo , $app, $role);
|
||||
$this->client->request('GET', '/');
|
||||
self::assertResponseRedirects('/application/');
|
||||
$this->client->followRedirect();
|
||||
self::assertResponseIsSuccessful();
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
|
@ -4,7 +4,10 @@ namespace App\Tests\Functional;
|
|||
|
||||
use App\Entity\Apps;
|
||||
use App\Entity\Organizations;
|
||||
use App\Entity\Roles;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserOrganizatonApp;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
|
@ -69,4 +72,34 @@ abstract class AbstractFunctionalTest extends WebTestCase
|
|||
|
||||
return $org;
|
||||
}
|
||||
|
||||
protected function createUOLink(User $user, Organizations $organization): UsersOrganizations{
|
||||
$uo = new UsersOrganizations();
|
||||
$uo->setUsers($user);
|
||||
$uo->setOrganization($organization);
|
||||
$this->entityManager->persist($uo);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $uo;
|
||||
}
|
||||
|
||||
protected function createUOALink(UsersOrganizations $uo, Apps $app, Roles $role): UserOrganizatonApp{
|
||||
$uoa = new UserOrganizatonApp();
|
||||
$uoa->setUserOrganization($uo);
|
||||
$uoa->setApplication($app);
|
||||
$uoa->setRole($role);
|
||||
$this->entityManager->persist($uoa);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $uoa;
|
||||
}
|
||||
|
||||
protected function createRole(string $name): Roles{
|
||||
$role = new Roles();
|
||||
$role->setName($name);
|
||||
$this->entityManager->persist($role);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $role;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue