public function test_set_values_form() { $input3 = $this->mockInputText('name3'); $input2 = $this->mockInputText('name2'); $input1 = $this->mockInputText('name1'); $input3->expects($this->once())->method('setValue'); $form = new Form(); $form->addInput($input3); $aValues = array('name3' => 'value 3 du formulaire'); $form->setValues($aValues); $form_html = $form->getDisplay(); }
/** * génère un formulaire prêt à l'emploi en fonction du tableau envoyé. * * Le tableau doit être de la forme : * * * array( * array( * 'type' => 'Form\Input\Text\Text', * 'id' => 'test_id', * 'label' => 'label de mon champs', * 'desc' => 'description de mon champs' * ), * array( * [...] * ) * ) * */ private function generateForm($post = null) { $form = new Form(); $form->addInput(new Nonce()); $this->formInstance = $form; foreach ($this->fields as $field) { // get value of this field if it exists for this post if (isset($post)) { $value = get_post_meta($post->ID, $field['id'], true); } $class_input = $field['type']; $field_id = $field['id']; $args = array('label' => $field['label'], 'desc' => $field['desc'], 'wysiwyg' => $field['wysiwyg'], 'content_type' => $this->content_type); if (isset($field['choices'])) { $args['choices'] = $field['choices']; } $input = new $class_input($field_id, $value, $field_id, $args); $this->formInstance->addInput($input); } }