From a602ba5941286bc57934c9b60c2edbb150f03aed Mon Sep 17 00:00:00 2001 From: Frank Mullenger Date: Fri, 28 Sep 2012 12:02:13 +1200 Subject: [PATCH] BUGFIX: Old version of SimpleTest does not recognise input fields of type 'email'. --- tests/forms/EmailFieldTest.php | 63 +++++++++++++++++++++++++++++++++- thirdparty/simpletest/page.php | 1 + 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/forms/EmailFieldTest.php b/tests/forms/EmailFieldTest.php index 62ee7c8db..c5019b0bf 100644 --- a/tests/forms/EmailFieldTest.php +++ b/tests/forms/EmailFieldTest.php @@ -1,6 +1,6 @@ assertTrue(false, $checkText . ": " . $e->GetMessage() . " (/$email/ did not pass validation, but was expected to)"); } } + + /** + * Check that input type='email' fields are submitted by SimpleTest + * + * @see SimpleTagBuilder::_createInputTag() + */ + function testEmailFieldPopulation() { + + $this->get('EmailFieldTest_Controller'); + $this->submitForm('Form_Form', null, array( + 'Email' => 'test@test.com' + )); + + $this->assertPartialMatchBySelector('p.good',array( + 'Test save was successful' + )); + } } class EmailFieldTest_Validator extends Validator { @@ -49,3 +66,47 @@ class EmailFieldTest_Validator extends Validator { public function php($data) { } } + +class EmailFieldTest_Controller extends Controller implements TestOnly { + + static $url_handlers = array( + '$Action//$ID/$OtherID' => "handleAction", + ); + + protected $template = 'BlankPage'; + + function Link($action = null) { + return Controller::join_links('EmailFieldTest_Controller', $this->request->latestParam('Action'), $this->request->latestParam('ID'), $action); + } + + function Form() { + $form = new Form( + $this, + 'Form', + new FieldList( + new EmailField('Email') + ), + new FieldList( + new FormAction('doSubmit') + ), + new RequiredFields( + 'Email' + ) + ); + + // Disable CSRF protection for easier form submission handling + $form->disableSecurityToken(); + + return $form; + } + + function doSubmit($data, $form, $request) { + $form->sessionMessage('Test save was successful', 'good'); + return $this->redirectBack(); + } + + function getViewer($action = null) { + return new SSViewer('BlankPage'); + } + +} diff --git a/thirdparty/simpletest/page.php b/thirdparty/simpletest/page.php index 54b26acfd..add422371 100644 --- a/thirdparty/simpletest/page.php +++ b/thirdparty/simpletest/page.php @@ -86,6 +86,7 @@ class SimpleTagBuilder { 'checkbox' => 'SimpleCheckboxTag', 'radio' => 'SimpleRadioButtonTag', 'text' => 'SimpleTextTag', + 'email' => 'SimpleTextTag', 'hidden' => 'SimpleTextTag', 'password' => 'SimpleTextTag', 'file' => 'SimpleUploadTag');