Commit 7ace29c3 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Merge branch 'master' of git.unicaen.fr:dsi/sygal

parents 537797a7 3d352430
Loading
Loading
Loading
Loading
Loading
+110 −56
Changes for module/Application/src/Application/Assertion/These/TheseEntityAssertion.php: 110 added lines, 56 removed lines.
Original line number Diff line number Diff line
@@ -55,10 +55,7 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
             * THESE_DEPOT_VERSION_INITIALE
             */
            case ThesePrivileges::THESE_DEPOT_VERSION_INITIALE:
                $this->assertTrue(
                    $this->these && !$this->these->getCorrectionAutorisee(),
                    "Le dépôt d'une version initiale n'est plus possible dès lors qu'une version corrigée est attendue."
                );
                $this->assertAucuneCorrectionAttendue();
                break;

            /**
@@ -94,17 +91,14 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
            case ValidationPrivileges::THESE_VALIDATION_RDV_BU:
                $this->assertAucuneValidationBU("La validation par la BU a été faite.");
                // ce qui suit a été ajouté lors de l'absorption de l'étape RDV_BU_SAISIE_BU par l'étape RDV_BU_VALIDATION_BU
                $this->assertTrue(
                    ($rdvBu = $this->these->getRdvBu()) && $rdvBu->isInfosBuSaisies(),
                    "La BU n'a pas renseigné toutes informations requises."
                );
                $this->assertInfosBuSaisies();
                break;

            /**
             * THESE_VALIDATION_RDV_BU_SUPPR
             */
            case ValidationPrivileges::THESE_VALIDATION_RDV_BU_SUPPR:
                $this->assertTrue($this->these && $this->these->getValidation(TypeValidation::CODE_RDV_BU));
                $this->assertExisteValidationRdvBu();
                $this->assertFalse($this->existeFichierTheseVersionCorrigee());
                break;

@@ -121,9 +115,7 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
             * VALIDATION_DEPOT_THESE_CORRIGEE_SUPPR
             */
            case ValidationPrivileges::VALIDATION_DEPOT_THESE_CORRIGEE_SUPPR:
                $this->assertTrue(
                    $this->these->getValidations(TypeValidation::CODE_CORRECTION_THESE)->count() === 0
                );
                $this->assertAucuneValidationCorrectionThese();
                break;

            /**
@@ -131,24 +123,9 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
             */
            case ValidationPrivileges::VALIDATION_CORRECTION_THESE:
                // le dépôt de la version corrigée doit être validé
                $this->assertTrue(
                    $this->these->getValidations(TypeValidation::CODE_DEPOT_THESE_CORRIGEE)->count() > 0,
                    "Le dépôt de la version corrigée n'a pas encore été validé par le doctorant."
                );

                $this->assertExisteValidationDepotThese();
                // recherche de l'utilisateur parmi les validateurs attendus
                $results = $this->validationService->getValidationsAttenduesPourCorrectionThese($this->these);
                $individu = $this->userContextService->getIdentityIndividu();
                $this->assertTrue($individu !== null);
                $found = false;
                /** @var DepotVersionCorrigeeValidationDirecteur $result */
                foreach ($results as $result) {
                    if ($result->getIndividu()->getId() === $individu->getId()) {
                        $found = true;
                        break;
                    }
                }
                $this->assertTrue($found);
                $this->assertUtilisateurExisteParmiValidateursAttendus();
                break;

            /**
@@ -156,29 +133,14 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
             */
            case ValidationPrivileges::VALIDATION_CORRECTION_THESE_SUPPR:
                // recherche de l'utilisateur parmi les personnes ayant validé
                $individu = $this->userContextService->getIdentityIndividu();
                $this->assertTrue($individu !== null);
                $found = false;
                $validations = $this->these->getValidations(TypeValidation::CODE_CORRECTION_THESE);
                foreach ($validations as $validation) {
                    if ($validation->getIndividu() && $validation->getIndividu()->getId() === $individu->getId()) {
                        $found = true;
                        break;
                    }
                }
                $this->assertTrue($found);
                $this->assertUtilisateurExisteParmiValidateursAyantValide();
                break;

            /**
             * Validation de la remise de la version papier corrigée.
             */
            case ValidationPrivileges::VALIDATION_VERSION_PAPIER_CORRIGEE:
                $res = $this->validationService->getRepository()->findValidationByCodeAndThese(
                    TypeValidation::CODE_VERSION_PAPIER_CORRIGEE,
                    $this->these
                );
                $pasEncoreValidee = empty($res);
                $this->assertTrue($pasEncoreValidee);
                $this->assertAucuneValidationVersionPapierCorrigee();
                break;
        }

