Commit 117a4ee6 authored by Florian Joriot's avatar Florian Joriot
Browse files

Mise en place test calcul Actif + correction fonction

parent ff172738
Loading
Loading
Loading
Loading
Loading
+3 −3
Changes for module/Contrat/src/Tbl/Process/ContratProcess.php: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -308,15 +308,15 @@ class ContratProcess implements ProcessInterface
            $this->calculAutreLibelles($contrat);
            $this->calculActif($contrat);
        }

        // ajout de contrats vides d'enseignement si aucune
        // Activer les lignes où il y a besoin de contrats/avenants
    }



    public function calculActif(Contrat $contrat): void
    {
        if($contrat->id){
            $contrat->actif = true;
        }
        if (!$contrat->actif) {
            if ($this->parametreAvenant == Parametre::AVENANT_AUTORISE) {
                $contrat->actif = true;
+155
Changes for tests/TblContrat/CalculActifTest.php: 155 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php declare(strict_types=1);

namespace TblContrat;

use Application\Entity\Db\Parametre;
use Contrat\Tbl\Process\Model\Contrat;
use tests\TblContrat\TblContratTestCase;

final class CalculActifTest extends TblContratTestCase
{
    public function testParametresCaenMission()
    {
        $parametres = [
            Parametre::AVENANT     => Parametre::AVENANT_AUTORISE,
            Parametre::CONTRAT_MIS => Parametre::CONTRAT_MIS_MISSION,
            Parametre::CONTRAT_ENS => Parametre::CONTRAT_ENS_COMPOSANTE,
        ];
        $this->useParametres($parametres);


        /* Jeu de données initial */
        $contrat1            = new Contrat();
        $contrat1->id        = 1;
        $contrat1->edite     = true;
        $contrat1->isMission = true;
        $contrat1->parent    = null;

        $avenant            = new Contrat();
        $avenant->id        = 1;
        $avenant->edite     = true;
        $avenant->isMission = true;
        $avenant->parent    = $contrat1;

        $avenant2            = new Contrat();
        $avenant2->isMission = true;
        $avenant2->parent    = $contrat1;

        $this->process->calculActif($contrat1);
        $this->process->calculActif($avenant);
        $this->process->calculActif($avenant2);

        self::assertTrue($contrat1->actif);
        self::assertTrue($avenant->actif);
        self::assertTrue($avenant2->actif);
    }

    public function testParametresCaenEnseignement()
    {
        $parametres = [
            Parametre::AVENANT     => Parametre::AVENANT_AUTORISE,
            Parametre::CONTRAT_MIS => Parametre::CONTRAT_MIS_MISSION,
            Parametre::CONTRAT_ENS => Parametre::CONTRAT_ENS_COMPOSANTE,
        ];
        $this->useParametres($parametres);


        /* Jeu de données initial */
        $contrat1            = new Contrat();
        $contrat1->id        = 1;
        $contrat1->edite     = true;
        $contrat1->isMission = false;
        $contrat1->parent    = null;

        $avenant            = new Contrat();
        $avenant->id        = 1;
        $avenant->edite     = true;
        $avenant->isMission = false;
        $avenant->parent    = $contrat1;

        $avenant2            = new Contrat();
        $avenant2->isMission = false;
        $avenant2->parent    = $contrat1;

        $this->process->calculActif($contrat1);
        $this->process->calculActif($avenant);
        $this->process->calculActif($avenant2);

        self::assertTrue($contrat1->actif);
        self::assertTrue($avenant->actif);
        self::assertTrue($avenant2->actif);
    }

    public function testParametresAvenantDesactiveEnseignement()
    {
        $parametres = [
            Parametre::AVENANT     => Parametre::AVENANT_DESACTIVE,
            Parametre::CONTRAT_MIS => Parametre::CONTRAT_MIS_MISSION,
            Parametre::CONTRAT_ENS => Parametre::CONTRAT_ENS_COMPOSANTE,
        ];
        $this->useParametres($parametres);


        /* Jeu de données initial */
        $contrat1            = new Contrat();
        $contrat1->id        = 1;
        $contrat1->edite     = true;
        $contrat1->isMission = false;
        $contrat1->parent    = null;

        $avenant            = new Contrat();
        $avenant->id        = 1;
        $avenant->edite     = true;
        $avenant->isMission = false;
        $avenant->parent    = $contrat1;

        $avenant2            = new Contrat();
        $avenant2->isMission = false;
        $avenant2->parent    = $contrat1;

        $this->process->calculActif($contrat1);
        $this->process->calculActif($avenant);
        $this->process->calculActif($avenant2);

        self::assertTrue($contrat1->actif);
        self::assertTrue($avenant->actif);
        self::assertFalse($avenant2->actif);
    }

    public function testParametresAvenantDesactiveMission()
    {
        $parametres = [
            Parametre::AVENANT     => Parametre::AVENANT_DESACTIVE,
            Parametre::CONTRAT_MIS => Parametre::CONTRAT_MIS_MISSION,
            Parametre::CONTRAT_ENS => Parametre::CONTRAT_ENS_COMPOSANTE,
        ];
        $this->useParametres($parametres);


        /* Jeu de données initial */
        $contrat1            = new Contrat();
        $contrat1->id        = 1;
        $contrat1->edite     = true;
        $contrat1->isMission = false;
        $contrat1->parent    = null;

        $avenant            = new Contrat();
        $avenant->id        = 1;
        $avenant->edite     = true;
        $avenant->isMission = false;
        $avenant->parent    = $contrat1;

        $avenant2            = new Contrat();
        $avenant2->isMission = false;
        $avenant2->parent    = $contrat1;

        $this->process->calculActif($contrat1);
        $this->process->calculActif($avenant);
        $this->process->calculActif($avenant2);

        self::assertTrue($contrat1->actif);
        self::assertTrue($avenant->actif);
        self::assertFalse($avenant2->actif);
    }

}