Easy_solution/tests/Controller/IndexControllerTest.php

92 lines
2.9 KiB
PHP

<?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
}