Interim commit.
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Kernel / ConstraintTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Kernel;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\simpletest\UserCreationTrait;
7 use Drupal\video_embed_field\Plugin\Validation\Constraint\VideoEmbedConstraint;
8
9 /**
10  * Test for the video embed constraint.
11  *
12  * @group video_embed_field
13  */
14 class ConstraintTest extends KernelTestBase {
15
16   use UserCreationTrait;
17
18   /**
19    * A test user.
20    *
21    * @var \Drupal\user\UserInterface
22    */
23   protected $user;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::setUp();
30
31     $this->installEntitySchema('user');
32     $this->installSchema('system', ['sequences']);
33
34     $this->user = $this->createUser([]);
35   }
36
37   /**
38    * Test the video embed constraint.
39    */
40   public function testConstraint() {
41     $entity = EntityTest::create(['user_id' => $this->user->id()]);
42     $entity->{$this->fieldName}->value = 'invalid URL';
43     $violations = $entity->validate();
44
45     $this->assertCount(1, $violations);
46     $this->assertInstanceOf(VideoEmbedConstraint::class, $violations[0]->getConstraint());
47
48     $entity->{$this->fieldName}->value = 'https://youtube.com/watch?v=fdbFV_Wup-Ssw';
49     $violations = $entity->validate();
50     $this->assertCount(0, $violations);
51   }
52
53 }