diff --git a/src/MediaTypeSourceFieldTrait.php b/src/MediaTypeSourceFieldTrait.php index e7094fe..f2afdbb 100644 --- a/src/MediaTypeSourceFieldTrait.php +++ b/src/MediaTypeSourceFieldTrait.php @@ -67,6 +67,7 @@ trait MediaTypeSourceFieldTrait { */ protected function sourceFieldConfigurationForm(array $form, FormStateInterface $form_state) { $source_field_info = $this->sourceFieldInfo(); + $options = []; $allowed_field_types = $source_field_info['allowed_types']; /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ diff --git a/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml b/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml index 6ff7e14..257c840 100644 --- a/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml +++ b/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml @@ -5,3 +5,6 @@ media_entity.bundle.type.test_type: test_config_value: type: string label: 'Test config value' + source_field: + type: string + label: 'Source field' diff --git a/tests/src/FunctionalJavascript/BundleCreationTest.php b/tests/src/FunctionalJavascript/BundleCreationTest.php index 149a261..fd701a6 100644 --- a/tests/src/FunctionalJavascript/BundleCreationTest.php +++ b/tests/src/FunctionalJavascript/BundleCreationTest.php @@ -2,9 +2,6 @@ namespace Drupal\Tests\media_entity\FunctionalJavascript; -use Drupal\field\Entity\FieldStorageConfig; -use Drupal\media_entity_test_type\Plugin\MediaEntity\Type\TestType; - /** * Tests the media bundle creation. * @@ -22,13 +19,6 @@ class BundleCreationTest extends MediaEntityJavascriptTestBase { ]; /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - } - - /** * Tests the media bundle creation form. */ public function testBundleCreationFormWithDefaultField() { @@ -39,22 +29,37 @@ class BundleCreationTest extends MediaEntityJavascriptTestBase { // Fill in a label to the bundle. $page->fillField('label', 'Foo bundle'); + // Wait for machine name generation. Default: waitUntilVisible(), does not + // work properly. + $this->getSession() + ->wait(5000, "jQuery('.machine-name-value').text() === 'foo_bundle'"); // 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(); -$this->saveHtmlOutput(); // @TODO Delete me before committing. // Make sure the checkbox for creating the source field is there and save. - $this->assertSession()->checkboxChecked('type_configuration[test_type][create_source_field]'); + $this->assertSession() + ->checkboxChecked('type_configuration[test_type][create_source_field]'); $page->pressButton('Save media bundle'); -$this->saveHtmlOutput(); // @TODO Delete me before committing. // Check whether the source field was correctly created. - // @TODO Finish me. - $this->assertNotNull(FieldStorageConfig::loadByName('media', TestType::MEDIA_ENTITY_TEST_TYPE_DEFAULT_FIELD_NAME)); + $this->drupalGet('admin/structure/media/manage/foo_bundle/fields'); + + // Check 2nd column of first data row, to be machine name for field name. + $this->assertSession() + ->elementContains('xpath', '(//table[@id="field-overview"]//tr)[2]//td[2]', 'field_media_test_type'); + // Check 3rd column of first data row, to be correct field type. + $this->assertSession() + ->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->assertSession() + ->fieldValueEquals('type_configuration[test_type][source_field]', 'field_media_test_type'); } }