@@ -198,9 +160,7 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
     */
    private function assertEntityAsDoctorant($privilege = null)
    {
        $this->assertTrue(
            $this->these->getDoctorant()->getId() === $this->getIdentityDoctorant()->getId(),
            "Cette thèse n'est pas la vôtre.");
        $this->assertUtilisateurEstAuteurDeLaThese();

        switch ($privilege) {
            case ThesePrivileges::THESE_SAISIE_DESCRIPTION:
@@ -214,19 +174,28 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
                }
                break;
        }

        // Une correction doit être apportée par le doctorant, celui-ci ne peut plus modifier son autorisation de diffusion
        if ($privilege === ThesePrivileges::THESE_SAISIE_AUTORISATION_DIFFUSION) {
            $this->assertFalse(
                $this->existeFichierTheseVersionCorrigee(),
            "Aucune version corrigée n'a été fournie.");
            $this->assertAucunDepotVersionCorrigee();
        }

        if (ThesePrivileges::THESE_DEPOT_VERSION_INITIALE) {
            $this->assertFalse(
                $this->these->estSoutenue(),
                "Dépot initial bloqué car soutenance effectuée"
        if ($privilege === ThesePrivileges::THESE_DEPOT_VERSION_INITIALE) {
            $this->assertTheseNonSoutenue();
        }
    }

    private function assertInfosBuSaisies()
    {
        $this->assertTrue(
            ($rdvBu = $this->these->getRdvBu()) && $rdvBu->isInfosBuSaisies(),
            "La BU n'a pas renseigné toutes informations requises."
        );
    }

    private function assertExisteValidationRdvBu()
    {
        $this->assertTrue($this->these && $this->these->getValidation(TypeValidation::CODE_RDV_BU));
    }

    private function assertAucuneValidationBU($message = null)
@@ -238,6 +207,69 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
            $message ?: "Opération impossible dès lors que la BU a validé.");
    }

    private function assertAucuneCorrectionAttendue()
    {
        $this->assertTrue(
            !$this->these->getCorrectionAutorisee(),
            "Le dépôt d'une version initiale n'est plus possible dès lors qu'une version corrigée est attendue."
        );
    }

    private function assertAucuneValidationCorrectionThese()
    {
        $this->assertTrue($this->these->getValidations(TypeValidation::CODE_CORRECTION_THESE)->count() === 0);
    }

    private function assertExisteValidationDepotThese()
    {
        $this->assertTrue(
            $this->these->getValidations(TypeValidation::CODE_DEPOT_THESE_CORRIGEE)->count() > 0,
            "Le dépôt de la version corrigée n'a pas encore été validé par le doctorant."
        );
    }

    private function assertUtilisateurExisteParmiValidateursAttendus()
    {
        // recherche de l'utilisateur parmi les validateurs attendus
        $results = $this->validationService->getValidationsAttenduesPourCorrectionThese($this->these);
        $individu = $this->userContextService->getIdentityIndividu();
        $this->assertTrue($individu !== null);
        $found = false;
        /** @var DepotVersionCorrigeeValidationDirecteur $result */
        foreach ($results as $result) {
            if ($result->getIndividu()->getId() === $individu->getId()) {
                $found = true;
                break;
            }
        }
        $this->assertTrue($found);
    }

    private function assertUtilisateurExisteParmiValidateursAyantValide()
    {
        // recherche de l'utilisateur parmi les personnes ayant validé
        $individu = $this->userContextService->getIdentityIndividu();
        $this->assertTrue($individu !== null);
        $found = false;
        $validations = $this->these->getValidations(TypeValidation::CODE_CORRECTION_THESE);
        foreach ($validations as $validation) {
            if ($validation->getIndividu() && $validation->getIndividu()->getId() === $individu->getId()) {
                $found = true;
                break;
            }
        }
        $this->assertTrue($found);
    }

    private function assertAucuneValidationVersionPapierCorrigee()
    {
        $res = $this->validationService->getRepository()->findValidationByCodeAndThese(
            TypeValidation::CODE_VERSION_PAPIER_CORRIGEE,
            $this->these
        );
        $pasEncoreValidee = empty($res);
        $this->assertTrue($pasEncoreValidee);
    }

    private function assertCorrectionAttendue()
    {
@@ -280,6 +312,28 @@ class TheseEntityAssertion implements EntityAssertionInterface, ValidationServic
        }
    }

    private function assertUtilisateurEstAuteurDeLaThese()
    {
        $this->assertTrue(
            $this->these->getDoctorant()->getId() === $this->getIdentityDoctorant()->getId(),
            "Cette thèse n'est pas la vôtre.");
    }

    private function assertAucunDepotVersionCorrigee()
    {
        $this->assertFalse(
            $this->existeFichierTheseVersionCorrigee(),
            "Aucune version corrigée n'a été fournie.");
    }

    private function assertTheseNonSoutenue()
    {
        $this->assertFalse(
            $this->these->estSoutenue(),
            "Dépot initial bloqué car soutenance effectuée"
        );
    }

    /**
     * @return bool
     */
