View source
<?php
namespace Drupal\Tests\video_embed_field\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\video_embed_field\Plugin\Field\FieldFormatter\Thumbnail;
class FormatterConfigurationTest extends BrowserTestBase {
use AdminUserTrait;
use EntityDisplaySetupTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'video_embed_field',
'node',
'field_ui',
'colorbox',
];
protected $manageDisplay;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->createAdminUser());
$this
->setupEntityDisplays();
$this->manageDisplay = 'admin/structure/types/manage/test_content_type_name/display/teaser';
}
public function testVideoConfirmationForm() {
$this
->setFormatter('video_embed_field_video');
$this
->assertSession()
->pageTextContains('Embedded Video (Responsive, autoplaying).');
$this
->updateFormatterSettings([
'autoplay' => FALSE,
'responsive' => FALSE,
'width' => 100,
'height' => 100,
]);
$this
->assertSession()
->pageTextContains('Embedded Video (100x100).');
$this
->setFormatter('video_embed_field_thumbnail');
$this
->assertSession()
->pageTextContains('Video thumbnail (no image style).');
$this
->updateFormatterSettings([
'image_style' => 'thumbnail',
'link_image_to' => Thumbnail::LINK_CONTENT,
]);
$this
->assertSession()
->pageTextContains('Video thumbnail (thumbnail, linked to content).');
$this
->updateFormatterSettings([
'image_style' => 'medium',
'link_image_to' => Thumbnail::LINK_PROVIDER,
]);
$this
->assertSession()
->pageTextContains('Video thumbnail (medium, linked to provider).');
$this
->setFormatter('video_embed_field_colorbox');
$this
->assertSession()
->pageTextContains('Thumbnail that launches a modal window.');
$this
->assertSession()
->pageTextContains('Embedded Video (Responsive, autoplaying).');
$this
->assertSession()
->pageTextContains('Video thumbnail (medium, linked to provider).');
$this
->updateFormatterSettings([
'autoplay' => FALSE,
'responsive' => FALSE,
'width' => 100,
'height' => 100,
'image_style' => 'medium',
'link_image_to' => Thumbnail::LINK_PROVIDER,
]);
$this
->assertSession()
->pageTextContains('Thumbnail that launches a modal window.');
$this
->assertSession()
->pageTextContains('Embedded Video (100x100).');
$this
->assertSession()
->pageTextContains('Video thumbnail (medium, linked to provider).');
}
protected function setFormatter($formatter) {
$this
->drupalGet($this->manageDisplay);
$this
->find('input[name="refresh_rows"]')
->setValue($this->fieldName);
$this
->submitForm([
'fields[' . $this->fieldName . '][type]' => $formatter,
'fields[' . $this->fieldName . '][region]' => 'content',
], t('Refresh'));
$this
->submitForm([], t('Save'));
}
protected function updateFormatterSettings($settings) {
$edit = [];
foreach ($settings as $key => $value) {
$edit["fields[{$this->fieldName}][settings_edit_form][settings][{$key}]"] = $value;
}
$this
->drupalGet($this->manageDisplay);
$this
->find('input[name="' . $this->fieldName . '_settings_edit"]')
->click();
$this
->submitForm($edit, $this->fieldName . '_plugin_settings_update');
$this
->submitForm([], t('Save'));
}
protected function find($css_selector) {
return $this
->getSession()
->getPage()
->find('css', $css_selector);
}
}