diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 04b90e5..53ddcb3 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -141,7 +141,7 @@ public function getFormId($form_arg, &$form_state) { } if (!is_object($form_arg) || !($form_arg instanceof FormInterface)) { - throw new \Exception(String::format('The form argument @form_arg is not a valid form.', array('@form_arg' => $form_arg))); + throw new \InvalidArgumentException(String::format('The form argument @form_arg is not a valid form.', array('@form_arg' => $form_arg))); } // Add the $form_arg as the callback object and determine the form ID. diff --git a/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php b/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php new file mode 100644 index 0000000..812f368 --- /dev/null +++ b/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php @@ -0,0 +1,91 @@ + 'submit', '#value' => 'Save'); + return $form; + } + + /** + * {@inheritdoc} + */ + public function customValidateForm(array &$form, array &$form_state) { + $form_state['test_handlers']['validate'][] = __FUNCTION__; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + $form_state['test_handlers']['validate'][] = __FUNCTION__; + } + + /** + * {@inheritdoc} + */ + public function customSubmitForm(array &$form, array &$form_state) { + $form_state['test_handlers']['submit'][] = __FUNCTION__; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $form_state['test_handlers']['submit'][] = __FUNCTION__; + } + + /** + * Tests that default handlers are added even if custom are specified. + */ + function testLimitValidationErrors() { + $form_state['values'] = array(); + $form_builder = $this->container->get('form_builder'); + $form_builder->submitForm($this, $form_state); + + $handlers = $form_state['test_handlers']; + + $this->assertIdentical(count($handlers['validate']), 2); + $this->assertIdentical($handlers['validate'][0], 'customValidateForm'); + $this->assertIdentical($handlers['validate'][1], 'validateForm'); + + $this->assertIdentical(count($handlers['submit']), 2); + $this->assertIdentical($handlers['submit'][0], 'customSubmitForm'); + $this->assertIdentical($handlers['submit'][1], 'submitForm'); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index 3f4e0ab..4702b9d 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -20,7 +20,8 @@ class FormBuilderTest extends FormTestBase { /** * Tests the getFormId() method with a string based form ID. * - * @expectedException \Exception + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The form argument foo is not a valid form. */ public function testGetFormIdWithString() { $form_arg = 'foo'; @@ -192,7 +193,8 @@ public function testHandleRedirectWithResponse() { /** * Tests the getForm() method with a string based form ID. * - * @expectedException \Exception + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The form argument test_form_id is not a valid form. */ public function testGetFormWithString() { $form_id = 'test_form_id'; @@ -235,7 +237,8 @@ public function testGetFormWithClassString() { /** * Tests the buildForm() method with a string based form ID. * - * @expectedException \Exception + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The form argument test_form_id is not a valid form. */ public function testBuildFormWithString() { $form_id = 'test_form_id';