public function testFormSubmit()
 {
     $new_field = magic_form_field_text::factory($this->input_default_name, $this->input_default_label);
     $this->magic_form->add_field($new_field);
     $this->magic_form->add_field(magic_form_field_submit::factory('submit', 'Submit'));
     // This is our submit handler.
     $this->magic_form->submit(function (magic_form $form) {
         require_once drupal_get_path("module", "devel") . "/krumo/class.krumo.php";
         krumo($form->get_fields());
         drupal_set_message("Submit happened in form {$form->magic_form_id} / {$form->form_id}");
     });
     $html = $this->magic_form->__toString();
     //Get HTML Dom
     $dom = str_get_html($html);
     $form = $dom->find("//form")[0];
     //Find Submit Button
     $test_submit_button = $form->find("button[name=submit]")[0];
     //Check Submit Button
     $this->assertEquals("submit", $test_submit_button->attr['id'], "Check ID Submit");
     $this->assertEquals("submit", $test_submit_button->attr['name'], "Check Name Submit");
 }
 public function testGroupInputRemoveFields()
 {
     $test_wrapper = magic_form_group::factory('Test Wrapper');
     //Create Text Input
     $new_field = magic_form_field_text::factory($this->input_default_name, $this->input_default_label);
     $new_field->set_attributes(array("testattribute" => "testattributevalue", "testattribute2" => "testattributevalue2"));
     $new_field2 = magic_form_field_text::factory($this->input_default_name . "_2", $this->input_default_label . "_2");
     $new_field2->set_attributes(array("testattribute" => "testattributevalue", "testattribute2" => "testattributevalue2"));
     $test_wrapper->add_fields($new_field, $new_field2);
     $test_wrapper->remove_fields($new_field, $new_field2);
     $json = $test_wrapper->__toJsonArray();
     $this->magic_form->add_field($test_wrapper);
     $html = $this->magic_form->__toString();
     //Get HTML Dom
     $dom = str_get_html($html);
     $form = $dom->find("//form")[0];
     //Find Form Group
     $test_group_field = $form->find("div[class=field-test-wrapper]")[0];
     //Check Group Field
     $this->assertContains("form-group", $test_group_field->attr['class'], "Type Contains Form Group");
     //Check Group Label
     $test_group_h3 = $test_group_field->find("h3")[0];
     $this->assertEquals("Test Wrapper", $test_group_h3->innertext(), "Check Label");
 }
 public function testTextSetValue()
 {
     //Create Text Input
     $new_field = magic_form_field_text::factory($this->input_default_name, $this->input_default_label, 'testsetdefaultvalue');
     $new_field->set_value('testsetvalue');
     $this->magic_form->add_field($new_field);
     $html = $this->magic_form->__toString();
     //Get HTML Dom
     $dom = str_get_html($html);
     $form = $dom->find("//form")[0];
     //Find Text Input
     $test_text_field = $form->find("input[name=test_text_field]")[0];
     //Check Value
     $this->assertContains('testsetvalue', $test_text_field->attr['value'], "Check Set Value");
 }