Merge pull request #6928 from open-sausages/pulls/4.0/form-action-handler-regression

Process actions on Form subclasses
This commit is contained in:
Daniel Hensby 2017-05-18 12:09:28 +01:00 committed by GitHub
commit db3e3d51fd
4 changed files with 78 additions and 0 deletions

View File

@ -236,6 +236,11 @@ class FormRequestHandler extends RequestHandler
return $this->$funcName($vars, $this->form, $request); return $this->$funcName($vars, $this->form, $request);
} }
// Otherwise, try a handler method on the form itself
if ($this->form->hasMethod($funcName)) {
return $this->form->$funcName($vars, $this->form, $request);
}
// Check for inline actions // Check for inline actions
$field = $this->checkFieldsForAction($this->form->Fields(), $funcName); $field = $this->checkFieldsForAction($this->form->Fields(), $funcName);
if ($field) { if ($field) {

View File

@ -0,0 +1,45 @@
<?php
namespace SilverStripe\Forms\Tests;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\FormRequestHandler;
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestForm;
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestFormRequestHandler;
class FormRequestHandlerTest extends SapphireTest
{
public function testCallsActionOnFormHandler()
{
$form = new TestForm(
new Controller(),
'Form',
new FieldList(),
new FieldList(new FormAction('mySubmitOnFormHandler'))
);
$form->disableSecurityToken();
$handler = new TestFormRequestHandler($form);
$request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnFormHandler' => 1]);
$response = $handler->httpSubmission($request);
$this->assertFalse($response->isError());
}
public function testCallsActionOnForm()
{
$form = new TestForm(
new Controller(),
'Form',
new FieldList(),
new FieldList(new FormAction('mySubmitOnForm'))
);
$form->disableSecurityToken();
$handler = new FormRequestHandler($form);
$request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnForm' => 1]);
$response = $handler->httpSubmission($request);
$this->assertFalse($response->isError());
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Forms\Tests\FormRequestHandlerTest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\FormRequestHandler;
class TestFormRequestHandler extends FormRequestHandler
{
public function mySubmitOnFormHandler()
{
return new HTTPResponse('success', 200);
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Forms\Tests\FormRequestHandlerTest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\Form;
class TestForm extends Form
{
public function mySubmitOnForm()
{
return new HTTPResponse('success', 200);
}
}