public function FileUploadTest::testFileUploadWidget in Lightning Media 8.3
Tests that the widget form is built properly.
File
- tests/
src/ Kernel/ FileUploadTest.php, line 44
Class
- FileUploadTest
- Contains low-level tests of the FileUpload entity browser widget.
Namespace
Drupal\Tests\lightning_media\KernelCode
public function testFileUploadWidget() {
if (version_compare(PHP_VERSION, '7.4', '<')) {
$this
->markTestSkipped('This test requires PHP 7.4 or later.');
}
$this
->installEntitySchema('media');
$this
->installSchema('system', 'key_value_expire');
$dir = $this->container
->get('extension.list.module')
->getPath('lightning_media');
$storage = new FileStorage($dir . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY);
$data = $storage
->read('field.storage.media.field_media_in_library');
FieldStorageConfig::create($data)
->save();
$browser = $storage
->read('entity_browser.browser.media_browser');
/** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
$browser = EntityBrowser::create($browser);
$browser
->save();
// There needs to be at least one file-based media type to test with.
$this
->createMediaType('image');
$this
->setUpCurrentUser([], [
'create media',
]);
// If access to the widget is not allowed, this test will falsely pass.
$widget_id = '044d2af7-314b-4830-8b6d-64896bbb861e';
$widget = $browser
->getWidget($widget_id);
$this
->assertTrue($widget
->access()
->isAllowed());
$form = EntityBrowserForm::create($this->container);
$form
->setEntityBrowser($browser);
$form_state = new FormState();
$form_state
->set('entity_browser_current_widget', $widget_id);
$this->container
->get('form_builder')
->getForm($form, $form_state);
// This test is looking for an error that happens during getForm() on PHP
// 7.4 and up. If we get this far, we've passed.
$this
->assertTrue(TRUE);
}