3 namespace Drupal\Tests\video_embed_field\Functional;
6 use Drupal\Tests\BrowserTestBase;
9 * Test the video embed field widget.
11 * @group video_embed_field
13 class WidgetTest extends BrowserTestBase {
15 use EntityDisplaySetupTrait;
21 public static $modules = [
28 * Test the input widget.
30 public function testVideoEmbedFieldDefaultWidget() {
31 $this->setupEntityDisplays();
32 $this->setFormComponentSettings('video_embed_field_textfield');
34 $this->drupalLogin($this->createAdminUser());
35 $node_title = $this->randomMachineName();
37 // Test an invalid input.
38 $this->drupalGet(Url::fromRoute('node.add', ['node_type' => $this->contentTypeName])->toString());
40 'title[0][value]' => $node_title,
41 $this->fieldName . '[0][value]' => 'Some useless value.',
42 ], t('Save and publish'));
43 $this->assertSession()->pageTextContains('Could not find a video provider to handle the given URL.');
45 // Test a valid input.
46 $valid_input = 'https://vimeo.com/80896303';
48 $this->fieldName . '[0][value]' => $valid_input,
49 ], t('Save and publish'));
50 $this->assertSession()->pageTextContains(sprintf('%s %s has been created.', $this->contentTypeName, $node_title));
52 // Load the saved node and assert the valid value was saved into the field.
53 $nodes = \Drupal::entityTypeManager()
55 ->loadByProperties(['title' => $node_title]);
56 $node = array_shift($nodes);
57 $this->assertEquals($node->{$this->fieldName}[0]->value, $valid_input);