You are here

public function ConstraintTest::testConstraint in Video Embed Field 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/ConstraintTest.php \Drupal\Tests\video_embed_field\Kernel\ConstraintTest::testConstraint()

Test the video embed constraint.

File

tests/src/Kernel/ConstraintTest.php, line 40

Class

ConstraintTest
Test for the video embed constraint.

Namespace

Drupal\Tests\video_embed_field\Kernel

Code

public function testConstraint() {
  $entity = EntityTest::create([
    'user_id' => $this->user
      ->id(),
  ]);
  $entity->{$this->fieldName}->value = 'invalid URL';
  $violations = $entity
    ->validate();
  $this
    ->assertCount(1, $violations);
  $this
    ->assertInstanceOf(VideoEmbedConstraint::class, $violations[0]
    ->getConstraint());
  $entity->{$this->fieldName}->value = 'https://youtube.com/watch?v=fdbFV_Wup-Ssw';
  $violations = $entity
    ->validate();
  $this
    ->assertCount(0, $violations);
}