You are here

public function JsonItemTest::testValidation in JSON Field 8

Tests the validators.

File

tests/src/Kernel/JsonItemTest.php, line 53

Class

JsonItemTest
@coversDefaultClass \Drupal\json_field\Plugin\Field\FieldType\JSONItem

Namespace

Drupal\Tests\json_field\Kernel

Code

public function testValidation() {
  $this
    ->createTestField();
  $entity = EntityTest::create([
    'test_json_field' => "this-is-not-valid-json';2';12'3;12'3;",
  ]);
  $entity
    ->save();
  $constraint_list = $entity
    ->validate()
    ->getByField('test_json_field');
  $this
    ->assertEquals(1, $constraint_list
    ->count());
  $this
    ->assertEquals('The supplied text is not valid JSON data (@error).', $constraint_list
    ->get(0)
    ->getMessage()
    ->getUntranslatedString());
}