Version 1
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Functional / FormatterConfigurationTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\video_embed_field\Plugin\Field\FieldFormatter\Thumbnail;
7
8 /**
9  * Tests the field formatter configuration forms.
10  *
11  * @group video_embed_field
12  */
13 class FormatterConfigurationTest extends BrowserTestBase {
14
15   use AdminUserTrait;
16   use EntityDisplaySetupTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = [
22     'video_embed_field',
23     'node',
24     'field_ui',
25     'colorbox',
26   ];
27
28   /**
29    * The URL to the manage display interface.
30    *
31    * @var string
32    */
33   protected $manageDisplay;
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function setUp() {
39     parent::setUp();
40     $this->drupalLogin($this->createAdminUser());
41     $this->setupEntityDisplays();
42     $this->manageDisplay = 'admin/structure/types/manage/test_content_type_name/display/teaser';
43   }
44
45   /**
46    * Test the formatter configuration forms.
47    */
48   public function testVideoConfirmationForm() {
49     // Test the settings form and summaries for the video formatter.
50     $this->setFormatter('video_embed_field_video');
51     $this->assertSession()->pageTextContains('Embedded Video (Responsive, autoplaying).');
52     $this->updateFormatterSettings([
53       'autoplay' => FALSE,
54       'responsive' => FALSE,
55       'width' => 100,
56       'height' => 100,
57     ]);
58     $this->assertSession()->pageTextContains('Embedded Video (100x100).');
59
60     // Test the image formatter.
61     $this->setFormatter('video_embed_field_thumbnail');
62     $this->assertSession()->pageTextContains('Video thumbnail (no image style).');
63     $this->updateFormatterSettings([
64       'image_style' => 'thumbnail',
65       'link_image_to' => Thumbnail::LINK_CONTENT,
66     ]);
67     $this->assertSession()->pageTextContains('Video thumbnail (thumbnail, linked to content).');
68     $this->updateFormatterSettings([
69       'image_style' => 'medium',
70       'link_image_to' => Thumbnail::LINK_PROVIDER,
71     ]);
72     $this->assertSession()->pageTextContains('Video thumbnail (medium, linked to provider).');
73
74     $this->setFormatter('video_embed_field_colorbox');
75     $this->assertSession()->pageTextContains('Thumbnail that launches a modal window.');
76     $this->assertSession()->pageTextContains('Embedded Video (Responsive, autoplaying).');
77     $this->assertSession()->pageTextContains('Video thumbnail (medium, linked to provider).');
78     $this->updateFormatterSettings([
79       'autoplay' => FALSE,
80       'responsive' => FALSE,
81       'width' => 100,
82       'height' => 100,
83       'image_style' => 'medium',
84       'link_image_to' => Thumbnail::LINK_PROVIDER,
85     ]);
86     $this->assertSession()->pageTextContains('Thumbnail that launches a modal window.');
87     $this->assertSession()->pageTextContains('Embedded Video (100x100).');
88     $this->assertSession()->pageTextContains('Video thumbnail (medium, linked to provider).');
89   }
90
91   /**
92    * Set the field formatter for the test field.
93    *
94    * @param string $formatter
95    *   The field formatter ID to use.
96    */
97   protected function setFormatter($formatter) {
98     $this->drupalGet($this->manageDisplay);
99     $this->find('input[name="refresh_rows"]')->setValue($this->fieldName);
100     $this->submitForm([
101       'fields[' . $this->fieldName . '][type]' => $formatter,
102       'fields[' . $this->fieldName . '][region]' => 'content',
103     ], t('Refresh'));
104     $this->submitForm([], t('Save'));
105   }
106
107   /**
108    * Update the settings for the current formatter.
109    *
110    * @param array $settings
111    *   The settings to update the foramtter with.
112    */
113   protected function updateFormatterSettings($settings) {
114     $edit = [];
115     foreach ($settings as $key => $value) {
116       $edit["fields[{$this->fieldName}][settings_edit_form][settings][$key]"] = $value;
117     }
118     $this->drupalGet($this->manageDisplay);
119     $this->find('input[name="' . $this->fieldName . '_settings_edit"]')->click();
120     $this->submitForm($edit, $this->fieldName . '_plugin_settings_update');
121     $this->submitForm([], t('Save'));
122   }
123
124   /**
125    * Find an element based on a CSS selector.
126    *
127    * @param string $css_selector
128    *   A css selector to find an element for.
129    *
130    * @return \Behat\Mink\Element\NodeElement|null
131    *   The found element or null.
132    */
133   protected function find($css_selector) {
134     return $this->getSession()->getPage()->find('css', $css_selector);
135   }
136
137 }