function InputTest::testInputIsValidated

Tests input validation.

File

core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php, line 84

Class

InputTest
@group Recipe @covers \Drupal\Core\Recipe\InputConfigurator[[api-linebreak]]

Namespace

Drupal\KernelTests\Core\Recipe

Code

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) {
    $value = $e->getValue();
    $this->assertInstanceOf(TypedDataInterface::class, $value);
    $this->assertSame('not-an-email-address', $value->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.