mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix tests for EntityWorkflow
This commit is contained in:
parent
e3c5f6f95f
commit
199a441593
@ -135,6 +135,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
if (!$this->steps->contains($step)) {
|
if (!$this->steps->contains($step)) {
|
||||||
$this->steps[] = $step;
|
$this->steps[] = $step;
|
||||||
$step->setEntityWorkflow($this);
|
$step->setEntityWorkflow($this);
|
||||||
|
$this->stepsChainedCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -332,32 +333,26 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
public function isFinal(): bool
|
public function isFinal(): bool
|
||||||
{
|
{
|
||||||
$steps = $this->getStepsChained();
|
foreach ($this->getStepsChained() as $step) {
|
||||||
|
if ($step->isFinal()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (1 === count($steps)) {
|
return false;
|
||||||
// the initial step cannot be finalized
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var EntityWorkflowStep $last */
|
|
||||||
$last = end($steps);
|
|
||||||
|
|
||||||
return $last->isFinal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isFreeze(): bool
|
public function isFreeze(): bool
|
||||||
{
|
{
|
||||||
$steps = $this->getStepsChained();
|
$steps = $this->getStepsChained();
|
||||||
|
|
||||||
if (1 === count($steps)) {
|
foreach ($this->getStepsChained() as $step) {
|
||||||
// the initial step cannot be finalized
|
if ($step->isFreezeAfter()) {
|
||||||
return false;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var EntityWorkflowStep $last */
|
return false;
|
||||||
$last = end($steps);
|
|
||||||
|
|
||||||
return $last->getPrevious()->isFreezeAfter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUserSubscribedToFinal(User $user): bool
|
public function isUserSubscribedToFinal(User $user): bool
|
||||||
@ -434,7 +429,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
$newStep->setCurrentStep($step);
|
$newStep->setCurrentStep($step);
|
||||||
|
|
||||||
// copy the freeze
|
// copy the freeze
|
||||||
if ($this->getCurrentStep()->isFreezeAfter()) {
|
if ($this->isFreeze()) {
|
||||||
$newStep->setFreezeAfter(true);
|
$newStep->setFreezeAfter(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,30 +24,30 @@ final class EntityWorkflowTest extends TestCase
|
|||||||
{
|
{
|
||||||
$entityWorkflow = new EntityWorkflow();
|
$entityWorkflow = new EntityWorkflow();
|
||||||
|
|
||||||
$entityWorkflow->getCurrentStep()->setFinalizeAfter(true);
|
|
||||||
$entityWorkflow->setStep('final');
|
$entityWorkflow->setStep('final');
|
||||||
|
$entityWorkflow->getCurrentStep()->setIsFinal(true);
|
||||||
|
|
||||||
$this->assertTrue($entityWorkflow->isFinalize());
|
$this->assertTrue($entityWorkflow->isFinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsFinalizeWith4Steps()
|
public function testIsFinalizeWith4Steps()
|
||||||
{
|
{
|
||||||
$entityWorkflow = new EntityWorkflow();
|
$entityWorkflow = new EntityWorkflow();
|
||||||
|
|
||||||
$this->assertFalse($entityWorkflow->isFinalize());
|
$this->assertFalse($entityWorkflow->isFinal());
|
||||||
|
|
||||||
$entityWorkflow->setStep('two');
|
$entityWorkflow->setStep('two');
|
||||||
|
|
||||||
$this->assertFalse($entityWorkflow->isFinalize());
|
$this->assertFalse($entityWorkflow->isFinal());
|
||||||
|
|
||||||
$entityWorkflow->setStep('previous_final');
|
$entityWorkflow->setStep('previous_final');
|
||||||
|
|
||||||
$this->assertFalse($entityWorkflow->isFinalize());
|
$this->assertFalse($entityWorkflow->isFinal());
|
||||||
|
|
||||||
$entityWorkflow->getCurrentStep()->setFinalizeAfter(true);
|
$entityWorkflow->getCurrentStep()->setIsFinal(true);
|
||||||
$entityWorkflow->setStep('final');
|
$entityWorkflow->setStep('final');
|
||||||
|
|
||||||
$this->assertTrue($entityWorkflow->isFinalize());
|
$this->assertTrue($entityWorkflow->isFinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsFreeze()
|
public function testIsFreeze()
|
||||||
@ -64,11 +64,8 @@ final class EntityWorkflowTest extends TestCase
|
|||||||
|
|
||||||
$this->assertFalse($entityWorkflow->isFreeze());
|
$this->assertFalse($entityWorkflow->isFreeze());
|
||||||
|
|
||||||
$entityWorkflow->getCurrentStep()->setFreezeAfter(true);
|
|
||||||
|
|
||||||
$this->assertFalse($entityWorkflow->isFreeze());
|
|
||||||
|
|
||||||
$entityWorkflow->setStep('freezed');
|
$entityWorkflow->setStep('freezed');
|
||||||
|
$entityWorkflow->getCurrentStep()->setFreezeAfter(true);
|
||||||
|
|
||||||
$this->assertTrue($entityWorkflow->isFreeze());
|
$this->assertTrue($entityWorkflow->isFreeze());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user