diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index f8bfb41..25ef7f2 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -22,7 +22,7 @@ * * @var array */ - public static $modules = ['node', 'file', 'file_module_test', 'field_ui']; + public static $modules = array('node', 'file', 'file_module_test', 'field_ui'); /** * An user with administration permissions. @@ -33,9 +33,9 @@ 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->adminUser = $this->drupalCreateUser(array('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']); + $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); } /** @@ -74,7 +74,7 @@ function getLastFileId() { * @param $widget_settings * A list of widget settings that will be added to the widget defaults. */ - function createFileField($name, $entity_type, $bundle, $storage_settings = [], $field_settings = [], $widget_settings = []) { + function createFileField($name, $entity_type, $bundle, $storage_settings = array(), $field_settings = array(), $widget_settings = array()) { $field_storage = entity_create('field_storage_config', array( 'entity_type' => $entity_type, 'field_name' => $name, @@ -102,36 +102,36 @@ function createFileField($name, $entity_type, $bundle, $storage_settings = [], $ * @param $widget_settings * A list of widget settings that will be added to the widget defaults. */ - function attachFileField($name, $entity_type, $bundle, $field_settings = [], $widget_settings = []) { - $field = [ + function attachFileField($name, $entity_type, $bundle, $field_settings = array(), $widget_settings = array()) { + $field = array( 'field_name' => $name, 'label' => $name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'required' => !empty($field_settings['required']), 'settings' => $field_settings, - ]; + ); entity_create('field_config', $field)->save(); entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($name, [ + ->setComponent($name, array( 'type' => 'file_generic', 'settings' => $widget_settings, - ]) + )) ->save(); // Assign display settings. entity_get_display($entity_type, $bundle, 'default') - ->setComponent($name, [ + ->setComponent($name, array( 'label' => 'hidden', 'type' => 'file_default', - ]) + )) ->save(); } /** * Updates an existing file field with new settings. */ - function updateFileField($name, $type_name, $field_settings = [], $widget_settings = []) { + function updateFileField($name, $type_name, $field_settings = array(), $widget_settings = array()) { $field = FieldConfig::loadByName('node', $type_name, $name); $field->settings = array_merge($field->settings, $field_settings); $field->save(); @@ -146,7 +146,7 @@ function updateFileField($name, $type_name, $field_settings = [], $widget_settin /** * Uploads a file to a node. */ - function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = []) { + function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) { $edit = array( 'title[0][value]' => $this->randomMachineName(), 'revision' => (string) (int) $new_revision, @@ -164,7 +164,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, // Save at least one revision to better simulate a real site. $node->setNewRevision(); $node->save(); - $node_storage->resetCache([$nid]); + $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); $this->assertNotEqual($nid, $node->getRevisionId(), 'Node revision exists.'); } @@ -191,7 +191,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { 'revision' => (string) (int) $new_revision, ); - $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove')); + $this->drupalPostForm('node/' . $nid . '/edit', array(), t('Remove')); $this->drupalPostForm(NULL, $edit, t('Save and keep published')); } @@ -204,7 +204,7 @@ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { 'revision' => (string) (int) $new_revision, ); - $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove')); + $this->drupalPostForm('node/' . $nid . '/edit', array(), t('Remove')); $this->drupalPostForm(NULL, $edit, t('Save and keep published')); } diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index 8792237..0314c52 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -27,7 +27,7 @@ class FileFieldWidgetTest extends FileFieldTestBase { * * @var array */ - public static $modules = ['comment']; + public static $modules = array('comment'); /** * Tests upload and remove buttons for a single-valued File field. @@ -40,13 +40,13 @@ function testSingleValuedWidget() { $test_file = $this->getTestFile('text'); - foreach (['nojs', 'js'] as $type) { + foreach (array('nojs', 'js') as $type) { // Create a new node with the uploaded file and ensure it got uploaded // successfully. // @todo This only tests a 'nojs' submission, because drupalPostAjaxForm() // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node_storage->resetCache([$nid]); + $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); @@ -63,11 +63,11 @@ function testSingleValuedWidget() { // "Click" the remove button (emulating either a nojs or js submission). switch ($type) { case 'nojs': - $this->drupalPostForm(NULL, [], t('Remove')); + $this->drupalPostForm(NULL, array(), t('Remove')); break; case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Remove') . '"]'); - $this->drupalPostAjaxForm(NULL, [], [(string) $button[0]['name'] => (string) $button[0]['value']]); + $this->drupalPostAjaxForm(NULL, array(), array((string) $button[0]['name'] => (string) $button[0]['value'])); break; } @@ -79,8 +79,8 @@ function testSingleValuedWidget() { $this->assertTrue(isset($label[0]), 'Label for upload found.'); // Save the node and ensure it does not have the file. - $this->drupalPostForm(NULL, [], t('Save and keep published')); - $node_storage->resetCache([$nid]); + $this->drupalPostForm(NULL, array(), t('Save and keep published')); + $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); $this->assertTrue(empty($node->{$field_name}->target_id), 'File was successfully removed from the node.'); } @@ -100,12 +100,12 @@ function testMultiValuedWidget() { // names). $field_name = 'test_file_field_1'; $field_name2 = 'test_file_field_2'; - $this->createFileField($field_name, 'node', $type_name, ['cardinality' => 3]); - $this->createFileField($field_name2, 'node', $type_name, ['cardinality' => 3]); + $this->createFileField($field_name, 'node', $type_name, array('cardinality' => 3)); + $this->createFileField($field_name2, 'node', $type_name, array('cardinality' => 3)); $test_file = $this->getTestFile('text'); - foreach (['nojs', 'js'] as $type) { + foreach (array('nojs', 'js') as $type) { // Visit the node creation form, and upload 3 files for each field. Since // the field has cardinality of 3, ensure the "Upload" button is displayed // until after the 3rd file, and after that, isn't displayed. Because @@ -115,9 +115,9 @@ function testMultiValuedWidget() { // does not yet emulate jQuery's file upload. // $this->drupalGet("node/add/$type_name"); - foreach ([$field_name2, $field_name] as $each_field_name) { + foreach (array($field_name2, $field_name) as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { - $edit = ['files[' . $each_field_name . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri())]; + $edit = array('files[' . $each_field_name . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri())); // If the Upload button doesn't exist, drupalPostForm() will automatically // fail with an assertion message. $this->drupalPostForm(NULL, $edit, t('Upload')); @@ -127,7 +127,7 @@ function testMultiValuedWidget() { $num_expected_remove_buttons = 6; - foreach ([$field_name, $field_name2] as $current_field_name) { + foreach (array($field_name, $field_name2) as $current_field_name) { // How many uploaded files for the current field are remaining. $remaining = 3; // Test clicking each "Remove" button. For extra robustness, test them out @@ -136,11 +136,11 @@ function testMultiValuedWidget() { // - First remove the 2nd file. // - Then remove what is then the 2nd file (was originally the 3rd file). // - Then remove the first file. - foreach ([1, 1, 0] as $delta) { + foreach (array(1,1,0) as $delta) { // Ensure we have the expected number of Remove buttons, and that they // are numbered sequentially. $buttons = $this->xpath('//input[@type="submit" and @value="Remove"]'); - $this->assertTrue(is_array($buttons) && count($buttons) === $num_expected_remove_buttons, format_string('There are %n "Remove" buttons displayed (JSMode=%type).', ['%n' => $num_expected_remove_buttons, '%type' => $type])); + $this->assertTrue(is_array($buttons) && count($buttons) === $num_expected_remove_buttons, format_string('There are %n "Remove" buttons displayed (JSMode=%type).', array('%n' => $num_expected_remove_buttons, '%type' => $type))); foreach ($buttons as $i => $button) { $key = $i >= $remaining ? $i - $remaining : $i; $check_field_name = $field_name2; @@ -167,12 +167,12 @@ function testMultiValuedWidget() { $button['value'] = 'DUMMY'; } } - $this->drupalPostForm(NULL, [], t('Remove')); + $this->drupalPostForm(NULL, array(), t('Remove')); break; case 'js': // drupalPostAjaxForm() lets us target the button precisely, so we don't // require the workaround used above for nojs. - $this->drupalPostAjaxForm(NULL, [], [$button_name => t('Remove')]); + $this->drupalPostAjaxForm(NULL, array(), array($button_name => t('Remove'))); break; } $num_expected_remove_buttons--; @@ -181,25 +181,25 @@ function testMultiValuedWidget() { // Ensure an "Upload" button for the current field is displayed with the // correct name. $upload_button_name = $current_field_name . '_' . $remaining . '_upload_button'; - $buttons = $this->xpath('//input[@type="submit" and @value="Upload" and @name=:name]', [':name' => $upload_button_name]); - $this->assertTrue(is_array($buttons) && count($buttons) == 1, format_string('The upload button is displayed with the correct name (JSMode=%type).', ['%type' => $type])); + $buttons = $this->xpath('//input[@type="submit" and @value="Upload" and @name=:name]', array(':name' => $upload_button_name)); + $this->assertTrue(is_array($buttons) && count($buttons) == 1, format_string('The upload button is displayed with the correct name (JSMode=%type).', array('%type' => $type))); // Ensure only at most one button per field is displayed. $buttons = $this->xpath('//input[@type="submit" and @value="Upload"]'); $expected = $current_field_name == $field_name ? 1 : 2; - $this->assertTrue(is_array($buttons) && count($buttons) == $expected, format_string('After removing a file, only one "Upload" button for each possible field is displayed (JSMode=%type).', ['%type' => $type])); + $this->assertTrue(is_array($buttons) && count($buttons) == $expected, format_string('After removing a file, only one "Upload" button for each possible field is displayed (JSMode=%type).', array('%type' => $type))); } } // Ensure the page now has no Remove buttons. - $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), format_string('After removing all files, there is no "Remove" button displayed (JSMode=%type).', ['%type' => $type])); + $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), format_string('After removing all files, there is no "Remove" button displayed (JSMode=%type).', array('%type' => $type))); // Save the node and ensure it does not have any files. - $this->drupalPostForm(NULL, ['title[0][value]' => $this->randomMachineName()], t('Save and publish')); - $matches = []; + $this->drupalPostForm(NULL, array('title[0][value]' => $this->randomMachineName()), t('Save and publish')); + $matches = array(); preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; - $node_storage->resetCache([$nid]); + $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); $this->assertTrue(empty($node->{$field_name}->target_id), 'Node was successfully saved without any files.'); } @@ -211,7 +211,7 @@ function testMultiValuedWidget() { function testPrivateFileSetting() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Grant the admin user required permissions. - user_role_grant_permissions($this->adminUser->roles[0]->target_id, ['administer node fields']); + user_role_grant_permissions($this->adminUser->roles[0]->target_id, array('administer node fields')); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -221,10 +221,10 @@ function testPrivateFileSetting() { $test_file = $this->getTestFile('text'); // Change the field setting to make its files private, and upload a file. - $edit = ['field_storage[settings][uri_scheme]' => 'private']; + $edit = array('field_storage[settings][uri_scheme]' => 'private'); $this->drupalPostForm("admin/structure/types/manage/$type_name/fields/$field->id/storage", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $node_storage->resetCache([$nid]); + $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); @@ -248,41 +248,41 @@ function testPrivateFileSetting() { * Tests that download restrictions on private files work on comments. */ function testPrivateFileComment() { - $user = $this->drupalCreateUser(['access comments']); + $user = $this->drupalCreateUser(array('access comments')); // Grant the admin user required comment permissions. $roles = $this->adminUser->getRoles(); - user_role_grant_permissions($roles[1], ['administer comment fields', 'administer comments']); + user_role_grant_permissions($roles[1], array('administer comment fields', 'administer comments')); // Revoke access comments permission from anon user, grant post to // authenticated. - user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, ['access comments']); - user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, ['post comments', 'skip comment approval']); + user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments')); + user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('post comments', 'skip comment approval')); // Create a new field. $this->container->get('comment.manager')->addDefaultField('node', 'article'); $name = strtolower($this->randomMachineName()); $label = $this->randomMachineName(); - $storage_edit = ['field_storage[settings][uri_scheme]' => 'private']; + $storage_edit = array('field_storage[settings][uri_scheme]' => 'private'); $this->fieldUIAddNewField('admin/structure/comment/manage/comment', $name, $label, 'file', $storage_edit); // Manually clear cache on the tester side. \Drupal::entityManager()->clearCachedFieldDefinitions(); // Create node. - $edit = [ + $edit = array( 'title[0][value]' => $this->randomMachineName(), - ]; + ); $this->drupalPostForm('node/add/article', $edit, t('Save and publish')); $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); // Add a comment with a file. $text_file = $this->getTestFile('text'); - $edit = [ + $edit = array( 'files[field_' . $name . '_' . 0 . ']' => drupal_realpath($text_file->getFileUri()), 'comment_body[0][value]' => $comment_body = $this->randomMachineName(), - ]; + ); $this->drupalPostForm('node/' . $node->id(), $edit, t('Save')); // Get the comment ID. @@ -308,7 +308,7 @@ function testPrivateFileComment() { // Unpublishes node. $this->drupalLogin($this->adminUser); - $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and unpublish')); + $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish')); // Ensures normal user can no longer download the file. $this->drupalLogin($user); @@ -323,11 +323,11 @@ function testWidgetValidation() { $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); - $this->updateFileField($field_name, $type_name, ['file_extensions' => 'txt']); + $this->updateFileField($field_name, $type_name, array('file_extensions' => 'txt')); - foreach (['nojs', 'js'] as $type) { + foreach (array('nojs', 'js') as $type) { // Create node and prepare files for upload. - $node = $this->drupalCreateNode(['type' => 'article']); + $node = $this->drupalCreateNode(array('type' => 'article')); $nid = $node->id(); $this->drupalGet("node/$nid/edit"); $test_file_text = $this->getTestFile('text'); @@ -342,11 +342,11 @@ function testWidgetValidation() { break; case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]'); - $this->drupalPostAjaxForm(NULL, $edit, [(string) $button[0]['name'] => (string) $button[0]['value']]); + $this->drupalPostAjaxForm(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value'])); break; } - $error_message = t('Only files with the following extensions are allowed: %files-allowed.', ['%files-allowed' => 'txt']); - $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', ['%type' => $type])); + $error_message = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => 'txt')); + $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', array('%type' => $type))); // Upload file with correct extension, check that error message is removed. $edit[$name] = drupal_realpath($test_file_text->getFileUri()); @@ -356,10 +356,10 @@ function testWidgetValidation() { break; case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]'); - $this->drupalPostAjaxForm(NULL, $edit, [(string) $button[0]['name'] => (string) $button[0]['value']]); + $this->drupalPostAjaxForm(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value'])); break; } - $this->assertNoRaw($error_message, t('Validation error removed when file with correct extension uploaded (JSMode=%type).', ['%type' => $type])); + $this->assertNoRaw($error_message, t('Validation error removed when file with correct extension uploaded (JSMode=%type).', array('%type' => $type))); } } } diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index 9d79a78..eb49534 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -21,7 +21,7 @@ class FileListingTest extends FileFieldTestBase { * * @var array */ - public static $modules = ['views', 'file', 'image']; + public static $modules = array('views', 'file', 'image'); /** * An authenticated user. @@ -33,9 +33,9 @@ class FileListingTest extends FileFieldTestBase { protected function setUp() { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(['access files overview', 'bypass node access']); + $this->adminUser = $this->drupalCreateUser(array('access files overview', 'bypass node access')); $this->baseUser = $this->drupalCreateUser(); - $this->createFileField('file', 'node', 'article', [], ['file_extensions' => 'txt png']); + $this->createFileField('file', 'node', 'article', array(), array('file_extensions' => 'txt png')); } /** @@ -73,7 +73,7 @@ function testFileListingPages() { $this->drupalLogin($this->adminUser); for ($i = 0; $i < 5; $i++) { - $nodes[] = $this->drupalCreateNode(['type' => 'article']); + $nodes[] = $this->drupalCreateNode(array('type' => 'article')); } $this->drupalGet('admin/content/files');