View source
<?php
namespace Drupal\Tests\media_entity_soundcloud\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
class SoundcloudEmbedFormatterTest extends BrowserTestBase {
use MediaTypeCreationTrait;
protected static $modules = [
'media_entity_soundcloud',
'media',
'link',
];
protected $defaultTheme = 'stable';
protected function setUp() {
parent::setUp();
$this
->config('media.settings')
->set('standalone_url', true)
->save();
$this
->refreshVariables();
\Drupal::service('router.builder')
->rebuild();
$account = $this
->drupalCreateUser([
'view media',
'create media',
'update media',
'update any media',
'delete media',
'delete any media',
]);
$this
->drupalLogin($account);
}
public function testSoundcloudEmbedFormatter() {
$entity_display_repository = \Drupal::service('entity_display.repository');
$media_type = $this
->createMediaType('soundcloud', [
'id' => 'soundcloud',
]);
$source_field = $media_type
->getSource()
->getSourceFieldDefinition($media_type);
$this
->assertSame('field_media_soundcloud', $source_field
->getName());
$this
->assertSame('string', $source_field
->getType());
\Drupal::service('entity_display.repository')
->getFormDisplay('media', $media_type
->id(), 'default')
->setComponent('field_media_soundcloud', [
'type' => 'string_textfield',
])
->save();
\Drupal::service('entity_display.repository')
->getViewDisplay('media', $media_type
->id(), 'full')
->setComponent('field_media_soundcloud', [
'type' => 'soundcloud_embed',
])
->save();
$this
->drupalGet('media/add/' . $media_type
->id());
$page = $this
->getSession()
->getPage();
$page
->fillField('name[0][value]', 'Soundcloud');
$page
->fillField('field_media_soundcloud[0][value]', 'https://soundcloud.com/winguy/billie-jean-remix-ft');
$page
->pressButton('Save');
$assert = $this
->assertSession();
$assert
->pageTextContains('has been created');
$medias = \Drupal::entityTypeManager()
->getStorage('media')
->loadByProperties([
'name' => 'Soundcloud',
]);
$media = reset($medias);
$this
->drupalGet(Url::fromRoute('entity.media.canonical', [
'media' => $media
->id(),
])
->toString());
$assert
->statusCodeEquals(200);
$assert
->elementExists('css', 'iframe[src*="soundcloud"]');
}
}