function MediaSourceTest::testSourceConfigurationSubmit
Tests configuration form submit handler on the base media source plugin.
File
- 
              core/modules/ media/ tests/ src/ Kernel/ MediaSourceTest.php, line 514 
Class
- MediaSourceTest
- Tests media source plugins related logic.
Namespace
Drupal\Tests\media\KernelCode
public function testSourceConfigurationSubmit() {
  /** @var \Drupal\media\MediaSourceManager $manager */
  $manager = $this->container
    ->get('plugin.manager.media.source');
  $form = [];
  $form_state = new FormState();
  $form_state->setValues([
    'test_config_value' => 'Somewhere over the rainbow.',
  ]);
  /** @var \Drupal\media\MediaSourceInterface $source */
  $source = $manager->createInstance('test', []);
  $source->submitConfigurationForm($form, $form_state);
  $expected = [
    'source_field' => 'field_media_test_1',
    'test_config_value' => 'Somewhere over the rainbow.',
  ];
  $this->assertSame($expected, $source->getConfiguration(), 'Submitted values were saved correctly.');
  // Try to save a NULL value.
  $form_state->setValue('test_config_value', NULL);
  $source->submitConfigurationForm($form, $form_state);
  $expected['test_config_value'] = NULL;
  $this->assertSame($expected, $source->getConfiguration(), 'Submitted values were saved correctly.');
  // Make sure that the config keys are determined correctly even if the
  // existing value is NULL.
  $form_state->setValue('test_config_value', 'Somewhere over the rainbow.');
  $source->submitConfigurationForm($form, $form_state);
  $expected['test_config_value'] = 'Somewhere over the rainbow.';
  $this->assertSame($expected, $source->getConfiguration(), 'Submitted values were saved correctly.');
  // Make sure that a non-relevant value will be skipped.
  $form_state->setValue('not_relevant', 'Should not be saved in the plugin.');
  $source->submitConfigurationForm($form, $form_state);
  $this->assertSame($expected, $source->getConfiguration(), 'Submitted values were saved correctly.');
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
