ENHANCEMENT Changing form ID to be unique

This commit is contained in:
3Dgoo 2017-04-18 10:41:32 +09:30 committed by Damian Mooyman
parent 2e73787088
commit ebbf9a727c
2 changed files with 11 additions and 10 deletions

View File

@ -459,7 +459,8 @@ class UserDefinedForm_Controller extends Page_Controller
*/ */
public function Form() public function Form()
{ {
$form = UserForm::create($this); $form = UserForm::create($this, 'Form_' . $this->ID);
$form->setFormAction(Controller::join_links($this->Link(), 'Form'));
$this->generateConditionalJavascript(); $this->generateConditionalJavascript();
return $form; return $form;
} }

View File

@ -23,7 +23,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$field = $this->objFromFixture('EditableTextField', 'basic-text'); $field = $this->objFromFixture('EditableTextField', 'basic-text');
$response = $this->submitForm('UserForm_Form', null, array($field->Name => 'Basic Value')); $response = $this->submitForm('UserForm_Form_' . $form->ID, null, array($field->Name => 'Basic Value'));
// should have a submitted form field now // should have a submitted form field now
$submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'"); $submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
@ -68,7 +68,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
// Post with no fields // Post with no fields
$this->get($form->URLSegment); $this->get($form->URLSegment);
$response = $this->submitForm('UserForm_Form', null, array()); $response = $this->submitForm('UserForm_Form_' . $form->ID, null, array());
$this->assertPartialMatchBySelector( $this->assertPartialMatchBySelector(
'.field .message', '.field .message',
array('This field is required') array('This field is required')
@ -76,7 +76,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
// Post with all fields, but invalid email // Post with all fields, but invalid email
$this->get($form->URLSegment); $this->get($form->URLSegment);
$this->submitForm('UserForm_Form', null, array( $this->submitForm('UserForm_Form_' . $form->ID, null, array(
'required-email' => 'invalid', 'required-email' => 'invalid',
'required-text' => 'bob' 'required-text' => 'bob'
)); ));
@ -87,7 +87,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
// Post with only required // Post with only required
$this->get($form->URLSegment); $this->get($form->URLSegment);
$this->submitForm('UserForm_Form', null, array( $this->submitForm('UserForm_Form_' . $form->ID, null, array(
'required-text' => 'bob' 'required-text' => 'bob'
)); ));
$this->assertPartialMatchBySelector( $this->assertPartialMatchBySelector(
@ -129,7 +129,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$controller = new UserDefinedFormControllerTest_Controller($form); $controller = new UserDefinedFormControllerTest_Controller($form);
// test form // test form
$this->assertEquals($controller->Form()->getName(), 'Form', 'The form is referenced as Form'); $this->assertEquals($controller->Form()->getName(), 'Form_' . $form->ID, 'The form is referenced as Form');
$this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields $this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
$this->assertEquals($controller->Form()->Actions()->Count(), 1); $this->assertEquals($controller->Form()->Actions()->Count(), 1);
$this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0); $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0);
@ -225,7 +225,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$index = new ArrayData($controller->index()); $index = new ArrayData($controller->index());
$parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest'))); $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
$this->checkTemplateIsCorrect($parser); $this->checkTemplateIsCorrect($parser, $form);
} }
public function testRenderingIntoTemplateWithSubstringReplacement() public function testRenderingIntoTemplateWithSubstringReplacement()
@ -238,7 +238,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$index = new ArrayData($controller->index()); $index = new ArrayData($controller->index());
$parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest'))); $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
$this->checkTemplateIsCorrect($parser); $this->checkTemplateIsCorrect($parser, $form);
} }
/** /**
* Publish a form for use on the frontend * Publish a form for use on the frontend
@ -259,9 +259,9 @@ class UserDefinedFormControllerTest extends FunctionalTest
return $form; return $form;
} }
public function checkTemplateIsCorrect($parser) public function checkTemplateIsCorrect($parser, $form)
{ {
$this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form')); $this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID));
// check for the input // check for the input
$this->assertArrayHasKey(0, $parser->getBySelector('input.text')); $this->assertArrayHasKey(0, $parser->getBySelector('input.text'));