silverstripe-framework/tests/php/Forms/FormRequestHandlerTest.php
2017-07-03 12:21:47 +12:00

52 lines
1.6 KiB
PHP

<?php
namespace SilverStripe\Forms\Tests;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
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;
/**
* @skipUpgrade
*/
class FormRequestHandlerTest extends SapphireTest
{
public function testCallsActionOnFormHandler()
{
$form = new TestForm(
Controller::curr(),
'Form',
new FieldList(),
new FieldList(new FormAction('mySubmitOnFormHandler'))
);
$form->disableSecurityToken();
$handler = new TestFormRequestHandler($form);
$request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnFormHandler' => 1]);
$request->setSession(new Session([]));
$response = $handler->httpSubmission($request);
$this->assertFalse($response->isError());
}
public function testCallsActionOnForm()
{
$form = new TestForm(
Controller::curr(),
'Form',
new FieldList(),
new FieldList(new FormAction('mySubmitOnForm'))
);
$form->disableSecurityToken();
$handler = new FormRequestHandler($form);
$request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnForm' => 1]);
$request->setSession(new Session([]));
$response = $handler->httpSubmission($request);
$this->assertFalse($response->isError());
}
}