protected function TestBase::assertViolations in Double Field 4.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/TestBase.php \Drupal\Tests\double_field\Functional\TestBase::assertViolations()
Passes if all expected violations were found.
4 calls to TestBase::assertViolations()
- FieldTypeTest::testFieldSettings in tests/
src/ Functional/ FieldTypeTest.php - Test field settings.
- FieldTypeTest::testFieldStorageSettings in tests/
src/ Functional/ FieldTypeTest.php - Test field storage settings.
- FieldTypeTest::testRequiredOptions in tests/
src/ Functional/ FieldTypeTest.php - Test required options.
- TestBase::assertNoViolations in tests/
src/ Functional/ TestBase.php - Passes if no violations were found.
File
- tests/
src/ Functional/ TestBase.php, line 300
Class
- TestBase
- Tests the creation of text fields.
Namespace
Drupal\Tests\double_field\FunctionalCode
protected function assertViolations(array $values, array $expected_messages) : void {
$node = Node::create([
'type' => $this->contentTypeId,
]);
$node->{$this->fieldName} = [
'first' => $values[0],
'second' => $values[1],
];
/** @var \Symfony\Component\Validator\ConstraintViolationInterface[] $violations */
$violations = $node->{$this->fieldName}
->validate();
foreach ($violations as $index => $violation) {
$message = strip_tags($violations[$index]
->getMessage());
$key = array_search($message, $expected_messages);
self::assertNotFalse($key, sprintf('Found violation: "%s".', $message));
}
self::assertEquals(count($violations), count($expected_messages));
}