diff --git a/tests/Controller/IndexControllerTest.php b/tests/Controller/IndexControllerTest.php new file mode 100644 index 0000000..a2b7364 --- /dev/null +++ b/tests/Controller/IndexControllerTest.php @@ -0,0 +1,92 @@ +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 +} \ No newline at end of file diff --git a/tests/Functional/AbstractFunctionalTest.php b/tests/Functional/AbstractFunctionalTest.php index c5209f4..fd0e13a 100644 --- a/tests/Functional/AbstractFunctionalTest.php +++ b/tests/Functional/AbstractFunctionalTest.php @@ -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; + } } \ No newline at end of file