class MediaSourceFileTest in Drupal 10
Same name in this branch
- 10 core/modules/media/tests/src/Functional/MediaSourceFileTest.php \Drupal\Tests\media\Functional\MediaSourceFileTest
- 10 core/modules/media/tests/src/FunctionalJavascript/MediaSourceFileTest.php \Drupal\Tests\media\FunctionalJavascript\MediaSourceFileTest
- 10 core/modules/media/tests/src/Kernel/MediaSourceFileTest.php \Drupal\Tests\media\Kernel\MediaSourceFileTest
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Functional/MediaSourceFileTest.php \Drupal\Tests\media\Functional\MediaSourceFileTest
- 9 core/modules/media/tests/src/Functional/MediaSourceFileTest.php \Drupal\Tests\media\Functional\MediaSourceFileTest
Tests the file media source.
@group media
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\media\Functional\MediaFunctionalTestBase uses MediaFunctionalTestTrait, MediaTypeCreationTrait
- class \Drupal\Tests\media\Functional\MediaSourceFileTest
- class \Drupal\Tests\media\Functional\MediaFunctionalTestBase uses MediaFunctionalTestTrait, MediaTypeCreationTrait
Expanded class hierarchy of MediaSourceFileTest
File
- core/
modules/ media/ tests/ src/ Functional/ MediaSourceFileTest.php, line 12
Namespace
Drupal\Tests\media\FunctionalView source
class MediaSourceFileTest extends MediaFunctionalTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that it's possible to change the allowed file extensions.
*/
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");
// File extension field exists.
$assert_session
->fieldExists('Allowed file extensions');
// Add another extension.
$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");
// Verify that new extension is present.
$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']);
}
/**
* Ensure source field deletion is not possible.
*/
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);
}
}