MediaSourceFileTest.php in Drupal 10
File
core/modules/media/tests/src/Functional/MediaSourceFileTest.php
View source
<?php
namespace Drupal\Tests\media\Functional;
use Drupal\field\Entity\FieldConfig;
class MediaSourceFileTest extends MediaFunctionalTestBase {
protected $defaultTheme = 'stark';
public function testSourceFieldSettingsEditing() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$media_type = $this
->createMediaType('file');
$media_type_id = $media_type
->id();
$this
->assertSame('txt doc docx pdf', FieldConfig::load("media.{$media_type_id}.field_media_file")
->get('settings')['file_extensions']);
$this
->drupalGet("admin/structure/media/manage/{$media_type_id}/fields/media.{$media_type_id}.field_media_file");
$assert_session
->fieldExists('Allowed file extensions');
$page
->fillField('settings[file_extensions]', 'txt, doc, docx, pdf, odt');
$page
->pressButton('Save settings');
$this
->drupalGet("admin/structure/media/manage/{$media_type_id}/fields/media.{$media_type_id}.field_media_file");
$assert_session
->fieldValueEquals('settings[file_extensions]', 'txt, doc, docx, pdf, odt');
$this
->assertSame('txt doc docx pdf odt', FieldConfig::load("media.{$media_type_id}.field_media_file")
->get('settings')['file_extensions']);
}
public function testPreventSourceFieldDeletion() {
$media_type = $this
->createMediaType('file');
$media_type_id = $media_type
->id();
$this
->drupalGet("admin/structure/media/manage/{$media_type_id}/fields/media.{$media_type_id}.field_media_file/delete");
$this
->assertSession()
->statusCodeEquals(403);
}
}