コード例 #1
0
ファイル: WizardStepTest.php プロジェクト: gridguyz/core
 /**
  * Test methods
  */
 public function testMethods()
 {
     $form = new Form();
     $step = new WizardStep();
     $step->setStepForm($form);
     $this->assertSame($form, $step->getStepForm());
     $step->setTextDomain('exampleTextDomain');
     $this->assertSame('exampleTextDomain', $step->getTextDomain());
     $step->setDescriptionPartial('exampleDescriptionPartial');
     $this->assertSame('exampleDescriptionPartial', $step->getDescriptionPartial());
     $this->assertFalse($step->canFinishWizard());
     $this->assertTrue($step->canCancelWizard());
     $this->assertFalse($step->canSkip());
     $step->setOption('finish', true);
     $step->setOption('cancel', false);
     $step->setOption('skip', true);
     $this->assertTrue($step->canFinishWizard());
     $this->assertFalse($step->canCancelWizard());
     $this->assertTrue($step->canSkip());
     $this->assertFalse($step->hasPreviousStep());
     $step->setPreviousStep('examplePreviousStep');
     $this->assertSame('examplePreviousStep', $step->getPreviousStep());
     $this->assertTrue($step->hasPreviousStep());
     $this->assertFalse($step->hasNextStep());
     $step->setNextStep('exampleNextStep');
     $this->assertSame('exampleNextStep', $step->getNextStep());
     $this->assertTrue($step->hasNextStep());
 }
コード例 #2
0
 /**
  * Run a single step (which is not finish or cancel)
  *
  * @param   string      $step
  * @param   WizardStep  $model
  * @return  string|null the step to redirect to
  */
 protected function runStep($step, WizardStep $model = null)
 {
     $request = $this->getRequest();
     $isValid = false;
     $isPost = $request->isPost();
     $isCancel = $isPost && $request->getPost('cancel');
     $isPrevious = $isPost && $request->getPost('previous');
     $isNext = $isPost && $request->getPost('next');
     $isFinish = $isPost && $request->getPost('finish');
     $jumpTo = $request->getQuery('jump');
     $values = $this->getStepStore($step);
     $form = $model ? $model->getStepForm() : null;
     $redirect = null;
     if (!empty($model) && $model->canSkip()) {
         $this->setStepStore($step, array());
         $this->pushStepStack($step);
         $redirect = $model->getNextStep();
     } else {
         if (empty($model) || empty($form)) {
             $redirect = $this->startStep;
         } else {
             if (!empty($values)) {
                 $form->setData($values);
             }
             if ($isPost && ($isNext || $isFinish)) {
                 $form->setData($request->getPost());
                 $isValid = $form->isValid();
             }
             if ($isNext && $isValid && ($redirect = $model->getNextStep())) {
                 $this->setStepStore($step, $form->getData());
                 $this->pushStepStack($step);
             } else {
                 if ($isPrevious && ($redirect = $model->getPreviousStep())) {
                     $top = $this->topStepStack();
                     if ($redirect == $top) {
                         $this->popStepStack();
                     }
                 } else {
                     if ($jumpTo) {
                         $store = $this->getStore();
                         while (!empty($store['stack']) && $jumpTo != $this->popStepStack()) {
                         }
                         $redirect = empty($store['stack']) ? $this->startStep : $jumpTo;
                     } else {
                         if ($isFinish && $isValid && $model->canFinishWizard()) {
                             $this->setStepStore($step, $form->getData());
                             $this->pushStepStack($step);
                             $redirect = self::STEP_FINISH;
                         } else {
                             if ($isCancel && $model->canCancelWizard()) {
                                 $redirect = self::STEP_CANCEL;
                             }
                         }
                     }
                 }
             }
         }
     }
     /* if ( $redirect && $redirect != $step )
        {
            if ( ! $this->stepping( $step, $redirect ) )
            {
                $redirect = null;
            }
        } */
     return $redirect;
 }