+62 −21
Changes for module/Application/tests/ApplicationUnitTest/Assertion/TheseEntityAssertionTest.php: 62 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@

namespace ApplicationUnitTest\Assertion;

use Application\Assertion\Exception\FailedAssertionException;
use Application\Assertion\These\TheseEntityAssertion;
use Application\Entity\Db\These;
use Application\Provider\Privilege\ThesePrivileges;
use Application\Service\UserContextService;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophet;

@@ -16,36 +16,68 @@ class TheseEntityAssertionTest extends \PHPUnit_Framework_TestCase
     */
    private $assertion;

    /**
     * @var Prophet
     */
    private $prophet;

    /**
     * @var These
     */
    private $these;

    /**
     * @var These|ObjectProphecy
     */
    private $theseProphecy;

    /**
     * @var UserContextService|ObjectProphecy
     */
    private $userContextServiceProphecy;

    /**
     *
     */
    protected function setUp()
    {
        $this->prophet = new Prophet();
        $this->assertion = new TheseEntityAssertion();
    }

    public function getCorrectionAutoriseeValeurs()
    {
        return [
            [These::CORRECTION_MINEURE],
            [These::CORRECTION_MAJEURE],
        ];
        $this->theseProphecy = $this->theseProphecy();
        $this->userContextServiceProphecy = $this->userContextServiceProphecy();
    }

    /**
     * @dataProvider getCorrectionAutoriseeValeurs
     * @expectedException FailedAssertionException
     * @param string $correctionAutorisee
     * @expectedException \Application\Assertion\Exception\FailedAssertionException
     */
    public function test_1er_depot_interdit_si_correction_mineure_autorisee($correctionAutorisee)
    public function test_interdit_1er_depot_si_correction_attendue()
    {
        $privilege = ThesePrivileges::THESE_DEPOT_VERSION_INITIALE;
        // Une correction est attendue lorsque $these->getCorrectionAutorisee() retourne une valeur non vide
        $this->theseProphecy->getCorrectionAutorisee()->willReturn('non vide');
        $these = $this->theseProphecy->reveal();

        $this->assertion
            ->setThese($these)
            ->assert(ThesePrivileges::THESE_DEPOT_VERSION_INITIALE);
    }

        $theseProphecy = $this->theseProphecy();
        $theseProphecy->getCorrectionAutorisee()->willReturn($correctionAutorisee);
    public function test_autorise_1er_depot_si_aucune_correction_attendue()
    {
        // Aucune correction n'est attendue lorsque $these->getCorrectionAutorisee() retourne une valeur vide
        $this->theseProphecy->getCorrectionAutorisee()->willReturn(null);
        /** @var These $these */
        $these = $theseProphecy->reveal();
        $these = $this->theseProphecy->reveal();

        $this->assertion
        $this->userContextServiceProphecy->getSelectedRoleDoctorant()->willReturn('non vide');
        /** @var UserContextService $userContextService */
        $userContextService = $this->userContextServiceProphecy->reveal();

        $res = $this->assertion
            ->setThese($these)
            ->assert($privilege);
            ->setUserContextService($userContextService)
            ->assert(ThesePrivileges::THESE_DEPOT_VERSION_INITIALE);

        $this->assertTrue($res);
    }

    /**
@@ -53,10 +85,19 @@ class TheseEntityAssertionTest extends \PHPUnit_Framework_TestCase
     */
    private function theseProphecy()
    {
        $prophet = new Prophet();
        /** @var These|ObjectProphecy $prophecy */
        $prophecy = $this->prophet->prophesize(These::class);

        return $prophecy;
    }

    /**
     * @return UserContextService|ObjectProphecy
     */
    private function userContextServiceProphecy()
    {
        /** @var These|ObjectProphecy $prophecy */
        $prophecy = $prophet->prophesize(These::class);
        $prophecy = $this->prophet->prophesize(UserContextService::class);

        return $prophecy;
    }