updated core to 8.6.3

This commit is contained in:
2018-11-21 12:49:46 +01:00
parent 8ca34853a3
commit c92c348eee
521 changed files with 12199 additions and 4578 deletions
+1
View File
@@ -215,6 +215,7 @@
*/
disableFields(event) {
const $clickedButton = $(this);
$clickedButton.trigger('formUpdated');
// Check if we're working with an "Upload" button.
let $enabledFields = [];
+1
View File
@@ -96,6 +96,7 @@
},
disableFields: function disableFields(event) {
var $clickedButton = $(this);
$clickedButton.trigger('formUpdated');
var $enabledFields = [];
if ($clickedButton.closest('div.js-form-managed-file').length > 0) {
@@ -1,6 +1,6 @@
<?php
namespace Drupal\file\Tests;
namespace Drupal\Tests\file\Functional;
/**
* Tests the 'managed_file' element type.
@@ -36,11 +36,13 @@ class FileManagedFileElementTest extends FileFieldTestBase {
// Submit with a file, but with an invalid form token. Ensure the file
// was not saved.
$last_fid_prior = $this->getLastFileId();
$this->drupalGet($path);
$form_token_field = $this->assertSession()->hiddenFieldExists('form_token');
$form_token_field->setValue('invalid token');
$edit = [
$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri()),
'form_token' => 'invalid token',
];
$this->drupalPostForm($path, $edit, t('Save'));
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
$last_fid = $this->getLastFileId();
$this->assertEqual($last_fid_prior, $last_fid, 'File was not saved when uploaded with an invalid form token.');
@@ -57,64 +59,41 @@ class FileManagedFileElementTest extends FileFieldTestBase {
$this->drupalPostForm($path . '/' . $last_fid, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => implode(',', [$last_fid])]), 'Empty submission did not change an existing file.');
// Now, test the Upload and Remove buttons, with and without Ajax.
foreach ([FALSE, TRUE] as $ajax) {
// Upload, then Submit.
$last_fid_prior = $this->getLastFileId();
$this->drupalGet($path);
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
if ($ajax) {
$this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button');
}
else {
$this->drupalPostForm(NULL, $edit, t('Upload'));
}
$last_fid = $this->getLastFileId();
$this->assertTrue($last_fid > $last_fid_prior, 'New file got uploaded.');
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => implode(',', [$last_fid])]), 'Submit handler has correct file info.');
// Upload, then Submit.
$last_fid_prior = $this->getLastFileId();
$this->drupalGet($path);
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
$last_fid = $this->getLastFileId();
$this->assertTrue($last_fid > $last_fid_prior, 'New file got uploaded.');
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => implode(',', [$last_fid])]), 'Submit handler has correct file info.');
// Remove, then Submit.
$remove_button_title = $multiple ? t('Remove selected') : t('Remove');
$remove_edit = [];
if ($multiple) {
$selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $last_fid . '][selected]';
$remove_edit = [$selected_checkbox => '1'];
}
$this->drupalGet($path . '/' . $last_fid);
if ($ajax) {
$this->drupalPostAjaxForm(NULL, $remove_edit, $input_base_name . '_remove_button');
}
else {
$this->drupalPostForm(NULL, $remove_edit, $remove_button_title);
}
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => '']), 'Submission after file removal was successful.');
// Upload, then Remove, then Submit.
$this->drupalGet($path);
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
if ($ajax) {
$this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button');
}
else {
$this->drupalPostForm(NULL, $edit, t('Upload'));
}
$remove_edit = [];
if ($multiple) {
$selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $this->getLastFileId() . '][selected]';
$remove_edit = [$selected_checkbox => '1'];
}
if ($ajax) {
$this->drupalPostAjaxForm(NULL, $remove_edit, $input_base_name . '_remove_button');
}
else {
$this->drupalPostForm(NULL, $remove_edit, $remove_button_title);
}
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => '']), 'Submission after file upload and removal was successful.');
// Remove, then Submit.
$remove_button_title = $multiple ? t('Remove selected') : t('Remove');
$remove_edit = [];
if ($multiple) {
$selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $last_fid . '][selected]';
$remove_edit = [$selected_checkbox => '1'];
}
$this->drupalGet($path . '/' . $last_fid);
$this->drupalPostForm(NULL, $remove_edit, $remove_button_title);
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => '']), 'Submission after file removal was successful.');
// Upload, then Remove, then Submit.
$this->drupalGet($path);
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
$remove_edit = [];
if ($multiple) {
$selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $this->getLastFileId() . '][selected]';
$remove_edit = [$selected_checkbox => '1'];
}
$this->drupalPostForm(NULL, $remove_edit, $remove_button_title);
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw(t('The file ids are %fids.', ['%fids' => '']), 'Submission after file upload and removal was successful.');
}
}
}
@@ -212,7 +191,7 @@ class FileManagedFileElementTest extends FileFieldTestBase {
$this->assertNoText('The file used in the Managed file &amp; butter field may not be referenced.');
$this->assertText('The file ids are ' . $file->id());
// Enable marking unused files as tempory, unused permanent files must not
// Enable marking unused files as temporary, unused permanent files must not
// be referenced now.
$this->config('file.settings')
->set('make_unused_managed_files_temporary', TRUE)
@@ -0,0 +1,101 @@
<?php
namespace Drupal\Tests\file\FunctionalJavascript;
use Drupal\Core\Database\Database;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests the 'managed_file' element type.
*
* @group file
*/
class FileManagedFileElementTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['node', 'file', 'file_module_test', 'field_ui'];
/**
* A user with administration permissions.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access content', 'access administration pages', 'administer site configuration', 'administer users', 'administer permissions', 'administer content types', 'administer node fields', 'administer node display', 'administer nodes', 'bypass node access']);
$this->drupalLogin($this->adminUser);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
}
/**
* Tests the managed_file element type.
*/
public function testManagedFile() {
// Perform the tests with all permutations of $form['#tree'],
// $element['#extended'], and $element['#multiple'].
$filename = \Drupal::service('file_system')->tempnam('temporary://', "testManagedFile") . '.txt';
file_put_contents($filename, $this->randomString(128));
foreach ([0, 1] as $tree) {
foreach ([0, 1] as $extended) {
foreach ([0, 1] as $multiple) {
$path = 'file/test/' . $tree . '/' . $extended . '/' . $multiple;
$input_base_name = $tree ? 'nested_file' : 'file';
$file_field_name = $multiple ? 'files[' . $input_base_name . '][]' : 'files[' . $input_base_name . ']';
// Now, test the Upload and Remove buttons, with Ajax.
// Upload, then Submit.
$last_fid_prior = $this->getLastFileId();
$this->drupalGet($path);
$this->getSession()->getPage()->attachFileToField($file_field_name, $this->container->get('file_system')->realpath($filename));
$uploaded_file = $this->assertSession()->waitForElement('css', '.file--mime-text-plain');
$this->assertNotEmpty($uploaded_file);
$last_fid = $this->getLastFileId();
$this->assertGreaterThan($last_fid_prior, $last_fid, 'New file got uploaded.');
$this->drupalPostForm(NULL, [], t('Save'));
// Remove, then Submit.
$remove_button_title = $multiple ? t('Remove selected') : t('Remove');
$this->drupalGet($path . '/' . $last_fid);
if ($multiple) {
$selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $last_fid . '][selected]';
$this->getSession()->getPage()->checkField($selected_checkbox);
}
$this->getSession()->getPage()->pressButton($remove_button_title);
$this->assertSession()->assertWaitOnAjaxRequest();
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertSession()->responseContains(t('The file ids are %fids.', ['%fids' => '']));
// Upload, then Remove, then Submit.
$this->drupalGet($path);
$this->getSession()->getPage()->attachFileToField($file_field_name, $this->container->get('file_system')->realpath($filename));
$uploaded_file = $this->assertSession()->waitForElement('css', '.file--mime-text-plain');
$this->assertNotEmpty($uploaded_file);
if ($multiple) {
$selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $this->getLastFileId() . '][selected]';
$this->getSession()->getPage()->checkField($selected_checkbox);
}
$this->getSession()->getPage()->pressButton($remove_button_title);
$this->assertSession()->assertWaitOnAjaxRequest();
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertSession()->responseContains(t('The file ids are %fids.', ['%fids' => '']));
}
}
}
}
/**
* Retrieves the fid of the last inserted file.
*/
protected function getLastFileId() {
return (int) Database::getConnection()->query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
}
}