Example #1
0
 /**
  * {@inheritDoc}
  */
 public function getForm()
 {
     $currentStep = $this->getCurrentStep();
     if (!$currentStep) {
         return;
     }
     if (null === $this->form) {
         $this->form = $this->formFactory->create();
         $this->form->setAttribute('action', sprintf('?%s=%s', $this->getOptions()->getTokenParamName(), $this->getUniqueId()));
         if (!$this->getSteps()->getPrevious($currentStep)) {
             $this->form->remove('previous');
         }
         if (!$this->getSteps()->getNext($currentStep)) {
             $this->form->remove('next');
         } else {
             $this->form->remove('valid');
         }
     }
     $stepForm = $currentStep->getForm();
     if ($stepForm instanceof Form) {
         if ($this->form->has(self::STEP_FORM_NAME)) {
             $this->form->remove(self::STEP_FORM_NAME);
         }
         $stepForm->setName(self::STEP_FORM_NAME);
         $stepForm->populateValues($currentStep->getData());
         $this->form->add($stepForm);
     }
     return $this->form;
 }
Example #2
0
 public function testCreateForm()
 {
     $formFactory = new FormFactory();
     $previousButton = new ButtonElement\Previous('previous');
     $nextButton = new ButtonElement\Next('next');
     $validButton = new ButtonElement\Valid('valid');
     $cancelButton = new ButtonElement\Cancel('cancel');
     $returnValueMap = [['Wizard\\Form\\Element\\Button\\Previous', $previousButton], ['Wizard\\Form\\Element\\Button\\Next', $nextButton], ['Wizard\\Form\\Element\\Button\\Valid', $validButton], ['Wizard\\Form\\Element\\Button\\Cancel', $cancelButton]];
     $formElementManagerStub = $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface');
     $formElementManagerStub->expects($this->any())->method('get')->will($this->returnValueMap($returnValueMap));
     $serviceManagerStub = $this->getMock('Zend\\ServiceManager\\ServiceManager');
     $serviceManagerStub->method('get')->will($this->returnValue($formElementManagerStub));
     $formFactory->setServiceManager($serviceManagerStub);
     /* @var $form \Zend\Form\Form */
     $form = $formFactory->create();
     $this->assertInstanceOf('Zend\\Form\\Form', $form);
     $this->assertCount(4, $form->getElements());
 }