function InputTest::testInputIsValidated
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ InputTest.php, line 70
Class
- InputTest
- @group Recipe @covers \Drupal\Core\Recipe\InputConfigurator
Namespace
Drupal\KernelTests\Core\RecipeCode
public function testInputIsValidated() : void {
$collector = $this->createMock(InputCollectorInterface::class);
$collector->expects($this->atLeastOnce())
->method('collectValue')
->with('feedback_contact_form.recipient', $this->isInstanceOf(DataDefinitionInterface::class), $this->anything())
->willReturn('not-an-email-address');
try {
$this->recipe->input
->collectAll($collector);
$this->fail('Expected an exception due to validation failure, but none was thrown.');
} catch (ValidationFailedException $e) {
$this->assertSame('not-an-email-address', $e->getValue());
$this->assertSame('This value is not a valid email address.', (string) $e->getViolations()
->get(0)
->getMessage());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.