summaryrefslogtreecommitdiffstats
path: root/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php')
-rw-r--r--core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php68
1 files changed, 46 insertions, 22 deletions
diff --git a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
index 8e2fc0d..ba5d5e8 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\Form;
use Drupal\Core\Form\FormState;
+use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Tests\UnitTestCase;
/**
@@ -12,31 +13,58 @@ use Drupal\Tests\UnitTestCase;
class FormErrorHandlerTest extends UnitTestCase {
/**
+ * The form error handler.
+ *
+ * @var \Drupal\Core\Form\FormErrorHandler|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $formErrorHandler;
+
+ /**
+ * The messenger.
+ *
+ * @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $messenger;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->messenger = $this->createMock(MessengerInterface::class);
+
+ $this->formErrorHandler = $this->getMockBuilder('Drupal\Core\Form\FormErrorHandler')
+ ->setMethods(['messenger'])
+ ->getMock();
+
+ $this->formErrorHandler->expects($this->atLeastOnce())
+ ->method('messenger')
+ ->willReturn($this->messenger);
+ }
+
+ /**
* @covers ::handleFormErrors
* @covers ::displayErrorMessages
*/
public function testDisplayErrorMessages() {
- $form_error_handler = $this->getMockBuilder('Drupal\Core\Form\FormErrorHandler')
- ->setMethods(['drupalSetMessage'])
- ->getMock();
-
- $form_error_handler->expects($this->at(0))
- ->method('drupalSetMessage')
+ $this->messenger->expects($this->at(0))
+ ->method('addMessage')
->with('invalid', 'error');
- $form_error_handler->expects($this->at(1))
- ->method('drupalSetMessage')
+ $this->messenger->expects($this->at(1))
+ ->method('addMessage')
->with('invalid', 'error');
- $form_error_handler->expects($this->at(2))
- ->method('drupalSetMessage')
+ $this->messenger->expects($this->at(2))
+ ->method('addMessage')
->with('invalid', 'error');
- $form_error_handler->expects($this->at(3))
- ->method('drupalSetMessage')
+ $this->messenger->expects($this->at(3))
+ ->method('addMessage')
->with('no title given', 'error');
- $form_error_handler->expects($this->at(4))
- ->method('drupalSetMessage')
+ $this->messenger->expects($this->at(4))
+ ->method('addMessage')
->with('element is invisible', 'error');
- $form_error_handler->expects($this->at(5))
- ->method('drupalSetMessage')
+ $this->messenger->expects($this->at(5))
+ ->method('addMessage')
->with('this missing element is invalid', 'error');
$form = [
@@ -88,7 +116,7 @@ class FormErrorHandlerTest extends UnitTestCase {
$form_state->setErrorByName('test5', 'no title given');
$form_state->setErrorByName('test6', 'element is invisible');
$form_state->setErrorByName('missing_element', 'this missing element is invalid');
- $form_error_handler->handleFormErrors($form, $form_state);
+ $this->formErrorHandler->handleFormErrors($form, $form_state);
$this->assertSame('invalid', $form['test1']['#errors']);
}
@@ -97,10 +125,6 @@ class FormErrorHandlerTest extends UnitTestCase {
* @covers ::setElementErrorsFromFormState
*/
public function testSetElementErrorsFromFormState() {
- $form_error_handler = $this->getMockBuilder('Drupal\Core\Form\FormErrorHandler')
- ->setMethods(['drupalSetMessage'])
- ->getMock();
-
$form = [
'#parents' => [],
'#array_parents' => [],
@@ -176,7 +200,7 @@ class FormErrorHandlerTest extends UnitTestCase {
$form_state->setErrorByName('grouping_test2', 'invalid');
$form_state->setErrorByName('fieldset][nested_test', 'invalid');
$form_state->setErrorByName('fieldset][nested_test2', 'invalid2');
- $form_error_handler->handleFormErrors($form, $form_state);
+ $this->formErrorHandler->handleFormErrors($form, $form_state);
$this->assertSame('invalid', $form['test']['#errors']);
$this->assertSame([
'grouping_test' => 'invalid',