/**
  * @group 7121
  */
 public function test_normalized_value_int()
 {
     $form = new EE_Form_Section_Proper(array('name' => 'test', 'subsections' => array('use_captcha' => new EE_Radio_Button_Input(array(1 => __('Yes', 'event_espresso'), 0 => __('No', 'event_espresso')), array('html_label_text' => __('Use reCAPTCHA', 'event_espresso'), 'default' => isset(EE_Registry::instance()->CFG->registration->use_captcha) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE, 'normalization_strategy' => new EE_Int_Normalization())))));
     $form->receive_form_submission(array('test' => array('use_captcha' => '1')));
     $this->assertTrue($form->is_valid());
     $this->assertTrue(1 === $form->get_input('use_captcha')->normalized_value());
     $this->assertTrue('1' === $form->get_input('use_captcha')->raw_value());
     $form->receive_form_submission(array('test' => array('use_captcha' => '0')));
     $this->assertTrue($form->is_valid());
     $this->assertTrue(0 === $form->get_input('use_captcha')->normalized_value());
     $this->assertTrue('0' === $form->get_input('use_captcha')->raw_value());
 }
 function test_many_valued()
 {
     //create a form with radio button in it.
     $form = new EE_Form_Section_Proper(array('name' => 'test1', 'subsections' => array('checkbox1' => new EE_Checkbox_Multi_Input(array('option1' => 'Option 1', 'option2' => 'Option 2')))));
     $checkbox = $form->get_input('checkbox1');
     //that radio button's normalization strategy is correct
     $this->assertInstanceOf('EE_Checkbox_Multi_Input', $checkbox);
     $this->assertInstanceOf('EE_Many_Valued_Normalization', $checkbox->get_normalization_strategy());
     //and that when it receives input, it sets it correctly
     $form->receive_form_submission(array('checkbox1' => array('option1')));
     $this->assertTrue($form->is_valid());
     $form->receive_form_submission(array('checkbox1' => array('option_nonexistent')));
     $this->assertFalse($form->is_valid());
     $form->receive_form_submission(array('checkbox1' => 'option1'));
     $this->assertTrue($form->is_valid());
     $form->receive_form_submission(array('checkbox1' => 'option_nonexistent'));
     $this->assertFalse($form->is_valid());
 }
 /**
  * @group 6781
  */
 public function test_get_validation_errors_accumulated()
 {
     $form = new EE_Form_Section_Proper(array('name' => 'Form', 'subsections' => array('radio1' => new EE_Radio_Button_Input(array('one' => 'One', 'two' => 'Two', 'three' => 'Three'), array('html_class' => 'spco-payment-method', 'default' => 'three')), 'input2' => new EE_Text_Input(array('required' => TRUE)), 'subsubsection' => new EE_Form_Section_Proper(array('subsections' => array('input3' => new EE_Float_Input(), 'input4' => new EE_Text_Input()))))));
     $post_data = array('Form' => array('radio1' => 'four-invalid', 'input2' => '', 'subsubsection' => array('input3' => 'non-number', 'input4' => 'whatever-ok')));
     $form->receive_form_submission($post_data);
     //submit twice, which should be fine; it shoudl jsut reset before
     //2nd submission
     $form->receive_form_submission($post_data);
     $this->assertFalse($form->is_valid());
     $all_errors = $form->get_validation_errors_accumulated();
     $this->assertEquals(3, count($all_errors));
     $error1 = array_shift($all_errors);
     $error2 = array_shift($all_errors);
     $error3 = array_shift($all_errors);
     $this->assertInstanceOf('EE_Validation_Error', $error1);
     $this->assertInstanceOf('EE_Radio_Button_Input', $error1->get_form_section());
     $this->assertEquals('radio1', $error1->get_form_section()->name());
     $this->assertInstanceOf('EE_Validation_Error', $error2);
     $this->assertInstanceOf('EE_Text_Input', $error2->get_form_section());
     $this->assertEquals('input2', $error2->get_form_section()->name());
     $this->assertInstanceOf('EE_Validation_Error', $error3);
     $this->assertInstanceOf('EE_Float_Input', $error3->get_form_section());
     $this->assertEquals('input3', $error3->get_form_section()->name());
 }
 /**
  * After the form section is initially created, call this to sanitize the data in the submission
  * which relates to this form section, validate it, and set it as properties on the form.
  * @param array $req_data should usually be $_REQUEST (the default). However, you CAN
  * supply a different array. Consider using set_defaults() instead however. (If you rendered
  * the form in the page using echo $form_x->get_html() the inputs will have the correct name
  * in the request data for this function to find them and populate the form with them.
  * If you have a flat form (with only input subsections), you can supply a flat array where keys
  * are the form input names and values are their values)
  * @param boolean $validate whether or not to perform validation on this data. Default is,
  * of course, to validate that data, and set errors on the invalid values. But if the data
  * has already been validated (eg you validated the data then stored it in the DB) you may want
  * to skip this step.
  * @return void
  */
 public function receive_form_submission($req_data = NULL, $validate = TRUE)
 {
     parent::receive_form_submission($req_data, $validate);
     //create or set the model object, if it isn't already
     if (!$this->_model_object) {
         //check to see if the form indicates a PK, in which case we want to only retrieve it and update it
         $pk_name = $this->_model->primary_key_name();
         $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
         if ($model_obj) {
             $this->_model_object = $model_obj;
         } else {
             $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
         }
     }
     //ok so the model object is set. Just set it with the submitted form data (don't save yet though)
     foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
         //only set the non-primary key
         if ($field_name != $this->_model->primary_key_name()) {
             $this->_model_object->set($field_name, $field_value);
         }
     }
 }