summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2018-07-02 16:26:17 (GMT)
committerxjm2018-07-02 16:26:17 (GMT)
commit3564dd559ebb82692b19a79af0911f938592bfb0 (patch)
tree0af12229956474f65fadc9db1f4eca45fe4168b5
parent6312fcbe67cc475a4294124715cacf9f272490d9 (diff)
Issue #2976889 by phenaproxima, xjm, chr.fritsch, samuel.mortenson, larowlan, alexpott: Add a trait to create media types in tests and replace MediaFunctionalTestCreateMediaTypeTrait
-rw-r--r--core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php4
-rw-r--r--core/modules/media/tests/src/Functional/MediaAccessTest.php2
-rw-r--r--core/modules/media/tests/src/Functional/MediaBulkFormTest.php2
-rw-r--r--core/modules/media/tests/src/Functional/MediaCacheTagsTest.php5
-rw-r--r--core/modules/media/tests/src/Functional/MediaContextualLinksTest.php2
-rw-r--r--core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php3
-rw-r--r--core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php60
-rw-r--r--core/modules/media/tests/src/Functional/MediaOverviewPageTest.php4
-rw-r--r--core/modules/media/tests/src/Functional/MediaRevisionTest.php6
-rw-r--r--core/modules/media/tests/src/Functional/MediaSettingsTest.php2
-rw-r--r--core/modules/media/tests/src/Functional/MediaSourceFileTest.php4
-rw-r--r--core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php3
-rw-r--r--core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php14
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php2
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php4
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php2
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php2
-rw-r--r--core/modules/media/tests/src/Kernel/MediaKernelTestBase.php35
-rw-r--r--core/modules/media/tests/src/Traits/MediaTypeCreationTrait.php76
-rw-r--r--core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php7
20 files changed, 127 insertions, 112 deletions
diff --git a/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php b/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php
index 6f110f5..2d344bd 100644
--- a/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php
+++ b/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php
@@ -102,7 +102,7 @@ class OEmbedFormatterTest extends MediaFunctionalTestBase {
$account = $this->drupalCreateUser(['administer media display']);
$this->drupalLogin($account);
- $media_type = $this->createMediaType([], 'oembed:video');
+ $media_type = $this->createMediaType('oembed:video');
$this->drupalGet('/admin/structure/media/manage/' . $media_type->id() . '/display');
$assert = $this->assertSession();
$assert->statusCodeEquals(200);
@@ -132,7 +132,7 @@ class OEmbedFormatterTest extends MediaFunctionalTestBase {
$account = $this->drupalCreateUser(['view media']);
$this->drupalLogin($account);
- $media_type = $this->createMediaType([], 'oembed:video');
+ $media_type = $this->createMediaType('oembed:video');
$source = $media_type->getSource();
$source_field = $source->getSourceFieldDefinition($media_type);
diff --git a/core/modules/media/tests/src/Functional/MediaAccessTest.php b/core/modules/media/tests/src/Functional/MediaAccessTest.php
index ef9f648..4672c3e 100644
--- a/core/modules/media/tests/src/Functional/MediaAccessTest.php
+++ b/core/modules/media/tests/src/Functional/MediaAccessTest.php
@@ -39,7 +39,7 @@ class MediaAccessTest extends MediaFunctionalTestBase {
public function testMediaAccess() {
$assert_session = $this->assertSession();
- $media_type = $this->createMediaType();
+ $media_type = $this->createMediaType('test');
// Create media.
$media = Media::create([
diff --git a/core/modules/media/tests/src/Functional/MediaBulkFormTest.php b/core/modules/media/tests/src/Functional/MediaBulkFormTest.php
index 44ec6b8..6bf9195 100644
--- a/core/modules/media/tests/src/Functional/MediaBulkFormTest.php
+++ b/core/modules/media/tests/src/Functional/MediaBulkFormTest.php
@@ -39,7 +39,7 @@ class MediaBulkFormTest extends MediaFunctionalTestBase {
protected function setUp() {
parent::setUp();
- $this->testMediaType = $this->createMediaType();
+ $this->testMediaType = $this->createMediaType('test');
// Create some test media items.
$this->mediaItems = [];
diff --git a/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php b/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php
index ece89f4..4cacf3d 100644
--- a/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php
+++ b/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php
@@ -4,6 +4,7 @@ namespace Drupal\Tests\media\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\media\Entity\Media;
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
/**
@@ -13,7 +14,7 @@ use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
*/
class MediaCacheTagsTest extends EntityWithUriCacheTagsTestBase {
- use MediaFunctionalTestCreateMediaTypeTrait;
+ use MediaTypeCreationTrait;
/**
* {@inheritdoc}
@@ -28,7 +29,7 @@ class MediaCacheTagsTest extends EntityWithUriCacheTagsTestBase {
*/
protected function createEntity() {
// Create a media type.
- $mediaType = $this->createMediaType();
+ $mediaType = $this->createMediaType('test');
// Create a media item.
$media = Media::create([
diff --git a/core/modules/media/tests/src/Functional/MediaContextualLinksTest.php b/core/modules/media/tests/src/Functional/MediaContextualLinksTest.php
index 1d97773..540afac 100644
--- a/core/modules/media/tests/src/Functional/MediaContextualLinksTest.php
+++ b/core/modules/media/tests/src/Functional/MediaContextualLinksTest.php
@@ -23,7 +23,7 @@ class MediaContextualLinksTest extends MediaFunctionalTestBase {
*/
public function testMediaContextualLinks() {
// Create a media type.
- $mediaType = $this->createMediaType();
+ $mediaType = $this->createMediaType('test');
// Create a media item.
$media = Media::create([
diff --git a/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php b/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php
index 017e725..b786d2e 100644
--- a/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php
+++ b/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\media\Functional;
use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
/**
* Base class for Media functional tests.
@@ -10,7 +11,7 @@ use Drupal\Tests\BrowserTestBase;
abstract class MediaFunctionalTestBase extends BrowserTestBase {
use MediaFunctionalTestTrait;
- use MediaFunctionalTestCreateMediaTypeTrait;
+ use MediaTypeCreationTrait;
/**
* Modules to enable.
diff --git a/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php b/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php
index 2a72edd..265671b 100644
--- a/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php
+++ b/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php
@@ -2,13 +2,24 @@
namespace Drupal\Tests\media\Functional;
-use Drupal\media\Entity\MediaType;
+@trigger_error(__NAMESPACE__ . '\MediaFunctionalTestCreateMediaTypeTrait is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\media\Traits\MediaTypeCreationTrait instead. See https://www.drupal.org/node/2981614.', E_USER_DEPRECATED);
+
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
/**
* Trait with helpers for Media functional tests.
+ *
+ * @deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use
+ * \Drupal\Tests\media\Traits\MediaTypeCreationTrait instead.
+ *
+ * @see https://www.drupal.org/node/2981614
*/
trait MediaFunctionalTestCreateMediaTypeTrait {
+ use MediaTypeCreationTrait {
+ createMediaType as traitCreateMediaType;
+ }
+
/**
* Creates a media type.
*
@@ -22,52 +33,7 @@ trait MediaFunctionalTestCreateMediaTypeTrait {
* A newly created media type.
*/
protected function createMediaType(array $values = [], $source = 'test') {
- if (empty($values['bundle'])) {
- $id = strtolower($this->randomMachineName());
- }
- else {
- $id = $values['bundle'];
- }
- $values += [
- 'id' => $id,
- 'label' => $id,
- 'source' => $source,
- 'source_configuration' => [],
- 'field_map' => [],
- 'new_revision' => FALSE,
- ];
-
- $media_type = MediaType::create($values);
- $status = $media_type->save();
-
- // @todo Rename to assertSame() when #1945040 is done.
- // @see https://www.drupal.org/node/1945040
- $this->assertIdentical(SAVED_NEW, $status, 'Media type was created successfully.');
-
- // Ensure that the source field exists.
- /** @var \Drupal\media\MediaSourceInterface $source */
- $source = $media_type->getSource();
- $source_field = $source->getSourceFieldDefinition($media_type);
- if (!$source_field) {
- $source_field = $source->createSourceField($media_type);
- /** @var \Drupal\field\FieldStorageConfigInterface $storage */
- $storage = $source_field->getFieldStorageDefinition();
- $storage->save();
- $source_field->save();
-
- $media_type
- ->set('source_configuration', [
- 'source_field' => $source_field->getName(),
- ])
- ->save();
- }
-
- // Move source field in form display.
- entity_get_form_display('media', $id, 'default')
- ->setComponent($source_field->getName())
- ->save();
-
- return $media_type;
+ return $this->traitCreateMediaType($source, $values);
}
}
diff --git a/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
index f946789..069390e 100644
--- a/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
+++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
@@ -57,8 +57,8 @@ class MediaOverviewPageTest extends MediaFunctionalTestBase {
$assert_session->pageTextContains('No content available.');
// Create some content for the view.
- $media_type1 = $this->createMediaType();
- $media_type2 = $this->createMediaType();
+ $media_type1 = $this->createMediaType('test');
+ $media_type2 = $this->createMediaType('test');
$media1 = Media::create([
'bundle' => $media_type1->id(),
'name' => 'Media 1',
diff --git a/core/modules/media/tests/src/Functional/MediaRevisionTest.php b/core/modules/media/tests/src/Functional/MediaRevisionTest.php
index 1747d5d..9a8ce5a 100644
--- a/core/modules/media/tests/src/Functional/MediaRevisionTest.php
+++ b/core/modules/media/tests/src/Functional/MediaRevisionTest.php
@@ -25,7 +25,7 @@ class MediaRevisionTest extends MediaFunctionalTestBase {
$media_storage = $this->container->get('entity.manager')->getStorage('media');
// Create a media type and media item.
- $media_type = $this->createMediaType();
+ $media_type = $this->createMediaType('test');
$media = $media_storage->create([
'bundle' => $media_type->id(),
'name' => 'Unnamed',
@@ -80,7 +80,7 @@ class MediaRevisionTest extends MediaFunctionalTestBase {
$uri = 'temporary://foo.txt';
file_put_contents($uri, $this->randomString(128));
- $this->createMediaType(['bundle' => 'file', 'new_revision' => TRUE], 'file');
+ $this->createMediaType('file', ['id' => 'file', 'new_revision' => TRUE]);
// Create a media item.
$this->drupalGet('/media/add/file');
@@ -119,7 +119,7 @@ class MediaRevisionTest extends MediaFunctionalTestBase {
public function testImageMediaRevision() {
$assert = $this->assertSession();
- $this->createMediaType(['bundle' => 'image', 'new_revision' => TRUE], 'image');
+ $this->createMediaType('image', ['id' => 'image', 'new_revision' => TRUE]);
/** @var \Drupal\field\FieldConfigInterface $field */
// Disable the alt text field, because this is not a JavaScript test and
diff --git a/core/modules/media/tests/src/Functional/MediaSettingsTest.php b/core/modules/media/tests/src/Functional/MediaSettingsTest.php
index 850d0e2..ba25392 100644
--- a/core/modules/media/tests/src/Functional/MediaSettingsTest.php
+++ b/core/modules/media/tests/src/Functional/MediaSettingsTest.php
@@ -26,7 +26,7 @@ class MediaSettingsTest extends MediaFunctionalTestBase {
$this->drupalGet('admin/reports/status');
$assert_session->pageTextNotContains('It is potentially insecure to display oEmbed content in a frame');
- $this->createMediaType([], 'oembed:video');
+ $this->createMediaType('oembed:video');
$this->drupalGet('admin/reports/status');
$assert_session->pageTextContains('It is potentially insecure to display oEmbed content in a frame');
diff --git a/core/modules/media/tests/src/Functional/MediaSourceFileTest.php b/core/modules/media/tests/src/Functional/MediaSourceFileTest.php
index 18131a4..fad13dc 100644
--- a/core/modules/media/tests/src/Functional/MediaSourceFileTest.php
+++ b/core/modules/media/tests/src/Functional/MediaSourceFileTest.php
@@ -19,7 +19,7 @@ class MediaSourceFileTest extends MediaFunctionalTestBase {
$page = $session->getPage();
$assert_session = $this->assertSession();
- $media_type = $this->createMediaType([], 'file');
+ $media_type = $this->createMediaType('file');
$media_type_id = $media_type->id();
$this->assertSame('txt doc docx pdf', FieldConfig::load("media.$media_type_id.field_media_file")->get('settings')['file_extensions']);
@@ -43,7 +43,7 @@ class MediaSourceFileTest extends MediaFunctionalTestBase {
* Ensure source field deletion is not possible.
*/
public function testPreventSourceFieldDeletion() {
- $media_type = $this->createMediaType([], 'file');
+ $media_type = $this->createMediaType('file');
$media_type_id = $media_type->id();
$this->drupalGet("admin/structure/media/manage/$media_type_id/fields/media.$media_type_id.field_media_file/delete");
diff --git a/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php b/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php
index 274497a..d4e3566 100644
--- a/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php
+++ b/core/modules/media/tests/src/Functional/MediaTemplateSuggestionsTest.php
@@ -22,8 +22,7 @@ class MediaTemplateSuggestionsTest extends MediaFunctionalTestBase {
* Tests template suggestions from media_theme_suggestions_media().
*/
public function testMediaThemeHookSuggestions() {
- $media_type = $this->createMediaType([
- 'new_revision' => FALSE,
+ $media_type = $this->createMediaType('test', [
'queue_thumbnail_downloads' => FALSE,
]);
diff --git a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php
index c885ea4..f820153 100644
--- a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php
+++ b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php
@@ -43,8 +43,7 @@ class MediaUiFunctionalTest extends MediaFunctionalTestBase {
$page = $session->getPage();
$assert_session = $this->assertSession();
- $media_type = $this->createMediaType([
- 'new_revision' => FALSE,
+ $media_type = $this->createMediaType('test', [
'queue_thumbnail_downloads' => FALSE,
]);
@@ -151,10 +150,10 @@ class MediaUiFunctionalTest extends MediaFunctionalTestBase {
$assert_session = $this->assertSession();
// Tests and creates the first media type.
- $first_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]);
+ $first_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]);
// Test and create a second media type.
- $second_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]);
+ $second_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]);
// Test if media/add displays two media type options.
$this->drupalGet('media/add');
@@ -284,7 +283,10 @@ class MediaUiFunctionalTest extends MediaFunctionalTestBase {
$create_media_types[] = "media_type_$id";
$permissions[] = "create media_type_$id media";
}
- $this->createMediaType(['bundle' => "media_type_$id"]);
+ $this->createMediaType('test', [
+ 'id' => "media_type_$id",
+ 'label' => "media_type_$id",
+ ]);
$media_types["media_type_$id"] = "media_type_$id";
}
@@ -513,7 +515,7 @@ class MediaUiFunctionalTest extends MediaFunctionalTestBase {
$this->container->get('module_installer')->uninstall(['views']);
// Create a media type and media item.
- $media_type = $this->createMediaType();
+ $media_type = $this->createMediaType('test');
$media = $media_storage->create([
'bundle' => $media_type->id(),
'name' => 'Unnamed',
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
index 0549d2d..30b6204 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
@@ -39,7 +39,7 @@ class MediaDisplayTest extends MediaJavascriptTestBase {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
- $media_type = $this->createMediaType();
+ $media_type = $this->createMediaType('test');
// Create a media item.
$media = Media::create([
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php b/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php
index 7fc26ec..e84db38 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php
@@ -3,8 +3,8 @@
namespace Drupal\Tests\media\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
-use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
use Drupal\Tests\media\Functional\MediaFunctionalTestTrait;
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
/**
* Base class for Media functional JavaScript tests.
@@ -12,7 +12,7 @@ use Drupal\Tests\media\Functional\MediaFunctionalTestTrait;
abstract class MediaJavascriptTestBase extends JavascriptTestBase {
use MediaFunctionalTestTrait;
- use MediaFunctionalTestCreateMediaTypeTrait;
+ use MediaTypeCreationTrait;
/**
* Modules to enable.
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
index 0116305..7af61fc 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
@@ -191,7 +191,7 @@ class MediaUiJavascriptTest extends MediaJavascriptTestBase {
// Test that the system for preventing the deletion of media types works
// (they cannot be deleted if there is media content of that type/bundle).
- $media_type2 = $this->createMediaType();
+ $media_type2 = $this->createMediaType('test');
$label2 = $media_type2->label();
$media = Media::create(['name' => 'lorem ipsum', 'bundle' => $media_type2->id()]);
$media->save();
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php
index df71943..3be7b1a 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php
@@ -22,7 +22,7 @@ class MediaViewsWizardTest extends MediaJavascriptTestBase {
$page = $session->getPage();
$assert_session = $this->assertSession();
- $this->createMediaType();
+ $this->createMediaType('test');
$view_id = strtolower($this->randomMachineName(16));
$this->drupalGet('admin/structure/views/add');
diff --git a/core/modules/media/tests/src/Kernel/MediaKernelTestBase.php b/core/modules/media/tests/src/Kernel/MediaKernelTestBase.php
index c00dc3d..1c6a879 100644
--- a/core/modules/media/tests/src/Kernel/MediaKernelTestBase.php
+++ b/core/modules/media/tests/src/Kernel/MediaKernelTestBase.php
@@ -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.
*
@@ -78,37 +80,6 @@ abstract class MediaKernelTestBase extends KernelTestBase {
}
/**
- * 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.
*
* @param string $filename
diff --git a/core/modules/media/tests/src/Traits/MediaTypeCreationTrait.php b/core/modules/media/tests/src/Traits/MediaTypeCreationTrait.php
new file mode 100644
index 0000000..8437507
--- /dev/null
+++ b/core/modules/media/tests/src/Traits/MediaTypeCreationTrait.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Drupal\Tests\media\Traits;
+
+use Drupal\media\Entity\MediaType;
+
+/**
+ * Provides methods to create a media type from given values.
+ *
+ * This trait is meant to be used only by test classes.
+ */
+trait MediaTypeCreationTrait {
+
+ /**
+ * Create a media type for a source plugin.
+ *
+ * @param string $source_plugin_id
+ * The media source plugin ID.
+ * @param mixed[] $values
+ * (optional) Additional values for the media type entity:
+ * - id: The ID of the media type. If none is provided, a random value will
+ * be used.
+ * - label: The human-readable label of the media type. If none is provided,
+ * a random value will be used.
+ * - bundle: (deprecated) The ID of the media type, for backwards
+ * compatibility purposes. Use 'id' instead.
+ * See \Drupal\media\MediaTypeInterface and \Drupal\media\Entity\MediaType
+ * for full documentation of the media type properties.
+ *
+ * @return \Drupal\media\MediaTypeInterface
+ * A media type.
+ *
+ * @see \Drupal\media\MediaTypeInterface
+ * @see \Drupal\media\Entity\MediaType
+ */
+ protected function createMediaType($source_plugin_id, array $values = []) {
+ if (isset($values['bundle'])) {
+ @trigger_error('Setting the "bundle" key when creating a test media type is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Set the "id" key instead. See https://www.drupal.org/node/2981614.', E_USER_DEPRECATED);
+ $values['id'] = $values['bundle'];
+ unset($values['bundle']);
+ }
+
+ $values += [
+ 'id' => $this->randomMachineName(),
+ 'label' => $this->randomString(),
+ 'source' => $source_plugin_id,
+ ];
+
+ /** @var \Drupal\media\MediaTypeInterface $media_type */
+ $media_type = MediaType::create($values);
+ $this->assertSame(SAVED_NEW, $media_type->save());
+
+ $source = $media_type->getSource();
+ $source_field = $source->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();
+
+ $source_configuration = $source->getConfiguration();
+ $source_configuration['source_field'] = $source_field->getName();
+ $source->setConfiguration($source_configuration);
+
+ $this->assertSame(SAVED_UPDATED, $media_type->save());
+
+ // Add the source field to the form display for the media type.
+ $form_display = entity_get_form_display('media', $media_type->id(), 'default');
+ $source->prepareFormDisplay($media_type, $form_display);
+ $form_display->save();
+
+ return $media_type;
+ }
+
+}
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
index 095de33..1bcedcf 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
@@ -16,7 +16,7 @@ use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
-use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\user\Entity\User;
/**
@@ -27,7 +27,7 @@ use Drupal\user\Entity\User;
class ContentEntityTest extends KernelTestBase {
use EntityReferenceTestTrait;
- use MediaFunctionalTestCreateMediaTypeTrait;
+ use MediaTypeCreationTrait;
/**
* {@inheritdoc}
@@ -339,12 +339,11 @@ class ContentEntityTest extends KernelTestBase {
public function testMediaSource() {
$values = [
'id' => 'image',
- 'bundle' => 'image',
'label' => 'Image',
'source' => 'test',
'new_revision' => FALSE,
];
- $media_type = $this->createMediaType($values);
+ $media_type = $this->createMediaType('test', $values);
$media = Media::create([
'name' => 'Foo media',
'uid' => $this->user->id(),