mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #6928 from open-sausages/pulls/4.0/form-action-handler-regression
Process actions on Form subclasses
This commit is contained in:
commit
db3e3d51fd
@ -236,6 +236,11 @@ class FormRequestHandler extends RequestHandler
|
||||
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
|
||||
$field = $this->checkFieldsForAction($this->form->Fields(), $funcName);
|
||||
if ($field) {
|
||||
|
45
tests/php/Forms/FormRequestHandlerTest.php
Normal file
45
tests/php/Forms/FormRequestHandlerTest.php
Normal 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());
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
14
tests/php/Forms/FormRequestHandlerTest/TestForm.php
Normal file
14
tests/php/Forms/FormRequestHandlerTest/TestForm.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user