-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #15605 [Workflow] Add catalog promotion state machine config (W…
…ojdylak) This PR was merged into the 1.13 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.13 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | N/A | License | MIT Commits ------- [CoreBundle][Workflow] Add catalog promotion state machine config
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/Sylius/Bundle/CoreBundle/Resources/config/app/workflow/sylius_catalog_promotion.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
framework: | ||
workflows: | ||
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::GRAPH: | ||
type: state_machine | ||
marking_store: | ||
type: method | ||
property: state | ||
supports: | ||
- Sylius\Component\Core\Model\CatalogPromotionInterface | ||
initial_marking: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE | ||
places: | ||
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE | ||
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING | ||
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_ACTIVE | ||
transitions: | ||
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::TRANSITION_PROCESS: | ||
from: | ||
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE | ||
- !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_ACTIVE | ||
to: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING | ||
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::TRANSITION_ACTIVATE: | ||
from: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING | ||
to: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_ACTIVE | ||
!php/const Sylius\Component\Promotion\Model\CatalogPromotionTransitions::TRANSITION_DEACTIVATE: | ||
from: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_PROCESSING | ||
to: !php/const Sylius\Component\Promotion\Model\CatalogPromotionStates::STATE_INACTIVE |
74 changes: 74 additions & 0 deletions
74
src/Sylius/Bundle/CoreBundle/Tests/Functional/StateMachine/CatalogPromotionWorkflowTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\Tests\Functional\StateMachine; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\CatalogPromotion; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
final class CatalogPromotionWorkflowTest extends KernelTestCase | ||
{ | ||
/** @test */ | ||
public function it_applies_available_transition_for_catalog_promotion_inactive_status(): void | ||
{ | ||
$stateMachine = $this->getStateMachine(); | ||
$catalogPromotion = new CatalogPromotion(); | ||
|
||
$stateMachine->apply($catalogPromotion, 'sylius_catalog_promotion', 'process'); | ||
|
||
$this->assertSame('processing', $catalogPromotion->getState()); | ||
} | ||
|
||
/** @test */ | ||
public function it_applies_available_transition_for_catalog_promotion_active_status(): void | ||
{ | ||
$stateMachine = $this->getStateMachine(); | ||
$catalogPromotion = new CatalogPromotion(); | ||
$catalogPromotion->setState('active'); | ||
|
||
$stateMachine->apply($catalogPromotion, 'sylius_catalog_promotion', 'process'); | ||
|
||
$this->assertSame('processing', $catalogPromotion->getState()); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @dataProvider availableTransitionsForProcessingState | ||
*/ | ||
public function it_applies_all_available_transition_for_catalog_promotion_processing_status( | ||
string $transition, | ||
string $expectedStatus, | ||
): void | ||
{ | ||
$stateMachine = $this->getStateMachine(); | ||
$catalogPromotion = new CatalogPromotion(); | ||
$catalogPromotion->setState('processing'); | ||
|
||
$stateMachine->apply($catalogPromotion, 'sylius_catalog_promotion', $transition); | ||
|
||
$this->assertSame($expectedStatus, $catalogPromotion->getState()); | ||
} | ||
|
||
public function availableTransitionsForProcessingState(): iterable | ||
{ | ||
yield ['activate', 'active']; | ||
yield ['deactivate', 'inactive']; | ||
} | ||
|
||
private function getStateMachine(): StateMachineInterface | ||
{ | ||
return self::getContainer()->get('sylius.state_machine.adapter.symfony_workflow'); | ||
} | ||
} |