Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / media / tests / src / Kernel / MediaKernelTestBase.php
index c00dc3d1de4462633229a997ec861d3b801a3724..1c6a879eeaae2eee939c0722839802162f14d960 100644 (file)
@@ -5,8 +5,8 @@ namespace Drupal\Tests\media\Kernel;
 use Drupal\file\Entity\File;
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\media\Entity\Media;
-use Drupal\media\Entity\MediaType;
 use Drupal\media\MediaTypeInterface;
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
 use Drupal\user\Entity\User;
 use org\bovigo\vfs\vfsStream;
 
@@ -15,6 +15,8 @@ use org\bovigo\vfs\vfsStream;
  */
 abstract class MediaKernelTestBase extends KernelTestBase {
 
+  use MediaTypeCreationTrait;
+
   /**
    * Modules to install.
    *
@@ -77,37 +79,6 @@ abstract class MediaKernelTestBase extends KernelTestBase {
     $this->container->get('current_user')->setAccount($this->user);
   }
 
-  /**
-   * Create a media type for a source plugin.
-   *
-   * @param string $media_source_name
-   *   The name of the media source.
-   *
-   * @return \Drupal\media\MediaTypeInterface
-   *   A media type.
-   */
-  protected function createMediaType($media_source_name) {
-    $id = strtolower($this->randomMachineName());
-    $media_type = MediaType::create([
-      'id' => $id,
-      'label' => $id,
-      'source' => $media_source_name,
-      'new_revision' => FALSE,
-    ]);
-    $media_type->save();
-    $source_field = $media_type->getSource()->createSourceField($media_type);
-    // The media type form creates a source field if it does not exist yet. The
-    // same must be done in a kernel test, since it does not use that form.
-    // @see \Drupal\media\MediaTypeForm::save()
-    $source_field->getFieldStorageDefinition()->save();
-    // The source field storage has been created, now the field can be saved.
-    $source_field->save();
-    $media_type->set('source_configuration', [
-      'source_field' => $source_field->getName(),
-    ])->save();
-    return $media_type;
-  }
-
   /**
    * Helper to generate a media item.
    *