View source
<?php
namespace Drupal\media_entity_soundcloud\Tests;
use Drupal\media_entity\Tests\MediaTestTrait;
use Drupal\simpletest\WebTestBase;
class SoundcloudEmbedFormatterTest extends WebTestBase {
use MediaTestTrait;
public static $modules = array(
'media_entity_soundcloud',
'media_entity',
'node',
'field_ui',
'views_ui',
'block',
'link',
);
protected $adminUser;
protected $bundle;
protected function setUp() {
parent::setUp();
$bundle['bundle'] = 'soundcloud';
$this->bundle = $this
->drupalCreateMediaBundle($bundle, 'soundcloud');
$this->adminUser = $this
->drupalCreateUser([
'administer media',
'administer media bundles',
'administer media fields',
'administer media form display',
'administer media display',
'view media',
'create media',
'update media',
'update any media',
'delete media',
'delete any media',
'administer views',
]);
$this
->drupalLogin($this->adminUser);
}
public function testSoundcloudEmbedFormatter() {
$this
->drupalGet('admin/structure/media/manage/' . $this->bundle
->id());
$this
->assertFieldByName('label', $this->bundle
->label());
$this
->assertFieldByName('type', 'soundcloud');
$this
->drupalGet('admin/structure/media/manage/' . $this->bundle
->id() . '/fields/add-field');
$config = [
'new_storage_type' => 'link',
'label' => 'Url',
'field_name' => 'media_url',
];
$this
->drupalPostForm(NULL, $config, t('Save and continue'));
$this
->assertText('These settings apply to the ' . $config['label'] . ' field everywhere it is used.');
$edit = [
'cardinality' => 'number',
'cardinality_number' => '1',
];
$this
->drupalPostForm(NULL, $edit, t('Save field settings'));
$this
->assertText('Updated field ' . $config['label'] . ' field settings.');
$edit = [
'settings[link_type]' => 16,
'settings[title]' => 0,
];
$this
->drupalPostForm(NULL, $edit, t('Save settings'));
$this
->assertText('Saved ' . $config['label'] . ' configuration.');
$this
->assertText('field_media_url');
$this
->drupalGet('admin/structure/media/manage/' . $this->bundle
->id() . '/display');
$edit = [
'fields[field_media_url][label]' => 'above',
'fields[field_media_url][type]' => 'soundcloud_embed',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText('Your settings have been saved.');
$this
->drupalGet('admin/structure/media/manage/' . $this->bundle
->id());
$edit = [
'type_configuration[soundcloud][source_url_field]' => 'field_media_url',
];
$this
->drupalPostForm(NULL, $edit, t('Save media bundle'));
$this
->drupalGet('media/add/' . $this->bundle
->id());
$this
->assertFieldByName('field_media_url[0][uri]');
$edit = [
'name[0][value]' => 'Soundcloud',
'field_media_url[0][uri]' => 'https://soundcloud.com/winguy/billie-jean-remix-ft',
];
$this
->drupalPostForm(NULL, $edit, t('Save and publish'));
$this
->assertText('Url');
$this
->assertFieldByXPath('//iframe');
}
}