Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / video_embed_field / modules / video_embed_media / tests / src / Kernel / DefaultNameTest.php
index 493f64837cabfc410b12e0ee5fdead10616a5d9e..e51b806940e3f7cc2ab9b59b8e927e4a6711cb00 100644 (file)
@@ -2,17 +2,31 @@
 
 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;
+use Drupal\media\Entity\Media;
+use Drupal\media\Entity\MediaType;
+use Drupal\Tests\media\Kernel\MediaKernelTestBase;
+use Drupal\video_embed_media\Plugin\media\Source\VideoEmbedField;
 
 /**
  * Test the media bundle default names.
  *
  * @group video_embed_media
  */
-class DefaultNameTest extends KernelTestBase {
+class DefaultNameTest extends MediaKernelTestBase {
+
+  /**
+   * The plugin under test.
+   *
+   * @var \Drupal\video_embed_media\Plugin\media\Source\VideoEmbedField
+   */
+  protected $plugin;
+
+  /**
+   * The created media type.
+   *
+   * @var \Drupal\media\Entity\MediaType;
+   */
+  protected $entityType;
 
   /**
    * Modules to enable.
@@ -20,19 +34,13 @@ class DefaultNameTest extends KernelTestBase {
    * @var array
    */
   public static $modules = [
+    'video_embed_field',
     'video_embed_media',
-    'media_entity',
+    'media',
     'file',
     'views',
   ];
 
-  /**
-   * The media video plugin manager.
-   *
-   * @var \Drupal\media_entity\MediaTypeManager
-   */
-  protected $mediaVideoPlugin;
-
   /**
    * Test cases for ::testDefaultName().
    */
@@ -55,26 +63,25 @@ class DefaultNameTest extends KernelTestBase {
    * @dataProvider defaultNameTestCases
    */
   public function testDefaultName($input, $expected) {
+    $field_name = $this->plugin->getSourceFieldDefinition($this->entityType)->getName();
     $entity = Media::create([
-      'bundle' => 'video',
-      VideoEmbedField::VIDEO_EMBED_FIELD_DEFAULT_NAME => [['value' => $input]],
+      'bundle' => $this->entityType->id(),
+      $field_name => [['value' => $input]],
     ]);
-    $actual = $this->mediaVideoPlugin->getDefaultName($entity);
+    $actual = $this->plugin->getMetadata($entity, 'default_name');
     $this->assertEquals($expected, $actual);
   }
 
   /**
    * {@inheritdoc}
    */
-  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();
+  public function setUp() {
+    parent::setUp();
+    $this->installConfig(['video_embed_field', 'video_embed_media']);
+
+    $this->entityType = $this->createMediaType('video_embed_field');
+
+    $this->plugin = $this->entityType->getSource();
   }
 
 }