DefaultNameTest.php in Video Embed Field 8
File
modules/video_embed_media/tests/src/Kernel/DefaultNameTest.php
View source
<?php
namespace Drupal\Tests\video_embed_media\Kernel;
use Drupal\media_entity\Entity\Media;
use Drupal\media_entity\Entity\MediaBundle;
use Drupal\Tests\video_embed_field\Kernel\KernelTestBase;
use Drupal\video_embed_media\Plugin\MediaEntity\Type\VideoEmbedField;
class DefaultNameTest extends KernelTestBase {
public static $modules = [
'video_embed_media',
'media_entity',
'file',
'views',
];
protected $mediaVideoPlugin;
public function defaultNameTestCases() {
return [
'YouTube' => [
'https://www.youtube.com/watch?v=gnERPdAiuSo',
'YouTube Video (gnERPdAiuSo)',
],
'Vimeo' => [
'https://vimeo.com/21681203',
'Drupal Commerce at DrupalCon Chicago',
],
];
}
public function testDefaultName($input, $expected) {
$entity = Media::create([
'bundle' => 'video',
VideoEmbedField::VIDEO_EMBED_FIELD_DEFAULT_NAME => [
[
'value' => $input,
],
],
]);
$actual = $this->mediaVideoPlugin
->getDefaultName($entity);
$this
->assertEquals($expected, $actual);
}
public function setup() {
parent::setup();
$this
->installConfig([
'media_entity',
]);
$this->mediaVideoPlugin = $this->container
->get('plugin.manager.media_entity.type')
->createInstance('video_embed_field', []);
$bundle = MediaBundle::create([
'id' => 'video',
'type' => 'video_embed_field',
]);
$bundle
->save();
}
}