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 / Functional / BundleTest.php
index ef3403882a93075b85ff26ab9364f3f082a0ed40..ece13725ce52b5bb7ead41ad0ae1f988124b32c5 100644 (file)
@@ -2,7 +2,8 @@
 
 namespace Drupal\Tests\video_embed_media\Functional;
 
-use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\media\Functional\MediaFunctionalTestBase;
+use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
 
 /**
@@ -10,7 +11,7 @@ use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
  *
  * @group video_embed_media
  */
-class BundleTest extends BrowserTestBase {
+class BundleTest extends MediaFunctionalTestBase {
 
   use AdminUserTrait;
 
@@ -22,26 +23,36 @@ class BundleTest extends BrowserTestBase {
   public static $modules = [
     'video_embed_field',
     'video_embed_media',
-    'media_entity',
-    'field_ui',
-    'node',
-    'image',
   ];
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+  }
+
   /**
    * Test the dialog form.
    */
   public function testMediaBundleCreation() {
-    $this->drupalLogin($this->createAdminUser());
+    $this->drupalLogin($this->adminUser);
 
-    // Create a new media bundle.
-    $this->drupalGet('admin/structure/media/add');
-    $this->submitForm([
-      'label' => 'Video Bundle',
-      'id' => 'video_bundle',
-      'type' => 'video_embed_field',
-    ], t('Save media bundle'));
-    $this->assertSession()->pageTextContains('The media bundle Video Bundle has been added.');
+    // Create bundle and modify form display.
+    $media_type = $this->createMediaType(['bundle' => 'video_bundle'], 'video_embed_field');
+    $source = $media_type->getSource();
+    $source_field = $source->getSourceFieldDefinition($media_type);
+    if ($source_field->isDisplayConfigurable('form')) {
+      // Use the default widget and settings.
+      $component = \Drupal::service('plugin.manager.field.widget')
+        ->prepareConfiguration('video_embed_field', []);
+
+      // @todo Replace entity_get_form_display() when #2367933 is done.
+      // https://www.drupal.org/node/2872159.
+      entity_get_form_display('media', $media_type->id(), 'default')
+        ->setComponent($source_field->getName(), $component)
+        ->save();
+    }
 
     // Ensure the video field is added to the media entity.
     $this->drupalGet('admin/structure/media/manage/video_bundle/fields');
@@ -56,34 +67,6 @@ class BundleTest extends BrowserTestBase {
     ], 'Save');
     // We should see the video thumbnail on the media page.
     $this->assertContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());
-
-    // Add another field and change the configured media field.
-    $this->drupalGet('admin/structure/media/manage/video_bundle/fields/add-field');
-    $this->submitForm([
-      'new_storage_type' => 'video_embed_field',
-      'label' => 'New Video Field',
-      'field_name' => 'new_video_field',
-    ], 'Save and continue');
-    $this->submitForm([], t('Save field settings'));
-    $this->submitForm([], t('Save settings'));
-
-    // Update video source field.
-    $this->drupalGet('admin/structure/media/manage/video_bundle');
-    $this->submitForm([
-      'type_configuration[video_embed_field][source_field]' => 'field_new_video_field',
-    ], t('Save media bundle'));
-
-    // Create a video, populating both video URL fields.
-    $this->drupalGet('media/add/video_bundle');
-    $this->submitForm([
-      'name[0][value]' => 'Another Video!',
-      'field_media_video_embed_field[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
-      'field_new_video_field[0][value]' => 'https://www.youtube.com/watch?v=gnERPdAiuSo',
-    ], t('Save'));
-
-    // We should see the newly configured video thumbnail, but not the original.
-    $this->assertContains('video_thumbnails/gnERPdAiuSo.jpg', $this->getSession()->getPage()->getHtml());
-    $this->assertNotContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());
   }
 
 }