diff --git a/core/modules/system/src/Tests/Entity/EntityFormTest.php b/core/modules/system/src/Tests/Entity/EntityFormTest.php index 307b69a..dcdb20f 100644 --- a/core/modules/system/src/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFormTest.php @@ -66,6 +66,8 @@ protected function doTestFormCRUD($entity_type) { ); $this->drupalPostForm($entity_type . '/add', $edit, t('Save')); + $this->assertNoRaw('This should not run.'); + $entity = $this->loadEntityByName($entity_type, $name1); $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $entity_type))); diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php index ec7c3e0..0f13979 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -43,6 +43,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $entity->isNewRevision(), ); } + $form['#validate'][] = '::formLevelValidator'; return $form; } @@ -50,6 +51,13 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ + public function formLevelValidator(array &$form, FormStateInterface $form_state) { + $form_state->setError($form, 'This should not run.'); + } + + /** + * {@inheritdoc} + */ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php index ea39a9d..b703d45 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormState; +use Drupal\Core\Form\FormStateInterface; use Drupal\Tests\UnitTestCase; /** @@ -123,4 +124,20 @@ public function testCopyFormValuesToEntity() { $this->assertNull($result->get('key_controlled_by_plugin_collection')); } + /** + * @covers ::validate + */ + public function testValidate() { + $form_object = $this->getMock('Drupal\Core\Entity\EntityFormInterface'); + $form_object->expects($this->once()) + ->method('validate') + ->willReturnCallback(function (array &$form, FormStateInterface $form_state) { + $form['foo'] = 'bar'; + }); + $form['baz'] = 'bim'; + $form_state = new FormState(); + $form_object->validate($form, $form_state); + $this->assertArrayHasKey('foo', $form); + } + }