diff --git a/tests/src/FunctionalJavascript/BundleCreationTest.php b/tests/src/FunctionalJavascript/BundleCreationTest.php index fd701a6..e27aeae 100644 --- a/tests/src/FunctionalJavascript/BundleCreationTest.php +++ b/tests/src/FunctionalJavascript/BundleCreationTest.php @@ -22,17 +22,18 @@ class BundleCreationTest extends MediaEntityJavascriptTestBase { * Tests the media bundle creation form. */ public function testBundleCreationFormWithDefaultField() { - - $page = $this->getSession()->getPage(); + $label = 'Bundle with Default Field'; + $bundleMachineName = str_replace(' ', '_', strtolower($label)); $this->drupalGet('admin/structure/media/add'); + $page = $this->getSession()->getPage(); // Fill in a label to the bundle. - $page->fillField('label', 'Foo bundle'); + $page->fillField('label', $label); // Wait for machine name generation. Default: waitUntilVisible(), does not // work properly. $this->getSession() - ->wait(5000, "jQuery('.machine-name-value').text() === 'foo_bundle'"); + ->wait(5000, "jQuery('.machine-name-value').text() === '{$bundleMachineName}'"); // Select our test bundle type. $this->assertSession()->fieldExists('Type provider'); @@ -46,7 +47,7 @@ class BundleCreationTest extends MediaEntityJavascriptTestBase { $page->pressButton('Save media bundle'); // Check whether the source field was correctly created. - $this->drupalGet('admin/structure/media/manage/foo_bundle/fields'); + $this->drupalGet("admin/structure/media/manage/{$bundleMachineName}/fields"); // Check 2nd column of first data row, to be machine name for field name. $this->assertSession() @@ -56,10 +57,44 @@ class BundleCreationTest extends MediaEntityJavascriptTestBase { ->elementTextContains('xpath', '(//table[@id="field-overview"]//tr)[2]//td[3]', 'Text (plain)'); // Check that the source field is correctly assigned to media bundle. - $this->drupalGet('admin/structure/media/manage/foo_bundle'); + $this->drupalGet("admin/structure/media/manage/{$bundleMachineName}"); $this->assertSession() ->fieldValueEquals('type_configuration[test_type][source_field]', 'field_media_test_type'); } + /** + * Test creation of media bundle without default field. + */ + public function testBundleCreationWithoutDefaultField() { + $label = 'Bundle without Default Field'; + $bundleMachineName = str_replace(' ', '_', strtolower($label)); + + $this->drupalGet('admin/structure/media/add'); + $page = $this->getSession()->getPage(); + + // Fill in a label to the bundle. + $page->fillField('label', 'Bundle without Default Field'); + + // Wait for machine name generation. Default: waitUntilVisible(), does not + // work properly. + $this->getSession() + ->wait(5000, "jQuery('.machine-name-value').text() === '{$bundleMachineName}'"); + + // Select our test bundle type. + $this->assertSession()->fieldExists('Type provider'); + $this->assertSession()->optionExists('Type provider', 'test_type'); + $page->selectFieldOption('Type provider', 'test_type'); + $this->waitForAjaxToFinish(); + + // Un-check creation of default source field. + $page->uncheckField('type_configuration[test_type][create_source_field]'); + $page->pressButton('Save media bundle'); + + // Check that there are not fields created. + $this->drupalGet("admin/structure/media/manage/{$bundleMachineName}/fields"); + $this->assertSession() + ->elementsCount('xpath', '//*[text()="No fields are present yet."]', 1); + } + }