Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
662bd393
Commit
662bd393
authored
Oct 29, 2013
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2120847
by tim.plunkett: Add test coverage for FormBuilder::sendResponse().
parent
482f4eb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
core/lib/Drupal/Core/Form/FormBuilder.php
core/lib/Drupal/Core/Form/FormBuilder.php
+2
-1
core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
+40
-1
No files found.
core/lib/Drupal/Core/Form/FormBuilder.php
View file @
662bd393
...
...
@@ -274,6 +274,7 @@ public function buildForm($form_id, &$form_state) {
// If the form returns some kind of response, deliver it.
if
(
$response
instanceof
Response
)
{
$this
->
sendResponse
(
$response
);
exit
;
}
// If this was a successful submission of a single-step form or the last step
...
...
@@ -572,6 +573,7 @@ public function retrieveForm($form_id, &$form_state) {
// If the form returns some kind of response, deliver it.
if
(
$form
instanceof
Response
)
{
$this
->
sendResponse
(
$form
);
exit
;
}
$form
[
'#form_id'
]
=
$form_id
;
...
...
@@ -1661,7 +1663,6 @@ protected function sendResponse(Response $response) {
->
prepare
(
$this
->
request
)
->
send
();
$this
->
httpKernel
->
terminate
(
$this
->
request
,
$response
);
exit
;
}
/**
...
...
core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
View file @
662bd393
...
...
@@ -14,6 +14,7 @@
use
Drupal\Tests\UnitTestCase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
/**
* Tests the form builder.
...
...
@@ -101,8 +102,11 @@ public function setUp() {
$this
->
csrfToken
=
$this
->
getMockBuilder
(
'Drupal\Core\Access\CsrfTokenGenerator'
)
->
disableOriginalConstructor
()
->
getMock
();
$http_kernel
=
$this
->
getMockBuilder
(
'Drupal\Core\HttpKernel'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
formBuilder
=
new
TestFormBuilder
(
$this
->
moduleHandler
,
$key_value_expirable_factory
,
$event_dispatcher
,
$this
->
urlGenerator
,
$translation_manager
,
$this
->
csrfToken
);
$this
->
formBuilder
=
new
TestFormBuilder
(
$this
->
moduleHandler
,
$key_value_expirable_factory
,
$event_dispatcher
,
$this
->
urlGenerator
,
$translation_manager
,
$this
->
csrfToken
,
$http_kernel
);
$this
->
formBuilder
->
setRequest
(
new
Request
());
$this
->
account
=
$this
->
getMock
(
'Drupal\Core\Session\AccountInterface'
);
...
...
@@ -475,6 +479,32 @@ public function testGetCache() {
$this
->
formBuilder
->
buildForm
(
$form_id
,
$form_state
);
}
/**
* Tests the sendResponse() method.
*
* @expectedException \Exception
*/
public
function
testSendResponse
()
{
$form_id
=
'test_form_id'
;
$expected_form
=
$this
->
getMockBuilder
(
'Symfony\Component\HttpFoundation\Response'
)
->
disableOriginalConstructor
()
->
getMock
();
$expected_form
->
expects
(
$this
->
once
())
->
method
(
'prepare'
)
->
will
(
$this
->
returnValue
(
$expected_form
));
$form_arg
=
$this
->
getMock
(
'Drupal\Core\Form\FormInterface'
);
$form_arg
->
expects
(
$this
->
any
())
->
method
(
'buildForm'
)
->
will
(
$this
->
returnValue
(
$expected_form
));
// Do an initial build of the form and track the build ID.
$form_state
=
array
();
$form_state
[
'build_info'
][
'callback_object'
]
=
$form_arg
;
$form_state
[
'build_info'
][
'args'
]
=
array
();
$this
->
formBuilder
->
buildForm
(
$form_id
,
$form_state
);
}
/**
* Asserts that the expected form structure is found in a form for a given key.
*
...
...
@@ -499,6 +529,15 @@ protected function assertFormElement(array $expected_form, array $actual_form, $
*/
class
TestFormBuilder
extends
FormBuilder
{
/**
* {@inheritdoc}
*/
protected
function
sendResponse
(
Response
$response
)
{
parent
::
sendResponse
(
$response
);
// Throw an exception instead of exiting.
throw
new
\
Exception
(
'exit'
);
}
/**
* @param \Drupal\Core\Session\AccountInterface $account
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment