diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/workflow/sylius_catalog_promotion.yaml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/workflow/sylius_catalog_promotion.yaml new file mode 100644 index 00000000000..9744bd10de0 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/workflow/sylius_catalog_promotion.yaml @@ -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 diff --git a/src/Sylius/Bundle/CoreBundle/Tests/Functional/StateMachine/CatalogPromotionWorkflowTest.php b/src/Sylius/Bundle/CoreBundle/Tests/Functional/StateMachine/CatalogPromotionWorkflowTest.php new file mode 100644 index 00000000000..199901ea47c --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Tests/Functional/StateMachine/CatalogPromotionWorkflowTest.php @@ -0,0 +1,74 @@ +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'); + } +}