Пример #1
0
 public function testWizardBehaviour()
 {
     $formOne = $this->getMock('HTML_QuickForm2', array('validate'), array('one'));
     $formOne->expects($this->exactly(2))->method('validate')->will($this->onConsecutiveCalls(false, true));
     $formTwo = $this->getMock('HTML_QuickForm2', array('validate'), array('two'));
     $formTwo->expects($this->exactly(2))->method('validate')->will($this->returnValue(true));
     $mockJumpOne = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJumpOne->expects($this->any())->method('perform')->will($this->returnValue('jump to page one'));
     $mockJumpTwo = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJumpTwo->expects($this->any())->method('perform')->will($this->returnValue('jump to page two'));
     $mockProcess = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockProcess->expects($this->any())->method('perform')->will($this->returnValue('do processing'));
     $mockDisplay = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockDisplay->expects($this->any())->method('perform')->will($this->returnValue('output form'));
     $pageOne = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formOne));
     $pageOne->addHandler('display', $mockDisplay);
     $pageOne->addHandler('jump', $mockJumpOne);
     $pageTwo = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formTwo));
     $pageTwo->addHandler('jump', $mockJumpTwo);
     $pageTwo->addHandler('process', $mockProcess);
     $controller = new HTML_QuickForm2_Controller('wizard_next', true);
     $controller->addPage($pageOne);
     $controller->addPage($pageTwo);
     $this->assertEquals('output form', $pageOne->handle('next'));
     $this->assertEquals('jump to page two', $pageOne->handle('next'));
     $this->assertEquals('do processing', $pageTwo->handle('next'));
     $controller->getSessionContainer()->storeValidationStatus('one', false);
     $this->assertEquals('jump to page one', $pageTwo->handle('next'));
 }
 public function testPerform()
 {
     $source = $this->getMock('HTML_QuickForm2', array('validate', 'getValue'), array('source'));
     $source->expects($this->once())->method('validate')->will($this->returnValue(true));
     $source->expects($this->once())->method('getValue')->will($this->returnValue(array('foo' => 'bar')));
     $sourcePage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($source));
     $sourcePage->addHandler('destination', new HTML_QuickForm2_Controller_Action_Direct());
     $destPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('destination')));
     $mockJump = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJump->expects($this->once())->method('perform')->will($this->returnValue('jump to destination'));
     $destPage->addHandler('jump', $mockJump);
     $controller = new HTML_QuickForm2_Controller('testDirectAction');
     $controller->addPage($sourcePage);
     $controller->addPage($destPage);
     $this->assertEquals('jump to destination', $sourcePage->handle('destination'));
     $this->assertTrue($controller->getSessionContainer()->getValidationStatus('source'));
     $this->assertEquals(array('foo' => 'bar'), $controller->getSessionContainer()->getValues('source'));
 }
Пример #3
0
 public function testNoValidationForWizards()
 {
     $mockForm = $this->getMock('HTML_QuickForm2', array('validate'), array('eternallyValid'));
     $mockForm->expects($this->once())->method('validate')->will($this->returnValue(true));
     $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockForm));
     $mockPage->addHandler('jump', $this->getMock('HTML_QuickForm2_Controller_Action', array('perform')));
     $wizard = new HTML_QuickForm2_Controller('wizard', true);
     $wizard->addPage($mockPage);
     $mockPage->handle('back');
     $this->assertNull($wizard->getSessionContainer()->getValidationStatus('eternallyValid'));
     $nonWizard = new HTML_QuickForm2_Controller('nonWizard', false);
     $nonWizard->addPage($mockPage);
     $mockPage->handle('back');
     $this->assertTrue($nonWizard->getSessionContainer()->getValidationStatus('eternallyValid'));
 }
 public function testNoLoadFromSessionContainerOnOtherActions()
 {
     $mockForm = $this->getMock('HTML_QuickForm2', array('validate'), array('noload'));
     $foo = $mockForm->addElement('text', 'foo');
     $mockForm->expects($this->never())->method('validate');
     $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockForm));
     $mockDisplay = $this->getMock('HTML_QuickForm2_Controller_Action_Display', array('renderForm'));
     $mockDisplay->expects($this->once())->method('renderForm')->will($this->returnValue('a form'));
     $mockPage->addHandler('display', $mockDisplay);
     $_REQUEST = array($mockPage->getButtonName('submit') => 'Yes, submit!');
     $controller = new HTML_QuickForm2_Controller('noLoadValues');
     $controller->addPage($mockPage);
     $controller->getSessionContainer()->storeValues('noload', array('foo' => 'bar'));
     $controller->getSessionContainer()->storeValidationStatus('noload', false);
     $controller->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => 'quux')));
     $this->assertEquals('a form', $mockPage->handle('display'));
     $this->assertEquals('quux', $foo->getValue());
 }
 public function testRedirectToInvalidPage()
 {
     $pageFirst = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('first')));
     $formSecond = $this->getMock('HTML_QuickForm2', array('validate'), array('second'));
     $formSecond->expects($this->once())->method('validate')->will($this->returnValue(true));
     $pageSecond = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formSecond));
     $mockJump = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJump->expects($this->once())->method('perform')->will($this->returnValue('jump to first'));
     $pageFirst->addHandler('jump', $mockJump);
     $controller = new HTML_QuickForm2_Controller('redirect_invalid', false);
     $controller->addPage($pageFirst);
     $controller->addPage($pageSecond);
     $controller->getSessionContainer()->storeValidationStatus('first', false);
     $this->assertEquals('jump to first', $pageSecond->handle('submit'));
 }
 public function testIsValidNotVisited()
 {
     $controller = new HTML_QuickForm2_Controller('isValidUnseen', false);
     $controller->addPage($this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('seen'))));
     $mockUnseen = $this->getMock('HTML_QuickForm2', array('validate', 'getValue'), array('unseen'));
     $mockUnseen->expects($this->once())->method('validate')->will($this->returnValue(true));
     $mockUnseen->expects($this->once())->method('getValue')->will($this->returnValue(array('foo' => 'bar')));
     $controller->addPage($this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockUnseen)));
     $controller->getSessionContainer()->storeValidationStatus('seen', true);
     $this->assertTrue($controller->isValid());
 }