public function testCreateFromConfig() { $flowStub = $this->getMock('\\Craue\\FormFlowBundle\\Form\\FormFlowInterface'); $step = Step::createFromConfig(1, array()); $this->assertEquals(1, $step->getNumber()); $this->assertEquals(null, $step->getLabel()); $this->assertEquals(null, $step->getType()); $this->assertEquals(false, $step->isSkipped()); $step->evaluateSkipping(1, $flowStub); $this->assertEquals(false, $step->isSkipped()); $step = Step::createFromConfig(1, array('label' => 'country')); $this->assertEquals('country', $step->getLabel()); $step = Step::createFromConfig(1, array('skip' => true)); $this->assertEquals(true, $step->isSkipped()); $step->evaluateSkipping(1, $flowStub); $this->assertEquals(true, $step->isSkipped()); $step = Step::createFromConfig(1, array('skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) { return true; })); $this->assertEquals(null, $step->isSkipped()); $step->evaluateSkipping(1, $flowStub); $this->assertEquals(true, $step->isSkipped()); $flowStubWithData = $this->getMock('\\Craue\\FormFlowBundle\\Form\\FormFlowInterface'); $flowStubWithData->expects($this->once())->method('getFormData')->will($this->returnValue(array('blah' => true))); $step = Step::createFromConfig(1, array('skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) { $formData = $flow->getFormData(); return $estimatedCurrentStepNumber > 1 && $formData['blah'] === true; })); $step->evaluateSkipping(2, $flowStubWithData); $this->assertEquals(true, $step->isSkipped()); }
protected function createStepWithSkipCallable($number, $returnValue) { return Step::createFromConfig($number, array('skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) use($returnValue) { return $returnValue; })); }
/** * Creates all steps from the given configuration. * @param array $stepsConfig * @return StepInterface[] Value with index 0 is step 1. */ public function createStepsFromConfig(array $stepsConfig) { $steps = array(); // fix array indexes not starting at 0 $stepsConfig = array_values($stepsConfig); foreach ($stepsConfig as $index => $stepConfig) { $steps[] = Step::createFromConfig($index + 1, $stepConfig); } return $steps; }
public function testCreateFromConfig_bcOptionType() { $step = Step::createFromConfig(1, array('type' => 'myFormType')); $this->assertEquals(array('Step config option "type" is deprecated since version 3.0. Use "form_type" instead.'), $this->getDeprecationNotices()); $this->assertEquals('myFormType', $step->getFormType()); }