3 namespace Drupal\Tests\video_embed_media\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
9 * Test the upgrade path from media_entity_embedded_video.
11 * @group video_embed_media
13 class UpgradePathTest extends BrowserTestBase {
18 * Disable strict checking because we are installing MEEV.
22 protected $strictConfigSchema = FALSE;
29 public static $modules = [
31 'media_entity_embeddable_video',
40 * Test the upgrade path.
42 public function testMediaBundleCreation() {
43 $this->drupalLogin($this->createAdminUser());
45 // Create a media_entity_embeddable_video bundle and field.
46 $this->drupalGet('admin/structure/media/add');
48 'label' => 'embeddable Video Bundle',
49 'id' => 'embeddable_bundle',
50 'type' => 'embeddable_video',
51 ], 'Save media bundle');
52 $this->assertSession()->pageTextContains('The media bundle embeddable Video Bundle has been added.');
53 $this->drupalGet('admin/structure/media/manage/embeddable_bundle/fields/add-field');
55 'new_storage_type' => 'string',
56 'label' => 'Video Text Field',
57 'field_name' => 'video_text_field',
58 ], t('Save and continue'));
59 $this->submitForm([], t('Save field settings'));
60 $this->submitForm([], t('Save settings'));
61 $this->drupalGet('admin/structure/media/manage/embeddable_bundle');
62 $this->submitForm(['type_configuration[embeddable_video][source_field]' => 'field_video_text_field'], t('Save media bundle'));
63 $this->drupalGet('media/add/embeddable_bundle');
65 'field_video_text_field[0][value]' => 'https://www.youtube.com/watch?v=gnERPdAiuSo',
66 'name[0][value]' => 'Test Media Entity',
69 // Install video_embed_field.
70 $this->container->get('module_installer')->install(['video_embed_media'], TRUE);
72 $this->assertUpgradeComplete();
74 // Uninstall the module and ensure everything is still okay.
75 $this->drupalGet('admin/modules/uninstall');
77 'uninstall[media_entity_embeddable_video]' => TRUE,
79 $this->submitForm([], 'Uninstall');
81 $this->assertUpgradeComplete();
85 * Assert the upgrade was successful.
87 protected function assertUpgradeComplete() {
88 // Ensure the new type is selected.
89 $this->drupalGet('admin/structure/media/manage/embeddable_bundle');
90 $this->assertTrue(!empty($this->getSession()->getPage()->find('xpath', '//option[@value="video_embed_field" and @selected="selected"]')), 'The media type was updated.');
91 // Ensure the media entity has updated values.
92 $this->drupalGet('media/1/edit');
93 $this->assertEquals($this->getSession()->getPage()->find('css', 'input[name="field_video_text_field[0][value]"]')->getValue(), 'https://www.youtube.com/watch?v=gnERPdAiuSo', 'Field values were copied.');