Skip to content
Snippets Groups Projects
Commit 4b95aa76 authored by Gabor Hojtsy's avatar Gabor Hojtsy
Browse files

Issue #2894270 by xjm, seanB, chr.fritsch, Wim Leers: Users unable to add an...

Issue #2894270 by xjm, seanB, chr.fritsch, Wim Leers: Users unable to add an extension to the file upload field
parent 6002539d
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ settings:
display_field: false
display_default: false
module: file
locked: true
locked: false
cardinality: 1
translatable: true
indexes: { }
......
......@@ -24,7 +24,7 @@ settings:
display_default: false
uri_scheme: public
module: image
locked: true
locked: false
cardinality: 1
translatable: true
indexes: { }
......
......@@ -240,7 +240,6 @@ protected function createSourceFieldStorage() {
'entity_type' => 'media',
'field_name' => $this->getSourceFieldName(),
'type' => reset($this->pluginDefinition['allowed_field_types']),
'locked' => TRUE,
]);
}
......
......@@ -318,8 +318,8 @@ public function save(array $form, FormStateInterface $form_state) {
$source_field = $source->createSourceField($media_type);
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = $source_field->getFieldStorageDefinition();
if ($storage->isNew() || !$storage->isLocked()) {
$storage->setLocked(TRUE)->save();
if ($storage->isNew()) {
$storage->save();
}
$source_field->save();
......
......@@ -51,7 +51,7 @@ protected function createMediaType(array $values = [], $source = 'test') {
$source_field = $source->createSourceField($media_type);
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = $source_field->getFieldStorageDefinition();
$storage->setLocked(TRUE)->save();
$storage->save();
$source_field->save();
$media_type
......
<?php
namespace Drupal\Tests\media\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\media\Entity\MediaType;
/**
* Tests the file media source.
*
* @group media
*/
class MediaSourceFileTest extends MediaFunctionalTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// We need to test without any default configuration in place.
// @TODO: Remove this as part of https://www.drupal.org/node/2883813.
MediaType::load('file')->delete();
}
/**
* Test 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']);
}
}
......@@ -90,7 +90,7 @@ public function testMediaTypes() {
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = $source_field->getFieldStorageDefinition();
$this->assertFalse($storage->isNew(), 'Source field storage definition was saved.');
$this->assertTrue($storage->isLocked(), 'Source field storage definition was locked.');
$this->assertFalse($storage->isLocked(), 'Source field storage definition was not locked.');
/** @var \Drupal\media\MediaTypeInterface $media_type_storage */
$media_type_storage = $this->container->get('entity_type.manager')->getStorage('media_type');
......
......@@ -352,7 +352,7 @@ public function testSourceFieldCreation() {
// Test field storage.
$this->assertTrue($field_storage->isNew(), 'Field storage is saved automatically.');
$this->assertTrue($field_storage->isLocked(), 'Field storage is not locked.');
$this->assertFalse($field_storage->isLocked(), 'Field storage is not locked.');
$this->assertEquals('string', $field_storage->getType(), 'Field is not of correct type.');
$this->assertEquals('field_media_test_1', $field_storage->getName(), 'Incorrect field name is used.');
$this->assertEquals('media', $field_storage->getTargetEntityTypeId(), 'Field is not targeting media entities.');
......@@ -387,7 +387,7 @@ public function testSourceFieldCreation() {
// Test field storage.
$this->assertTrue($field_storage->isNew(), 'Field storage is saved automatically.');
$this->assertTrue($field_storage->isLocked(), 'Field storage is not locked.');
$this->assertFalse($field_storage->isLocked(), 'Field storage is not locked.');
$this->assertEquals('string_long', $field_storage->getType(), 'Field is of incorrect type.');
$this->assertEquals('field_media_test_constraints_1', $field_storage->getName(), 'Incorrect field name is used.');
$this->assertEquals('media', $field_storage->getTargetEntityTypeId(), 'Field is not targeting media entities.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment