3 namespace Drupal\Tests\video_embed_field\Kernel;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\simpletest\UserCreationTrait;
7 use Drupal\video_embed_field\Plugin\Validation\Constraint\VideoEmbedConstraint;
10 * Test for the video embed constraint.
12 * @group video_embed_field
14 class ConstraintTest extends KernelTestBase {
16 use UserCreationTrait;
21 * @var \Drupal\user\UserInterface
28 protected function setUp() {
31 $this->installEntitySchema('user');
32 $this->installSchema('system', ['sequences']);
34 $this->user = $this->createUser([]);
38 * Test the video embed constraint.
40 public function testConstraint() {
41 $entity = EntityTest::create(['user_id' => $this->user->id()]);
42 $entity->{$this->fieldName}->value = 'invalid URL';
43 $violations = $entity->validate();
45 $this->assertCount(1, $violations);
46 $this->assertInstanceOf(VideoEmbedConstraint::class, $violations[0]->getConstraint());
48 $entity->{$this->fieldName}->value = 'https://youtube.com/watch?v=fdbFV_Wup-Ssw';
49 $violations = $entity->validate();
50 $this->assertCount(0, $violations);