예제 #1
0
 public function testValue()
 {
     $form = new Miao_Form('test-select');
     $form->addSelect('users', array(), array('root', 'guest', 'editor'));
     $form->load(array('users' => '2'));
     $actual = array('users' => '2');
     $expected = $form->getValues();
     $this->assertEquals($expected, $actual);
 }
예제 #2
0
 public function isValid($run = false)
 {
     if ($run) {
         $request = Miao_Office_Request::getInstance();
         $data = $request->getVars();
         $this->_isValid = $this->_form->isValid($data);
     }
     return $this->_isValid;
 }
예제 #3
0
 public function providerTestForm()
 {
     $data = array();
     $form = new Miao_Form('frm_test');
     $attributes = array();
     $title = new Miao_Form_Control_Text('title', $attributes);
     $url = new Miao_Form_Control_Text('url', $attributes);
     $form->addGroup('group', array($title, $url));
     $data[] = array($form, '1.html');
     return $data;
 }
예제 #4
0
 protected function _init()
 {
     $this->_generateFid();
     $this->_load();
     $this->_clear();
     if (is_null($this->_form)) {
         $this->_form = $this->buildForm();
         $this->_save();
     } else {
         if ($this->isRedirect()) {
             $this->_isRedirect = false;
             $this->_isValid = $this->_form->isValid();
             if ($this->_isValid) {
                 $this->_form->clearValue();
             }
             $this->_clear();
         } else {
             $request = Miao_Office_Request::getInstance();
             if ('POST' === $request->getMethod()) {
                 $data = $request->getVars();
                 $this->_isValid = $this->_form->isValid($data);
             }
             $this->_save();
         }
     }
 }
예제 #5
0
 protected function __construct()
 {
     $this->_generateFid();
     $session = Miao_Session::getInstance();
     $form = $session->loadObject($this->_fid, null, true);
     $session->saveObject($this->_fid, null);
     if (is_null($form)) {
         $this->_form = $this->buildForm();
     } else {
         $this->_form = $form;
         $this->_isRedirect = true;
         $request = Miao_Office_Request::getInstance();
         $data = $request->getVars();
         $this->_isValid = $this->_form->isValid($data);
     }
     $this->save();
 }
예제 #6
0
 public function providerTestLoad()
 {
     $data = array();
     $form = new Miao_Form('frm_test');
     $form->addText('name', array('class' => 'input-xlarge'));
     $postData = array('name' => 'Mister Smit');
     $actual = '<input name="name" value="Mister Smit" type="text" class="input-xlarge" />';
     $data[] = array($form, $postData, $actual);
     $form = new Miao_Form('frm_test');
     $form->addText('name[1]', array('class' => 'input-xlarge'));
     $postData = array('name' => array(1 => 'Mister Smit'));
     $actual = '<input name="name[1]" value="Mister Smit" type="text" class="input-xlarge" />';
     $data[] = array($form, $postData, $actual);
     $form = new Miao_Form('frm_test');
     $form->addText('name[1][2]', array('class' => 'input-xlarge'));
     $postData = array('name' => array(1 => array(2 => 'Mister Smit')));
     $actual = '<input name="name[1][2]" value="Mister Smit" type="text" class="input-xlarge" />';
     $data[] = array($form, $postData, $actual);
     return $data;
 }
예제 #7
0
 /**
  * @dataProvider providerTestGetHtmlName
  */
 public function testGetHtmlName($data, $actual, $exceptionName = '')
 {
     if (!empty($exceptionName)) {
         $this->setExpectedException($exceptionName);
     }
     $expected = Miao_Form::getHtmlName($data);
     $this->assertEquals($expected, $actual);
 }
예제 #8
0
 public function testFormAndList()
 {
     $form = new Miao_Form('frm_form');
     $name = 'name';
     $attributes = array();
     $control = new Miao_Form_Control_Text($name, $attributes);
     $list = new Miao_Form_Control_List($control);
     $form->addControl($list);
     $form->load(array('name' => array('a', 'b')));
     $expected = $form->name->render();
     $actual = '<input name="name[]" value="a" type="text" /><input name="name[]" value="b" type="text" />';
     $this->assertEquals($expected, $actual);
 }