View source
<?php
namespace Drupal\Tests\jw_player\Functional;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
class JwPlayerConfigurationTest extends BrowserTestBase {
use FieldUiTestTrait;
public static $modules = array(
'node',
'jw_player',
'file',
'field',
'field_ui',
'block',
);
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'jw_player',
'name' => 'JW content',
));
$this
->drupalPlaceBlock('system_breadcrumb_block');
}
public function testJwPlayerCreation() {
$admin_user = $this
->drupalCreateUser(array(
'administer site configuration',
'administer JW Player presets',
'administer nodes',
'create jw_player content',
'administer content types',
'administer node fields',
'administer node display',
'access administration pages',
));
$this
->drupalLogin($admin_user);
$edit = [
'jw_player_hosting' => 'cloud',
'cloud_player_library_url' => $cloud_library = 'https://content.jwplatform.com/libraries/' . $this
->randomMachineName(8) . '.js',
];
$this
->drupalPostForm('admin/config/media/jw_player/settings', $edit, t('Save configuration'));
$edit = array(
'label' => 'Test preset',
'id' => 'test_preset',
'description' => 'Test preset description',
'settings[skin]' => 'bekle',
'settings[mode]' => 'html5',
'settings[width]' => 100,
'settings[height]' => 100,
'settings[advertising][client]' => 'vast',
'settings[advertising][tag]' => 'www.example.com/vast',
'settings[controlbar]' => 'bottom',
'settings[mute]' => TRUE,
'settings[autostart]' => TRUE,
);
$this
->drupalPostForm('admin/config/media/jw_player/add', $edit, t('Save'));
$this
->assertText('Saved the Test preset Preset.');
$this
->drupalGet('admin/config/media/jw_player/test_preset');
$this
->assertFieldByName('label', 'Test preset');
$this
->assertFieldByName('description', 'Test preset description');
$this
->assertFieldByName('settings[mode]', 'html5');
$this
->assertFieldByName('settings[skin]', 'bekle');
$this
->assertFieldByName('settings[advertising][client]', 'vast');
$this
->assertFieldByName('settings[advertising][tag]', 'www.example.com/vast');
$this
->assertFieldByName('settings[controlbar]', 'bottom');
$this
->assertFieldByName('settings[mute]', TRUE);
$this
->assertFieldByName('settings[autostart]', TRUE);
$this
->assertNoFieldByName('settings[sharing]');
static::fieldUIAddNewField('admin/structure/types/manage/jw_player', 'video', 'Video', 'file', array(), array(
'settings[file_extensions]' => 'mp4',
));
$this
->drupalPostForm('admin/structure/types/manage/jw_player/display', array(
'fields[field_video][type]' => 'jwplayer_formatter',
), t('Save'));
$this
->drupalPostForm(NULL, NULL, 'field_video_settings_edit');
$edit = [
'fields[field_video][settings_edit_form][settings][jwplayer_preset]' => 'test_preset',
];
$this
->drupalPostForm(NULL, $edit, t('Update'));
$this
->drupalPostForm(NULL, NULL, t('Save'));
$this
->assertText('Preset: Test preset');
$this
->assertText('Dimensions: 100x100, uniform');
$this
->assertText('Skin: bekle');
$this
->assertText('Enabled options: Autostart, Mute');
$view_display = EntityViewDisplay::load('node.jw_player.default');
$this
->assertTrue(in_array('jw_player.preset.test_preset', $view_display
->getDependencies()['config']));
$text = 'Trust me I\'m a video';
file_put_contents('temporary://myVideo.mp4', $text);
$edit = array(
'title[0][value]' => 'Test video',
'files[field_video_0]' => \Drupal::service('file_system')
->realpath('temporary://myVideo.mp4'),
);
$this
->drupalPostForm('node/add/jw_player', $edit, t('Save'));
$this
->assertText('JW content Test video has been created.');
$element = $this
->getSession()
->getPage()
->find('css', 'video');
$id = $element
->getAttribute('id');
$this
->assertRaw('jw_player":{"players":{"' . $id . '":{"file":"' . str_replace('/', '\\/', file_create_url(\Drupal::token()
->replace('public://[date:custom:Y]-[date:custom:m]/myVideo.mp4'))) . '"');
$this
->assertEquals(1, preg_match('/jwplayer-[a-zA-Z0-9]{1,}$/', $id));
$this
->assertRaw('<script src="' . $cloud_library . '"></script>');
}
public function testDelete() {
$admin_user = $this
->drupalCreateUser(array(
'administer site configuration',
));
$this
->drupalLogin($admin_user);
$this
->drupalPostForm('admin/config/media/jw_player/add', [
'label' => 'Test preset',
'id' => 'test_preset',
'settings[width]' => 100,
'settings[height]' => 100,
], t('Save'));
$this
->clickLink(t('Delete'));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertRaw(t('The @entity-type %label has been deleted.', [
'@entity-type' => 'jw player preset',
'%label' => 'Test preset',
]));
$this
->assertEqual([], $this
->xpath('//td[text()=@label]', [
'@label' => 'Test preset',
]));
}
}