|
|
@@ -5,6 +5,13 @@ namespace App\Tests\Application;
|
|
|
use App\Entity\Access\Access;
|
|
|
use App\Entity\Person\Person;
|
|
|
use App\Entity\Public\FederationStructure;
|
|
|
+use App\Enum\Organization\LegalEnum;
|
|
|
+use App\Enum\Organization\PrincipalTypeEnum;
|
|
|
+use App\Enum\Organization\SettingsProductEnum;
|
|
|
+use App\Tests\Fixture\Factory\Access\AccessFactory;
|
|
|
+use App\Tests\Fixture\Factory\Organization\OrganizationFactory;
|
|
|
+use App\Tests\Fixture\Factory\Organization\SettingsFactory;
|
|
|
+use App\Tests\Fixture\Factory\Person\PersonFactory;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
@@ -42,7 +49,7 @@ abstract class OtWebTestCase extends ApiTestCase
|
|
|
$this->purgeDb();
|
|
|
|
|
|
// Définit les fixtures et flush
|
|
|
- $this->setFixtures();
|
|
|
+ $this->loadFixture();
|
|
|
$this->em->flush();
|
|
|
|
|
|
// Instancie le client qui exécutera les requêtes à l'api
|
|
|
@@ -69,14 +76,36 @@ abstract class OtWebTestCase extends ApiTestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Create and persist the fixtures (no need to flush, the setup will perform it later)
|
|
|
+ * Create and persist the fixtures (do not flush)
|
|
|
*
|
|
|
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#same-entities-used-in-these-docs
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- protected function setFixtures(): void {
|
|
|
- // TODO: préparer un jeu de fixtures par défaut
|
|
|
+ protected function loadFixture(): void {
|
|
|
+ $person = PersonFactory::createOne(
|
|
|
+ [
|
|
|
+ 'username' => 'username',
|
|
|
+ 'password' => 'password'
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ $organization = OrganizationFactory::createOne([
|
|
|
+ 'legalStatus' => LegalEnum::ASSOCIATION_LAW_1901()->getValue(),
|
|
|
+ 'principalType' => PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY()->getValue(),
|
|
|
+ 'name' => 'My Organization'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ SettingsFactory::createOne([
|
|
|
+ 'product' => SettingsProductEnum::ARTIST(),
|
|
|
+ 'organization' => $organization
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->user = AccessFactory::createOne([
|
|
|
+ 'person' => $person,
|
|
|
+ 'organization' => $organization,
|
|
|
+ 'roles' => ['ROLE_USERS_VIEW']
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -97,7 +126,6 @@ abstract class OtWebTestCase extends ApiTestCase
|
|
|
}
|
|
|
|
|
|
$parameters = ['headers' => $headers];
|
|
|
-
|
|
|
if ($data) {
|
|
|
$parameters['json'] = $data;
|
|
|
}
|
|
|
@@ -175,6 +203,36 @@ abstract class OtWebTestCase extends ApiTestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Login as the given Access user
|
|
|
+ *
|
|
|
+ * @param Proxy|Access $access
|
|
|
+ * @return void
|
|
|
+ * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
|
|
|
+ * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
|
|
|
+ * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
|
|
+ * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
|
|
+ */
|
|
|
+ protected function loginAs(Proxy | Access $access): void {
|
|
|
+ $person = $access->getPerson();
|
|
|
+
|
|
|
+ $response = $this->post(
|
|
|
+ '/login_check',
|
|
|
+ ['username' => $person->getUsername(), 'password' => $person->getPassword()]
|
|
|
+ );
|
|
|
+ $content = $response->getContent();
|
|
|
+
|
|
|
+ $this->securityToken = json_decode($content)->token;
|
|
|
+ $this->user = $access;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Assert that the response has the expected status code and is well formated
|
|
|
+ *
|
|
|
+ * @param string $resourceClass
|
|
|
+ * @param int $expectedStatus
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
protected function validateCollectionSchema(string $resourceClass, int $expectedStatus = 200): void {
|
|
|
$this->assertResponseStatusCodeSame($expectedStatus);
|
|
|
|
|
|
@@ -189,17 +247,4 @@ abstract class OtWebTestCase extends ApiTestCase
|
|
|
// >>> Issue with the json typed PublicStructure::addresses properties
|
|
|
// $this->assertMatchesResourceCollectionJsonSchema($resourceClass);
|
|
|
}
|
|
|
-
|
|
|
- protected function loginAs(Proxy | Access $access): void {
|
|
|
- $person = $access->getPerson();
|
|
|
-
|
|
|
- $response = $this->post(
|
|
|
- '/login_check',
|
|
|
- ['username' => $person->getUsername(), 'password' => $person->getPassword()]
|
|
|
- );
|
|
|
- $content = $response->getContent();
|
|
|
-
|
|
|
- $this->securityToken = json_decode($content)->token;
|
|
|
- $this->user = $access;
|
|
|
- }
|
|
|
}
|