silverstripe-framework/tests/php/Forms/FormRequestHandlerTest.php
Ingo Schommer adbf9d9f71 Process actions on Form subclasses
Regression introduced through https://github.com/silverstripe/silverstripe-framework/issues/6362.

Quote from the RFC:

```
Thus the order of action precedence becomes

action callback
action on the Form
action on the FormRequestHandler
action on any parent controller (if given)
```
2017-05-18 22:47:39 +12:00

46 lines
1.5 KiB
PHP

<?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());
}
}