Example #1
0
 public function testFormValidatorEntityBindSetters()
 {
     //Second element
     $address = new Text('address');
     $address->addValidator(new PresenceOf(array('message' => 'The address is required')));
     $telephone = new Text("telephone");
     $telephone->addValidator(new PresenceOf(array('message' => 'The telephone is required')));
     $entity = new ContactFormSettersGetters();
     $form = new Form();
     $form->add($address);
     $form->add($telephone);
     $form->bind(array('telephone' => '+44 123 45678', 'address' => 'hello'), $entity);
     $this->assertTrue($form->isValid());
     $this->assertEquals($entity->getTelephone(), '+44 123 45678');
     $this->assertEquals($entity->getAddress(), 'hello');
 }
Example #2
0
 /**
  * Overwrite bind function
  *
  * @param array $data
  * @param object $entity
  * @param array $whiteList
  * @return Form
  */
 public function bind(array $data, $entity, $whiteList = null)
 {
     if ($this->_titleColumn != '') {
         $data = $this->repaidSEOData($data);
         unset($data['zcms_seo_title']);
         unset($data['zcms_meta_robot_advance']);
         unset($data['zcms_meta_robot_follow']);
         unset($data['zcms_meta_robot_index']);
         unset($data['zcms_metadata']);
         unset($data['zcms_redirect_301']);
     }
     return parent::bind($data, $entity, $whiteList);
 }
Example #3
0
 /**
  * Bind also an array values.
  *
  * @param array $data
  * @param object $entity
  * @param array $whitelist
  */
 public function bind(array $data, $entity, $whitelist = null)
 {
     parent::bind($data, $entity, $whitelist);
     $this->bindArrays($data, $entity, $whitelist);
 }
Example #4
0
 /**
  * Tests clearing the Form Elements by using Form::bind
  *
  * @issue  11978
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-10-01
  * @param  IntegrationTester $I
  */
 public function clearFormElementsByUsingFormBind(IntegrationTester $I)
 {
     $name = new Text('sel_name');
     $text = new Text('sel_text');
     $form = new Form();
     $form->add($name)->add($text);
     $entity = new MvcModel();
     $I->assertNull(Tag::getValue('sel_name'));
     $I->assertNull($form->getValue('sel_name'));
     $I->assertNull($form->get('sel_name')->getValue());
     $I->assertNull($name->getValue());
     Tag::setDefault('sel_name', 'Please specify name');
     $_POST = ['sel_name' => 'Some Name', 'sel_text' => 'Some Text'];
     $form->bind($_POST, $entity);
     $I->assertEquals('Some Name', $entity->getName());
     $I->assertEquals('Some Text', $entity->getText());
     $I->assertEquals('Some Name', $form->getValue('sel_name'));
     $I->assertEquals('Some Name', $form->get('sel_name')->getValue());
     $I->assertEquals('Some Name', $name->getValue());
     $I->assertEquals('Some Text', $form->getValue('sel_text'));
     $I->assertEquals('Some Text', $form->get('sel_text')->getValue());
     $I->assertEquals('Some Text', $text->getValue());
     $form->clear(['sel_name']);
     $I->assertNull(Tag::getValue('sel_name'));
     $I->assertNull($form->getValue('sel_name'));
     $I->assertNull($form->get('sel_name')->getValue());
     $I->assertNull($name->getValue());
     $I->assertEquals('Some Text', $form->getValue('sel_text'));
     $I->assertEquals('Some Text', $form->get('sel_text')->getValue());
     $I->assertEquals('Some Text', $text->getValue());
     $form->clear(['non_existent', 'another_filed']);
     $I->assertEquals('Some Text', $form->getValue('sel_text'));
     $I->assertEquals('Some Text', $form->get('sel_text')->getValue());
     $I->assertEquals('Some Text', $text->getValue());
     $form->clear();
     $I->assertNull(Tag::getValue('sel_text'));
     $I->assertNull($form->getValue('sel_text'));
     $I->assertNull($form->get('sel_text')->getValue());
     $I->assertNull($text->getValue());
     $I->assertEquals('Some Name', $entity->getName());
     $I->assertEquals('Some Text', $entity->getText());
     $I->assertEquals(['sel_name' => 'Some Name', 'sel_text' => 'Some Text'], $_POST);
 }