FileUploadTest.php in Lightning Media 8.3
File
tests/src/Kernel/FileUploadTest.php
View source
<?php
namespace Drupal\Tests\lightning_media\Kernel;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Form\FormState;
use Drupal\entity_browser\Entity\EntityBrowser;
use Drupal\entity_browser\Form\EntityBrowserForm;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
class FileUploadTest extends KernelTestBase {
use MediaTypeCreationTrait;
use UserCreationTrait;
protected static $modules = [
'entity_browser',
'field',
'file',
'image',
'lightning_media',
'media',
'system',
'user',
];
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');
$browser = EntityBrowser::create($browser);
$browser
->save();
$this
->createMediaType('image');
$this
->setUpCurrentUser([], [
'create media',
]);
$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
->assertTrue(TRUE);
}
}
Classes
Name |
Description |
FileUploadTest |
Contains low-level tests of the FileUpload entity browser widget. |