3 namespace Drupal\Tests\video_embed_field\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\video_embed_field\Plugin\Field\FieldFormatter\Thumbnail;
9 * Tests the field formatter configuration forms.
11 * @group video_embed_field
13 class FormatterConfigurationTest extends BrowserTestBase {
16 use EntityDisplaySetupTrait;
21 public static $modules = [
29 * The URL to the manage display interface.
33 protected $manageDisplay;
38 protected function setUp() {
40 $this->drupalLogin($this->createAdminUser());
41 $this->setupEntityDisplays();
42 $this->manageDisplay = 'admin/structure/types/manage/test_content_type_name/display/teaser';
46 * Test the formatter configuration forms.
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([
54 'responsive' => FALSE,
58 $this->assertSession()->pageTextContains('Embedded Video (100x100).');
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,
67 $this->assertSession()->pageTextContains('Video thumbnail (thumbnail, linked to content).');
68 $this->updateFormatterSettings([
69 'image_style' => 'medium',
70 'link_image_to' => Thumbnail::LINK_PROVIDER,
72 $this->assertSession()->pageTextContains('Video thumbnail (medium, linked to provider).');
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([
80 'responsive' => FALSE,
83 'image_style' => 'medium',
84 'link_image_to' => Thumbnail::LINK_PROVIDER,
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).');
92 * Set the field formatter for the test field.
94 * @param string $formatter
95 * The field formatter ID to use.
97 protected function setFormatter($formatter) {
98 $this->drupalGet($this->manageDisplay);
99 $this->find('input[name="refresh_rows"]')->setValue($this->fieldName);
101 'fields[' . $this->fieldName . '][type]' => $formatter,
102 'fields[' . $this->fieldName . '][region]' => 'content',
104 $this->submitForm([], t('Save'));
108 * Update the settings for the current formatter.
110 * @param array $settings
111 * The settings to update the foramtter with.
113 protected function updateFormatterSettings($settings) {
115 foreach ($settings as $key => $value) {
116 $edit["fields[{$this->fieldName}][settings_edit_form][settings][$key]"] = $value;
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'));
125 * Find an element based on a CSS selector.
127 * @param string $css_selector
128 * A css selector to find an element for.
130 * @return \Behat\Mink\Element\NodeElement|null
131 * The found element or null.
133 protected function find($css_selector) {
134 return $this->getSession()->getPage()->find('css', $css_selector);