X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmedia%2Ftests%2Fsrc%2FFunctionalJavascript%2FMediaTypeCreationTest.php;h=42e3511f315b9d1b8a94f43e89663ecd4d932540;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=61fe2a9c55e169cb838095be09485d49ddd833e5;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php b/web/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php index 61fe2a9c5..42e3511f3 100644 --- a/web/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php +++ b/web/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php @@ -12,9 +12,9 @@ use Drupal\Component\Utility\Html; class MediaTypeCreationTest extends MediaJavascriptTestBase { /** - * Tests the media type creation form. + * Tests the source field behavior on the add media type form. */ - public function testMediaTypeCreationFormWithDefaultField() { + public function testSourceChangeOnMediaTypeCreationForm() { $session = $this->getSession(); $page = $session->getPage(); $assert_session = $this->assertSession(); @@ -26,17 +26,58 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase { // Fill in a label to the media type. $page->fillField('label', $label); - // Wait for machine name generation. Default: waitUntilVisible(), does not - // work properly. - $session->wait(5000, "jQuery('.machine-name-value').text() === '{$mediaTypeMachineName}'"); + $this->assertNotEmpty( + $assert_session->waitForElementVisible('css', '.machine-name-value') + ); // Select the media source used by our media type. + $assert_session->selectExists('Media source')->selectOption('test_different_displays'); + $this->assertNotEmpty( + $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]') + ); + + // Change the media source. + $assert_session->selectExists('Media source')->selectOption('test'); + $this->assertNotEmpty( + $assert_session->waitForElement('css', 'fieldset[data-drupal-selector="edit-source-configuration"] .fieldset-wrapper .placeholder:contains("Text (plain)")') + ); + + $page->pressButton('Save'); + + // Check that source can not be changed anymore. + $this->drupalGet("admin/structure/media/manage/{$mediaTypeMachineName}"); + $assert_session->pageTextContains('The media source cannot be changed after the media type is created'); + $assert_session->fieldDisabled('Media source'); + } + + /** + * Tests the media type creation form. + */ + public function testMediaTypeCreationFormWithDefaultField() { + $session = $this->getSession(); + $page = $session->getPage(); + $assert_session = $this->assertSession(); + + $label = 'Type with Default Field'; + $mediaTypeMachineName = str_replace(' ', '_', strtolower($label)); + + $this->drupalGet('admin/structure/media/add'); + + // Select the media source used by our media type. Do this before setting + // the label or machine name in order to guard against the regression in + // https://www.drupal.org/project/drupal/issues/2557299. $assert_session->fieldExists('Media source'); $assert_session->optionExists('Media source', 'test'); $page->selectFieldOption('Media source', 'test'); $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]'); $this->assertNotEmpty($result); + // Fill in a label to the media type. + $page->fillField('label', $label); + // Wait for machine name generation. Default: waitUntilVisible(), does not + // work properly. + $session->wait(5000, "jQuery('.machine-name-value').text() === '{$mediaTypeMachineName}'"); + $page->pressButton('Save'); // Check whether the source field was correctly created. @@ -97,11 +138,12 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase { // Create a new media type, which should create a new field we can reuse. $this->drupalGet('/admin/structure/media/add'); - $page->fillField('label', 'Pastafazoul'); - $session->wait(5000, "jQuery('.machine-name-value').text() === 'pastafazoul'"); + // Choose the source plugin before setting the label and machine name. $page->selectFieldOption('Media source', 'test'); $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]'); $this->assertNotEmpty($result); + $page->fillField('label', 'Pastafazoul'); + $session->wait(5000, "jQuery('.machine-name-value').text() === 'pastafazoul'"); $page->pressButton('Save'); $label = 'Type reusing Default Field'; @@ -109,14 +151,8 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase { $this->drupalGet('admin/structure/media/add'); - // Fill in a label to the media type. - $page->fillField('label', $label); - - // Wait for machine name generation. Default: waitUntilVisible(), does not - // work properly. - $session->wait(5000, "jQuery('.machine-name-value').text() === '{$mediaTypeMachineName}'"); - - // Select the media source used by our media type. + // Select the media source used by our media type. Do this before setting + // the label and machine name. $assert_session->fieldExists('Media source'); $assert_session->optionExists('Media source', 'test'); $page->selectFieldOption('Media source', 'test'); @@ -124,6 +160,14 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase { $this->assertNotEmpty($result); // Select the existing field for re-use. $page->selectFieldOption('source_configuration[source_field]', 'field_media_test'); + + // Fill in a label to the media type. + $page->fillField('label', $label); + + // Wait for machine name generation. Default: waitUntilVisible(), does not + // work properly. + $session->wait(5000, "jQuery('.machine-name-value').text() === '{$mediaTypeMachineName}'"); + $page->pressButton('Save'); // Check that no new fields were created.