Merge pull request #737 from creative-commoners/pulls/5.0/fix-cwp-compat

FIX getFormParent does not automatically look up arbitrary test stubs, remove theme dependency
This commit is contained in:
Dylan Wagstaff 2018-03-20 10:33:17 +13:00 committed by GitHub
commit e041c4805f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View File

@ -128,17 +128,24 @@ class EmailRecipient extends DataObject
/** /**
* Get instance of UserForm when editing in getCMSFields * Get instance of UserForm when editing in getCMSFields
* *
* @return UserDefinedForm|UserForm * @return UserDefinedForm|UserForm|null
*/ */
protected function getFormParent() 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. // LeftAndMain::sessionNamespace is protected. @todo replace this with a non-deprecated equivalent.
$sessionNamespace = $this->config()->get('session_namespace') ?: CMSMain::class; $sessionNamespace = $this->config()->get('session_namespace') ?: CMSMain::class;
$formID = $this->FormID ?: Controller::curr()->getRequest()->getSession()->get($sessionNamespace . '.currentPage'); $formID = Controller::curr()->getRequest()->getSession()->get($sessionNamespace . '.currentPage');
$formClass = $this->FormClass ?: UserDefinedForm::class; if ($formID) {
return UserDefinedForm::get()->byID($formID);
return $formClass::get()->byID($formID); }
} }
public function getTitle() public function getTitle()

View File

@ -2,6 +2,7 @@
namespace SilverStripe\UserForms\Tests\Control; namespace SilverStripe\UserForms\Tests\Control;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\CSSContentParser; use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
@ -104,32 +105,26 @@ class UserDefinedFormControllerTest extends FunctionalTest
// Post with no fields // Post with no fields
$this->get($form->URLSegment); $this->get($form->URLSegment);
/** @var HTTPResponse $response */
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, []); $response = $this->submitForm('UserForm_Form_' . $form->ID, null, []);
$this->assertPartialMatchBySelector( $this->assertContains('This field is required', $response->getBody());
'.field .message',
['This field is required']
);
// 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_' . $form->ID, null, [ /** @var HTTPResponse $response */
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [
'required-email' => 'invalid', 'required-email' => 'invalid',
'required-text' => 'bob' 'required-text' => 'bob'
]); ]);
$this->assertPartialMatchBySelector( $this->assertContains('Please enter an email address', $response->getBody());
'.field .message',
['Please enter an email address']
);
// Post with only required // Post with only required
$this->get($form->URLSegment); $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' 'required-text' => 'bob'
]); ]);
$this->assertPartialMatchBySelector( $this->assertContains("Thanks, we've received your submission.", $response->getBody());
'p',
["Thanks, we've received your submission."]
);
} }
public function testFinished() public function testFinished()

View File

@ -111,6 +111,7 @@ class UserDefinedFormTest extends FunctionalTest
$popup = new EmailRecipient(); $popup = new EmailRecipient();
$popup->FormID = $form->ID; $popup->FormID = $form->ID;
$popup->FormClass = UserDefinedForm::class;
$fields = $popup->getCMSFields(); $fields = $popup->getCMSFields();
@ -167,6 +168,7 @@ class UserDefinedFormTest extends FunctionalTest
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page'); $page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$recipient = new EmailRecipient(); $recipient = new EmailRecipient();
$recipient->FormID = $page->ID; $recipient->FormID = $page->ID;
$recipient->FormClass = UserDefinedForm::class;
$result = $recipient->getEmailTemplateDropdownValues(); $result = $recipient->getEmailTemplateDropdownValues();
@ -180,6 +182,7 @@ class UserDefinedFormTest extends FunctionalTest
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page'); $page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$recipient = new EmailRecipient(); $recipient = new EmailRecipient();
$recipient->FormID = $page->ID; $recipient->FormID = $page->ID;
$recipient->FormClass = UserDefinedForm::class;
// Set the default template // Set the default template
$recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues())); $recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues()));