updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for file_module_test module.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class FileModuleTestForm extends FormBase {
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -4,3 +4,9 @@ file.test:
|
||||
_form: 'Drupal\file_test\Form\FileTestForm'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
file.save_upload_from_form_test:
|
||||
path: '/file-test/save_upload_from_form_test'
|
||||
defaults:
|
||||
_form: 'Drupal\file_test\Form\FileTestSaveUploadFromForm'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\file_test\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Messenger\MessengerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* File test form class.
|
||||
*/
|
||||
class FileTestSaveUploadFromForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Stores the state storage service.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The messenger.
|
||||
*
|
||||
* @var \Drupal\Core\Messenger\MessengerInterface
|
||||
*/
|
||||
protected $messenger;
|
||||
|
||||
/**
|
||||
* Constructs a FileTestSaveUploadFromForm object.
|
||||
*
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state key value store.
|
||||
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
|
||||
* The messenger.
|
||||
*/
|
||||
public function __construct(StateInterface $state, MessengerInterface $messenger) {
|
||||
$this->state = $state;
|
||||
$this->messenger = $messenger;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('state'),
|
||||
$container->get('messenger')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return '_file_test_save_upload_from_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['file_test_upload'] = [
|
||||
'#type' => 'file',
|
||||
'#multiple' => TRUE,
|
||||
'#title' => $this->t('Upload a file'),
|
||||
];
|
||||
$form['file_test_replace'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Replace existing image'),
|
||||
'#options' => [
|
||||
FILE_EXISTS_RENAME => $this->t('Appends number until name is unique'),
|
||||
FILE_EXISTS_REPLACE => $this->t('Replace the existing file'),
|
||||
FILE_EXISTS_ERROR => $this->t('Fail with an error'),
|
||||
],
|
||||
'#default_value' => FILE_EXISTS_RENAME,
|
||||
];
|
||||
$form['file_subdir'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subdirectory for test file'),
|
||||
'#default_value' => '',
|
||||
];
|
||||
|
||||
$form['extensions'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Allowed extensions.'),
|
||||
'#default_value' => '',
|
||||
];
|
||||
|
||||
$form['allow_all_extensions'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Allow all extensions?'),
|
||||
'#default_value' => FALSE,
|
||||
];
|
||||
|
||||
$form['is_image_file'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Is this an image file?'),
|
||||
'#default_value' => TRUE,
|
||||
];
|
||||
|
||||
$form['error_message'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Custom error message.'),
|
||||
'#default_value' => '',
|
||||
];
|
||||
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Submit'),
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
// Process the upload and perform validation. Note: we're using the
|
||||
// form value for the $replace parameter.
|
||||
if (!$form_state->isValueEmpty('file_subdir')) {
|
||||
$destination = 'temporary://' . $form_state->getValue('file_subdir');
|
||||
file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
|
||||
}
|
||||
else {
|
||||
$destination = FALSE;
|
||||
}
|
||||
|
||||
// Preset custom error message if requested.
|
||||
if ($form_state->getValue('error_message')) {
|
||||
$this->messenger->addError($form_state->getValue('error_message'));
|
||||
}
|
||||
|
||||
// Setup validators.
|
||||
$validators = [];
|
||||
if ($form_state->getValue('is_image_file')) {
|
||||
$validators['file_validate_is_image'] = [];
|
||||
}
|
||||
|
||||
if ($form_state->getValue('allow_all_extensions')) {
|
||||
$validators['file_validate_extensions'] = [];
|
||||
}
|
||||
elseif (!$form_state->isValueEmpty('extensions')) {
|
||||
$validators['file_validate_extensions'] = [$form_state->getValue('extensions')];
|
||||
}
|
||||
|
||||
// The test for drupal_move_uploaded_file() triggering a warning is
|
||||
// unavoidable. We're interested in what happens afterwards in
|
||||
// _file_save_upload_from_form().
|
||||
if ($this->state->get('file_test.disable_error_collection')) {
|
||||
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
|
||||
}
|
||||
|
||||
$form['file_test_upload']['#upload_validators'] = $validators;
|
||||
$form['file_test_upload']['#upload_location'] = $destination;
|
||||
|
||||
$this->messenger->addStatus($this->t('Number of error messages before _file_save_upload_from_form(): @count.', ['@count' => count($this->messenger->messagesByType(MessengerInterface::TYPE_ERROR))]));
|
||||
$file = _file_save_upload_from_form($form['file_test_upload'], $form_state, 0, $form_state->getValue('file_test_replace'));
|
||||
$this->messenger->addStatus($this->t('Number of error messages after _file_save_upload_from_form(): @count.', ['@count' => count($this->messenger->messagesByType(MessengerInterface::TYPE_ERROR))]));
|
||||
|
||||
if ($file) {
|
||||
$form_state->setValue('file_test_upload', $file);
|
||||
$this->messenger->addStatus($this->t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
|
||||
$this->messenger->addStatus($this->t('File name is @filename.', ['@filename' => $file->getFilename()]));
|
||||
$this->messenger->addStatus($this->t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
|
||||
$this->messenger->addStatus($this->t('You WIN!'));
|
||||
}
|
||||
elseif ($file === FALSE) {
|
||||
$this->messenger->addError($this->t('Epic upload FAIL!'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {}
|
||||
|
||||
}
|
||||
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
uuid: 9ca49b35-b49d-4014-9337-965cdf15b61e
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.field.node.article.body
|
||||
- field.field.node.article.comment
|
||||
- field.field.node.article.field_file_generic_2677990
|
||||
- field.field.node.article.field_file_table_2677990
|
||||
- field.field.node.article.field_image
|
||||
- field.field.node.article.field_tags
|
||||
- image.style.large
|
||||
- node.type.article
|
||||
module:
|
||||
- comment
|
||||
- file
|
||||
- image
|
||||
- text
|
||||
- user
|
||||
_core:
|
||||
default_config_hash: JtAg_-waIt1quMtdDtHIaXJMxvTuSmxW7bWyO6Zd68E
|
||||
id: node.article.default
|
||||
targetEntityType: node
|
||||
bundle: article
|
||||
mode: default
|
||||
content:
|
||||
body:
|
||||
type: text_default
|
||||
weight: 0
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
label: hidden
|
||||
comment:
|
||||
label: above
|
||||
type: comment_default
|
||||
weight: 20
|
||||
settings:
|
||||
pager_id: 0
|
||||
third_party_settings: { }
|
||||
field_file_generic_2677990:
|
||||
weight: 101
|
||||
label: above
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
type: file_default
|
||||
field_file_table_2677990:
|
||||
weight: 102
|
||||
label: above
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
type: file_table
|
||||
field_image:
|
||||
type: image
|
||||
weight: -1
|
||||
settings:
|
||||
image_style: large
|
||||
image_link: ''
|
||||
third_party_settings: { }
|
||||
label: hidden
|
||||
field_tags:
|
||||
type: entity_reference_label
|
||||
weight: 10
|
||||
label: above
|
||||
settings:
|
||||
link: true
|
||||
third_party_settings: { }
|
||||
links:
|
||||
weight: 100
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
hidden: { }
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
|
||||
* upgrade path of https://www.drupal.org/node/2677990.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Component\Serialization\Yaml;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Configuration for a file field storage for generic display.
|
||||
$field_file_generic_2677990 = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_file_generic_2677990.yml'));
|
||||
|
||||
// Configuration for a file field storage for table display.
|
||||
$field_file_table_2677990 = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_file_table_2677990.yml'));
|
||||
|
||||
$connection->insert('config')
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'field.storage.' . $field_file_generic_2677990['id'],
|
||||
'data' => serialize($field_file_generic_2677990),
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'field.storage.' . $field_file_table_2677990['id'],
|
||||
'data' => serialize($field_file_table_2677990),
|
||||
])
|
||||
->execute();
|
||||
// We need to Update the registry of "last installed" field definitions.
|
||||
$installed = $connection->select('key_value')
|
||||
->fields('key_value', ['value'])
|
||||
->condition('collection', 'entity.definitions.installed')
|
||||
->condition('name', 'node.field_storage_definitions')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$installed = unserialize($installed);
|
||||
$installed['field_file_generic_2677990'] = new FieldStorageConfig($field_file_generic_2677990);
|
||||
$installed['field_file_table_2677990'] = new FieldStorageConfig($field_file_table_2677990);
|
||||
$connection->update('key_value')
|
||||
->condition('collection', 'entity.definitions.installed')
|
||||
->condition('name', 'node.field_storage_definitions')
|
||||
->fields([
|
||||
'value' => serialize($installed)
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Configuration for a file field storage for generic display.
|
||||
$field_file_generic_2677990 = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_file_generic_2677990.yml'));
|
||||
|
||||
// Configuration for a file field storage for table display.
|
||||
$field_file_table_2677990 = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_file_table_2677990.yml'));
|
||||
|
||||
$connection->insert('config')
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'field.field.' . $field_file_generic_2677990['id'],
|
||||
'data' => serialize($field_file_generic_2677990),
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'field.field.' . $field_file_table_2677990['id'],
|
||||
'data' => serialize($field_file_table_2677990),
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Configuration of the view mode to set the proper formatters.
|
||||
$view_mode_2677990 = Yaml::decode(file_get_contents(__DIR__ . '/core.entity_view_display.node.article.default_2677990.yml'));
|
||||
|
||||
$connection->update('config')
|
||||
->fields([
|
||||
'data' => serialize($view_mode_2677990),
|
||||
])
|
||||
->condition('name', 'core.entity_view_display.' . $view_mode_2677990['id'])
|
||||
->execute();
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
uuid: d352a831-c267-4ecc-9b4e-7ae1896b2241
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_file_generic_2677990
|
||||
- node.type.article
|
||||
module:
|
||||
- file
|
||||
id: node.article.field_file_generic_2677990
|
||||
field_name: field_file_generic_2677990
|
||||
entity_type: node
|
||||
bundle: article
|
||||
label: 'File generic'
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
file_directory: '[date:custom:Y]-[date:custom:m]'
|
||||
file_extensions: txt
|
||||
max_filesize: ''
|
||||
description_field: true
|
||||
handler: 'default:file'
|
||||
handler_settings: { }
|
||||
field_type: file
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
uuid: 44c7a590-ffcc-4534-b01c-b17b8d57ed48
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_file_table_2677990
|
||||
- node.type.article
|
||||
module:
|
||||
- file
|
||||
id: node.article.field_file_table_2677990
|
||||
field_name: field_file_table_2677990
|
||||
entity_type: node
|
||||
bundle: article
|
||||
label: 'File table'
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
file_directory: '[date:custom:Y]-[date:custom:m]'
|
||||
file_extensions: txt
|
||||
max_filesize: ''
|
||||
description_field: true
|
||||
handler: 'default:file'
|
||||
handler_settings: { }
|
||||
field_type: file
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
uuid: a7eb470d-e538-4221-a8ac-57f989d92d8e
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- file
|
||||
- node
|
||||
id: node.field_file_generic_2677990
|
||||
field_name: field_file_generic_2677990
|
||||
entity_type: node
|
||||
type: file
|
||||
settings:
|
||||
display_field: false
|
||||
display_default: false
|
||||
uri_scheme: public
|
||||
target_type: file
|
||||
module: file
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
uuid: 43113a5e-3e07-4234-b045-4aa4cd217dca
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- file
|
||||
- node
|
||||
id: node.field_file_table_2677990
|
||||
field_name: field_file_table_2677990
|
||||
entity_type: node
|
||||
type: file
|
||||
settings:
|
||||
display_field: false
|
||||
display_default: false
|
||||
uri_scheme: public
|
||||
target_type: file
|
||||
module: file
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
||||
@@ -8,8 +8,8 @@ dependencies:
|
||||
- file
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -180,7 +180,7 @@ abstract class FileFieldTestBase extends BrowserTestBase {
|
||||
*/
|
||||
public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) {
|
||||
$edit = [
|
||||
'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()),
|
||||
'files[' . $field_name . '_0]' => \Drupal::service('file_system')->realpath($file->getFileUri()),
|
||||
'revision' => (string) (int) $new_revision,
|
||||
];
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\Tests\file\Functional;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests access to managed files.
|
||||
@@ -11,6 +12,19 @@ use Drupal\file\Entity\File;
|
||||
*/
|
||||
class FileManagedAccessTest extends FileManagedTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Give anonymous users permission to access content, so they can view and
|
||||
// download public files.
|
||||
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
|
||||
$anonymous_role->grantPermission('access content');
|
||||
$anonymous_role->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if public file is always accessible.
|
||||
*/
|
||||
@@ -29,7 +43,7 @@ class FileManagedAccessTest extends FileManagedTestBase {
|
||||
$file->save();
|
||||
|
||||
// Create authenticated user to check file access.
|
||||
$account = $this->createUser(['access site reports']);
|
||||
$account = $this->createUser(['access site reports', 'access content']);
|
||||
|
||||
$this->assertTrue($file->access('view', $account), 'Public file is viewable to authenticated user');
|
||||
$this->assertTrue($file->access('download', $account), 'Public file is downloadable to authenticated user');
|
||||
@@ -54,7 +68,7 @@ class FileManagedAccessTest extends FileManagedTestBase {
|
||||
$file->save();
|
||||
|
||||
// Create authenticated user to check file access.
|
||||
$account = $this->createUser(['access site reports']);
|
||||
$account = $this->createUser(['access site reports', 'access content']);
|
||||
|
||||
$this->assertFalse($file->access('view', $account), 'Private file is not viewable to authenticated user');
|
||||
$this->assertFalse($file->access('download', $account), 'Private file is not downloadable to authenticated user');
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Functional\Formatter;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\file\Entity\File;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\Field\FieldFormatter\FileAudioFormatter
|
||||
* @group file
|
||||
*/
|
||||
class FileAudioFormatterTest extends FileMediaFormatterTestBase {
|
||||
|
||||
/**
|
||||
* @covers ::viewElements
|
||||
*
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testRender($tag_count, $formatter_settings) {
|
||||
$field_config = $this->createMediaField('file_audio', 'mp3', $formatter_settings);
|
||||
|
||||
file_put_contents('public://file.mp3', str_repeat('t', 10));
|
||||
$file1 = File::create([
|
||||
'uri' => 'public://file.mp3',
|
||||
'filename' => 'file.mp3',
|
||||
]);
|
||||
$file1->save();
|
||||
|
||||
$file2 = File::create([
|
||||
'uri' => 'public://file.mp3',
|
||||
'filename' => 'file.mp3',
|
||||
]);
|
||||
$file2->save();
|
||||
|
||||
$entity = EntityTest::create([
|
||||
$field_config->getName() => [
|
||||
[
|
||||
'target_id' => $file1->id(),
|
||||
],
|
||||
[
|
||||
'target_id' => $file2->id(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
$this->drupalGet($entity->toUrl());
|
||||
|
||||
$file1_url = file_url_transform_relative(file_create_url($file1->getFileUri()));
|
||||
$file2_url = file_url_transform_relative(file_create_url($file2->getFileUri()));
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
$assert_session->elementsCount('css', 'audio[controls="controls"]', $tag_count);
|
||||
$assert_session->elementExists('css', "audio > source[src='$file1_url'][type='audio/mpeg']");
|
||||
$assert_session->elementExists('css', "audio > source[src='$file2_url'][type='audio/mpeg']");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Functional\Formatter;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Provides methods specifically for testing File module's media formatter's.
|
||||
*/
|
||||
abstract class FileMediaFormatterTestBase extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = [
|
||||
'entity_test',
|
||||
'field',
|
||||
'file',
|
||||
'user',
|
||||
'system',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalLogin($this->drupalCreateUser(['view test entity']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file field and set's the correct formatter.
|
||||
*
|
||||
* @param string $formatter
|
||||
* The formatter ID.
|
||||
* @param string $file_extensions
|
||||
* The file extensions of the new field.
|
||||
* @param array $formatter_settings
|
||||
* Settings for the formatter.
|
||||
*
|
||||
* @return \Drupal\field\Entity\FieldConfig
|
||||
* Newly created file field.
|
||||
*/
|
||||
protected function createMediaField($formatter, $file_extensions, array $formatter_settings = []) {
|
||||
$entity_type = $bundle = 'entity_test';
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => $entity_type,
|
||||
'field_name' => $field_name,
|
||||
'type' => 'file',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
])->save();
|
||||
$field_config = FieldConfig::create([
|
||||
'entity_type' => $entity_type,
|
||||
'field_name' => $field_name,
|
||||
'bundle' => $bundle,
|
||||
'settings' => [
|
||||
'file_extensions' => trim($file_extensions),
|
||||
],
|
||||
]);
|
||||
$field_config->save();
|
||||
|
||||
$display = entity_get_display('entity_test', 'entity_test', 'full');
|
||||
$display->setComponent($field_name, [
|
||||
'type' => $formatter,
|
||||
'settings' => $formatter_settings,
|
||||
])->save();
|
||||
|
||||
return $field_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testRender.
|
||||
*
|
||||
* @return array
|
||||
* An array of data arrays.
|
||||
* The data array contains:
|
||||
* - The number of expected HTML tags.
|
||||
* - An array of settings for the field formatter.
|
||||
*/
|
||||
public function dataProvider() {
|
||||
return [
|
||||
[2, []],
|
||||
[1, ['multiple_file_display_type' => 'sources']],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Functional\Formatter;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\file\Entity\File;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\Field\FieldFormatter\FileVideoFormatter
|
||||
* @group file
|
||||
*/
|
||||
class FileVideoFormatterTest extends FileMediaFormatterTestBase {
|
||||
|
||||
/**
|
||||
* @covers ::viewElements
|
||||
*
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testRender($tag_count, $formatter_settings) {
|
||||
$field_config = $this->createMediaField('file_video', 'mp4', $formatter_settings);
|
||||
|
||||
file_put_contents('public://file.mp4', str_repeat('t', 10));
|
||||
$file1 = File::create([
|
||||
'uri' => 'public://file.mp4',
|
||||
'filename' => 'file.mp4',
|
||||
]);
|
||||
$file1->save();
|
||||
|
||||
$file2 = File::create([
|
||||
'uri' => 'public://file.mp4',
|
||||
'filename' => 'file.mp4',
|
||||
]);
|
||||
$file2->save();
|
||||
|
||||
$entity = EntityTest::create([
|
||||
$field_config->getName() => [
|
||||
[
|
||||
'target_id' => $file1->id(),
|
||||
],
|
||||
[
|
||||
'target_id' => $file2->id(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
$this->drupalGet($entity->toUrl());
|
||||
|
||||
$file1_url = file_url_transform_relative(file_create_url($file1->getFileUri()));
|
||||
$file2_url = file_url_transform_relative(file_create_url($file2->getFileUri()));
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
$assert_session->elementsCount('css', 'video[controls="controls"]', $tag_count);
|
||||
$assert_session->elementExists('css', "video > source[src='$file1_url'][type='video/mp4']");
|
||||
$assert_session->elementExists('css', "video > source[src='$file2_url'][type='video/mp4']");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Kernel;
|
||||
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\file\FileInterface;
|
||||
use Drupal\file\ComputedFileUrl;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\ComputedFileUrl
|
||||
*
|
||||
* @group file
|
||||
*/
|
||||
class ComputedFileUrlTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The test URL to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testUrl = 'public://druplicon.txt';
|
||||
|
||||
/**
|
||||
* @covers ::getValue
|
||||
*/
|
||||
public function testGetValue() {
|
||||
$entity = $this->prophesize(FileInterface::class);
|
||||
$entity->getFileUri()
|
||||
->willReturn($this->testUrl);
|
||||
|
||||
$parent = $this->prophesize(FieldItemInterface::class);
|
||||
$parent->getEntity()
|
||||
->shouldBeCalledTimes(2)
|
||||
->willReturn($entity->reveal());
|
||||
|
||||
$definition = $this->prophesize(DataDefinitionInterface::class);
|
||||
|
||||
$typed_data = new ComputedFileUrl($definition->reveal(), $this->randomMachineName(), $parent->reveal());
|
||||
|
||||
$expected = base_path() . $this->siteDirectory . '/files/druplicon.txt';
|
||||
|
||||
$this->assertSame($expected, $typed_data->getValue());
|
||||
// Do this a second time to confirm the same value is returned but the value
|
||||
// isn't retrieved from the parent entity again.
|
||||
$this->assertSame($expected, $typed_data->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setValue
|
||||
*/
|
||||
public function testSetValue() {
|
||||
$name = $this->randomMachineName();
|
||||
$parent = $this->prophesize(FieldItemInterface::class);
|
||||
$parent->onChange($name)
|
||||
->shouldBeCalled();
|
||||
|
||||
$definition = $this->prophesize(DataDefinitionInterface::class);
|
||||
$typed_data = new ComputedFileUrl($definition->reveal(), $name, $parent->reveal());
|
||||
|
||||
// Setting the value explicitly should mean the parent entity is never
|
||||
// called into.
|
||||
$typed_data->setValue($this->testUrl);
|
||||
|
||||
$this->assertSame($this->testUrl, $typed_data->getValue());
|
||||
// Do this a second time to confirm the same value is returned but the value
|
||||
// isn't retrieved from the parent entity again.
|
||||
$this->assertSame($this->testUrl, $typed_data->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setValue
|
||||
*/
|
||||
public function testSetValueNoNotify() {
|
||||
$name = $this->randomMachineName();
|
||||
$parent = $this->prophesize(FieldItemInterface::class);
|
||||
$parent->onChange($name)
|
||||
->shouldNotBeCalled();
|
||||
|
||||
$definition = $this->prophesize(DataDefinitionInterface::class);
|
||||
$typed_data = new ComputedFileUrl($definition->reveal(), $name, $parent->reveal());
|
||||
|
||||
// Setting the value should explicitly should mean the parent entity is
|
||||
// never called into.
|
||||
$typed_data->setValue($this->testUrl, FALSE);
|
||||
|
||||
$this->assertSame($this->testUrl, $typed_data->getValue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests using entity fields of the file field type.
|
||||
@@ -42,6 +43,14 @@ class FileItemTest extends FieldKernelTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
$this->installConfig(['user']);
|
||||
// Give anonymous users permission to access content, so they can view and
|
||||
// download public files.
|
||||
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
|
||||
$anonymous_role->grantPermission('access content');
|
||||
$anonymous_role->save();
|
||||
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Kernel;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
|
||||
/**
|
||||
* File URI field item test.
|
||||
*
|
||||
* @group file
|
||||
*
|
||||
* @see \Drupal\file\Plugin\Field\FieldType\FileUriItem
|
||||
* @see \Drupal\file\FileUrl
|
||||
*/
|
||||
class FileUriItemTest extends FileManagedUnitTestBase {
|
||||
|
||||
/**
|
||||
* Tests the file entity override of the URI field.
|
||||
*/
|
||||
public function testCustomFileUriField() {
|
||||
$uri = 'public://druplicon.txt';
|
||||
|
||||
// Create a new file entity.
|
||||
$file = File::create([
|
||||
'uid' => 1,
|
||||
'filename' => 'druplicon.txt',
|
||||
'uri' => $uri,
|
||||
'filemime' => 'text/plain',
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
]);
|
||||
file_put_contents($file->getFileUri(), 'hello world');
|
||||
|
||||
$file->save();
|
||||
|
||||
$this->assertSame($uri, $file->uri->value);
|
||||
$expected_url = base_path() . $this->siteDirectory . '/files/druplicon.txt';
|
||||
$this->assertSame($expected_url, $file->uri->url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class MigrateUploadTest extends MigrateDrupal6TestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['menu_ui'];
|
||||
public static $modules = ['language', 'menu_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -51,7 +51,7 @@ class MigrateUploadTest extends MigrateDrupal6TestBase {
|
||||
}
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
$this->migrateContent();
|
||||
$this->migrateContent(['translations']);
|
||||
// Since we are only testing a subset of the file migration, do not check
|
||||
// that the full file migration has been run.
|
||||
$migration = $this->getMigration('d6_upload');
|
||||
@@ -65,16 +65,18 @@ class MigrateUploadTest extends MigrateDrupal6TestBase {
|
||||
public function testUpload() {
|
||||
$this->container->get('entity.manager')
|
||||
->getStorage('node')
|
||||
->resetCache([1, 2]);
|
||||
->resetCache([1, 2, 12]);
|
||||
|
||||
$nodes = Node::loadMultiple([1, 2]);
|
||||
$nodes = Node::loadMultiple([1, 2, 12]);
|
||||
$node = $nodes[1];
|
||||
$this->assertEquals('en', $node->langcode->value);
|
||||
$this->assertIdentical(1, count($node->upload));
|
||||
$this->assertIdentical('1', $node->upload[0]->target_id);
|
||||
$this->assertIdentical('file 1-1-1', $node->upload[0]->description);
|
||||
$this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
|
||||
|
||||
$node = $nodes[2];
|
||||
$this->assertEquals('en', $node->langcode->value);
|
||||
$this->assertIdentical(2, count($node->upload));
|
||||
$this->assertIdentical('3', $node->upload[0]->target_id);
|
||||
$this->assertIdentical('file 2-3-3', $node->upload[0]->description);
|
||||
@@ -82,6 +84,13 @@ class MigrateUploadTest extends MigrateDrupal6TestBase {
|
||||
$this->assertIdentical('2', $node->upload[1]->target_id);
|
||||
$this->assertIdentical(TRUE, $node->upload[1]->isDisplayed());
|
||||
$this->assertIdentical('file 2-3-2', $node->upload[1]->description);
|
||||
|
||||
$node = $nodes[12];
|
||||
$this->assertEquals('zu', $node->langcode->value);
|
||||
$this->assertEquals(1, count($node->upload));
|
||||
$this->assertEquals('3', $node->upload[0]->target_id);
|
||||
$this->assertEquals('file 12-15-3', $node->upload[0]->description);
|
||||
$this->assertEquals(FALSE, $node->upload[0]->isDisplayed());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ class CckFileTest extends MigrateDrupalTestBase {
|
||||
* Tests configurability of file migration name.
|
||||
*
|
||||
* @covers ::__construct
|
||||
* @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead.
|
||||
*/
|
||||
public function testConfigurableFileMigration() {
|
||||
$migration = Migration::create($this->container, [], 'custom_migration', []);
|
||||
|
||||
@@ -34,6 +34,14 @@ class UploadTest extends MigrateSqlSourceTestBase {
|
||||
'list' => '0',
|
||||
'weight' => '-1',
|
||||
],
|
||||
[
|
||||
'fid' => '3',
|
||||
'nid' => '12',
|
||||
'vid' => '15',
|
||||
'description' => 'file 12-15-3',
|
||||
'list' => '0',
|
||||
'weight' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['source_data']['node'] = [
|
||||
@@ -54,6 +62,23 @@ class UploadTest extends MigrateSqlSourceTestBase {
|
||||
'tnid' => '0',
|
||||
'translate' => '0',
|
||||
],
|
||||
[
|
||||
'nid' => '12',
|
||||
'vid' => '15',
|
||||
'type' => 'page',
|
||||
'language' => 'zu',
|
||||
'title' => 'Abantu zulu',
|
||||
'uid' => '1',
|
||||
'status' => '1',
|
||||
'created' => '1444238800',
|
||||
'changed' => '1444238808',
|
||||
'comment' => '0',
|
||||
'promote' => '0',
|
||||
'moderate' => '0',
|
||||
'sticky' => '0',
|
||||
'tnid' => '12',
|
||||
'translate' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
@@ -66,10 +91,24 @@ class UploadTest extends MigrateSqlSourceTestBase {
|
||||
'list' => '0',
|
||||
],
|
||||
],
|
||||
'language' => '',
|
||||
'nid' => '1',
|
||||
'vid' => '1',
|
||||
'type' => 'story',
|
||||
],
|
||||
[
|
||||
'upload' => [
|
||||
[
|
||||
'fid' => '3',
|
||||
'description' => 'file 12-15-3',
|
||||
'list' => '0',
|
||||
],
|
||||
],
|
||||
'language' => 'zu',
|
||||
'nid' => '12',
|
||||
'vid' => '15',
|
||||
'type' => 'page',
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\field\d6\ImageField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d6\ImageField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class ImageFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new ImageField([], 'image', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
* @expectedDeprecation ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d6\ImageField instead. See https://www.drupal.org/node/2936061.
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'd6_field_file',
|
||||
'source' => 'somefieldname',
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Prophecy\Argument;
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\ImageField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class ImageFieldTest extends UnitTestCase {
|
||||
|
||||
@@ -44,6 +45,7 @@ class ImageFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
* @expectedDeprecation ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
@@ -17,6 +17,8 @@ class CckFileTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that alt and title attributes are included in transformed values.
|
||||
*
|
||||
* @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead.
|
||||
*/
|
||||
public function testTransformAltTitle() {
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\file\Plugin\migrate\process\d6\FileUri;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
@@ -69,7 +68,7 @@ class FileUriTest extends MigrateTestCase {
|
||||
}
|
||||
|
||||
protected function doTransform(array $value) {
|
||||
$executable = new MigrateExecutable($this->getMigration(), new MigrateMessage());
|
||||
$executable = new MigrateExecutable($this->getMigration());
|
||||
$row = new Row();
|
||||
|
||||
return (new FileUri([], 'file_uri', []))
|
||||
|
||||
Reference in New Issue
Block a user