mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX getFormParent does not automatically look up arbitrary test stubs, remove theme dependency
This commit is contained in:
parent
9403ee2cc1
commit
d19914044a
@ -128,17 +128,24 @@ class EmailRecipient extends DataObject
|
||||
/**
|
||||
* Get instance of UserForm when editing in getCMSFields
|
||||
*
|
||||
* @return UserDefinedForm|UserForm
|
||||
* @return UserDefinedForm|UserForm|null
|
||||
*/
|
||||
protected function getFormParent()
|
||||
{
|
||||
// If polymorphic relationship is actually defined, use it
|
||||
if ($this->FormID && $this->FormClass) {
|
||||
$formClass = $this->FormClass;
|
||||
return $formClass::get()->byID($this->FormID);
|
||||
}
|
||||
|
||||
// Revert to checking for a form from the session
|
||||
// LeftAndMain::sessionNamespace is protected. @todo replace this with a non-deprecated equivalent.
|
||||
$sessionNamespace = $this->config()->get('session_namespace') ?: CMSMain::class;
|
||||
|
||||
$formID = $this->FormID ?: Controller::curr()->getRequest()->getSession()->get($sessionNamespace . '.currentPage');
|
||||
$formClass = $this->FormClass ?: UserDefinedForm::class;
|
||||
|
||||
return $formClass::get()->byID($formID);
|
||||
$formID = Controller::curr()->getRequest()->getSession()->get($sessionNamespace . '.currentPage');
|
||||
if ($formID) {
|
||||
return UserDefinedForm::get()->byID($formID);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Control;
|
||||
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
@ -104,32 +105,26 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
||||
|
||||
// Post with no fields
|
||||
$this->get($form->URLSegment);
|
||||
/** @var HTTPResponse $response */
|
||||
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, []);
|
||||
$this->assertPartialMatchBySelector(
|
||||
'.field .message',
|
||||
['This field is required']
|
||||
);
|
||||
$this->assertContains('This field is required', $response->getBody());
|
||||
|
||||
// Post with all fields, but invalid email
|
||||
$this->get($form->URLSegment);
|
||||
$this->submitForm('UserForm_Form_' . $form->ID, null, [
|
||||
/** @var HTTPResponse $response */
|
||||
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [
|
||||
'required-email' => 'invalid',
|
||||
'required-text' => 'bob'
|
||||
]);
|
||||
$this->assertPartialMatchBySelector(
|
||||
'.field .message',
|
||||
['Please enter an email address']
|
||||
);
|
||||
$this->assertContains('Please enter an email address', $response->getBody());
|
||||
|
||||
// Post with only required
|
||||
$this->get($form->URLSegment);
|
||||
$this->submitForm('UserForm_Form_' . $form->ID, null, [
|
||||
/** @var HTTPResponse $response */
|
||||
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [
|
||||
'required-text' => 'bob'
|
||||
]);
|
||||
$this->assertPartialMatchBySelector(
|
||||
'p',
|
||||
["Thanks, we've received your submission."]
|
||||
);
|
||||
$this->assertContains("Thanks, we've received your submission.", $response->getBody());
|
||||
}
|
||||
|
||||
public function testFinished()
|
||||
|
@ -111,6 +111,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
|
||||
$popup = new EmailRecipient();
|
||||
$popup->FormID = $form->ID;
|
||||
$popup->FormClass = UserDefinedForm::class;
|
||||
|
||||
$fields = $popup->getCMSFields();
|
||||
|
||||
@ -167,6 +168,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
|
||||
$recipient = new EmailRecipient();
|
||||
$recipient->FormID = $page->ID;
|
||||
$recipient->FormClass = UserDefinedForm::class;
|
||||
|
||||
$result = $recipient->getEmailTemplateDropdownValues();
|
||||
|
||||
@ -180,6 +182,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
|
||||
$recipient = new EmailRecipient();
|
||||
$recipient->FormID = $page->ID;
|
||||
$recipient->FormClass = UserDefinedForm::class;
|
||||
|
||||
// Set the default template
|
||||
$recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues()));
|
||||
|
Loading…
Reference in New Issue
Block a user