Version 1
[yaffs-website] / web / modules / contrib / video_embed_field / modules / video_embed_media / tests / src / Functional / UpgradePathTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_media\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
7
8 /**
9  * Test the upgrade path from media_entity_embedded_video.
10  *
11  * @group video_embed_media
12  */
13 class UpgradePathTest extends BrowserTestBase {
14
15   use AdminUserTrait;
16
17   /**
18    * Disable strict checking because we are installing MEEV.
19    *
20    * @var bool
21    */
22   protected $strictConfigSchema = FALSE;
23
24   /**
25    * Modules to install.
26    *
27    * @var array
28    */
29   public static $modules = [
30     'video_embed_field',
31     'media_entity_embeddable_video',
32     'media_entity',
33     'field_ui',
34     'node',
35     'image',
36     'text',
37   ];
38
39   /**
40    * Test the upgrade path.
41    */
42   public function testMediaBundleCreation() {
43     $this->drupalLogin($this->createAdminUser());
44
45     // Create a media_entity_embeddable_video bundle and field.
46     $this->drupalGet('admin/structure/media/add');
47     $this->submitForm([
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');
54     $this->submitForm([
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');
64     $this->submitForm([
65       'field_video_text_field[0][value]' => 'https://www.youtube.com/watch?v=gnERPdAiuSo',
66       'name[0][value]' => 'Test Media Entity',
67     ], t('Save'));
68
69     // Install video_embed_field.
70     $this->container->get('module_installer')->install(['video_embed_media'], TRUE);
71
72     $this->assertUpgradeComplete();
73
74     // Uninstall the module and ensure everything is still okay.
75     $this->drupalGet('admin/modules/uninstall');
76     $this->submitForm([
77       'uninstall[media_entity_embeddable_video]' => TRUE,
78     ], t('Uninstall'));
79     $this->submitForm([], 'Uninstall');
80
81     $this->assertUpgradeComplete();
82   }
83
84   /**
85    * Assert the upgrade was successful.
86    */
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.');
94   }
95
96 }