-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6928 from open-sausages/pulls/4.0/form-action-han…
…dler-regression Process actions on Form subclasses
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/php/Forms/FormRequestHandlerTest/FormRequestHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |