Version 1
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Functional / WidgetTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Test the video embed field widget.
10  *
11  * @group video_embed_field
12  */
13 class WidgetTest extends BrowserTestBase {
14
15   use EntityDisplaySetupTrait;
16   use AdminUserTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = [
22     'field_ui',
23     'node',
24     'video_embed_field',
25   ];
26
27   /**
28    * Test the input widget.
29    */
30   public function testVideoEmbedFieldDefaultWidget() {
31     $this->setupEntityDisplays();
32     $this->setFormComponentSettings('video_embed_field_textfield');
33
34     $this->drupalLogin($this->createAdminUser());
35     $node_title = $this->randomMachineName();
36
37     // Test an invalid input.
38     $this->drupalGet(Url::fromRoute('node.add', ['node_type' => $this->contentTypeName])->toString());
39     $this->submitForm([
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.');
44
45     // Test a valid input.
46     $valid_input = 'https://vimeo.com/80896303';
47     $this->submitForm([
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));
51
52     // Load the saved node and assert the valid value was saved into the field.
53     $nodes = \Drupal::entityTypeManager()
54       ->getStorage('node')
55       ->loadByProperties(['title' => $node_title]);
56     $node = array_shift($nodes);
57     $this->assertEquals($node->{$this->fieldName}[0]->value, $valid_input);
58   }
59
60 }