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()); }
/** * Default values for checkboxes and multiselects were ignored when validating an unseen page * * Unlikely that this bug will resurface, but just in case. * * @see http://pear.php.net/bugs/bug.php?id=8687 */ public function testBug8687() { $mockForm = $this->getMock('HTML_QuickForm2', array('validate'), array('invalid')); $mockForm->expects($this->once())->method('validate')->will($this->returnValue(false)); $select = $mockForm->addElement('select', 'foo', array('multiple'))->loadOptions(array('one' => 'First label', 'two' => 'Second label')); $box = $mockForm->addElement('checkbox', 'bar'); $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockForm)); $controller = new HTML_QuickForm2_Controller('bug8687', false); $controller->addPage($mockPage); $controller->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => array('two'), 'bar' => '1'))); $this->assertFalse($controller->isValid()); $this->assertEquals(array('two'), $select->getValue()); $this->assertEquals('1', $box->getValue()); }