diff --git a/core/modules/file/css/file.admin.css b/core/modules/file/css/file.admin.css index 585ea62..d3d9a5f 100644 --- a/core/modules/file/css/file.admin.css +++ b/core/modules/file/css/file.admin.css @@ -1,4 +1,3 @@ - /** * @file * Admin stylesheet for file module. diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php index 202081d..bc3fdd1 100644 --- a/core/modules/file/file.api.php +++ b/core/modules/file/file.api.php @@ -27,7 +27,7 @@ function hook_file_create(\Drupal\file\Entity\File $file) { * file_load_multiple() calls this hook to allow modules to load * additional information into each file. * - * @param $files + * @param array $files * An array of file entities, indexed by fid. * * @see file_load_multiple() @@ -51,7 +51,8 @@ function hook_file_load($files) { * * @param \Drupal\file\FileInterface $file * The file entity being validated. - * @return + * + * @return array * An array of error messages. If there are no problems with the file return * an empty array. * @@ -96,7 +97,7 @@ function hook_file_presave(Drupal\file\FileInterface $file) { * The file that has been added. */ function hook_file_insert(Drupal\file\FileInterface $file) { - // Add a message to the log, if the file is a jpg + // Add a message to the log, if the file is a jpg. $validate = file_validate_extensions($file, 'jpg'); if (empty($validate)) { watchdog('file', 'A jpg has been added.'); @@ -118,7 +119,7 @@ function hook_file_update(Drupal\file\FileInterface $file) { $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); $file->save(); - watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename()))); + watchdog('file', '%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename())); } } @@ -138,7 +139,7 @@ function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterfa $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); $file->save(); - watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename()))); + watchdog('file', 'Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())); } } @@ -158,7 +159,7 @@ function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterfa $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); $file->save(); - watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename()))); + watchdog('file', 'Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())); } } @@ -204,19 +205,19 @@ function hook_file_delete(Drupal\file\FileInterface $file) { * references the file; for example, only users with access to a node should be * allowed to download files attached to that node. * - * @param $field + * @param array $field * The field to which the file belongs. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity which references the file. * @param \Drupal\file\FileInterface $file * The file entity that is being requested. * - * @return + * @return bool * TRUE is access should be allowed by this entity or FALSE if denied. Note * that denial may be overridden by another entity controller, making this * grant permissive rather than restrictive. * - * @see hook_entity_field_access(). + * @see hook_entity_field_access() */ function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $entity, Drupal\file\FileInterface $file) { if ($entity->getEntityTypeId() == 'node') { @@ -231,9 +232,9 @@ function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $e * individual files. Module may use this hook to create custom access rules * for file downloads. * - * @see hook_file_download_access(). + * @see hook_file_download_access() * - * @param $grants + * @param array $grants * An array of grants gathered by hook_file_download_access(). The array is * keyed by the module that defines the entity type's access control; the * values are Boolean grant responses for each module. @@ -243,7 +244,7 @@ function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $e * - entity: The entity which references the file. * - file: The file entity that is being requested. * - * @see hook_file_download_access(). + * @see hook_file_download_access() */ function hook_file_download_access_alter(&$grants, $context) { // For our example module, we always enforce the rules set by node module. diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index a3c7140..000f22b 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -21,7 +21,7 @@ function file_field_info_alter(&$info) { /** * Returns HTML for an individual file upload widget. * - * @param $variables + * @param array $variables * An associative array containing: * - element: A render element representing the widget. * @@ -47,7 +47,7 @@ function theme_file_widget($variables) { /** * Returns HTML for a group of file upload widgets. * - * @param $variables + * @param array $variables * An associative array containing: * - element: A render element representing the widgets. * @@ -166,7 +166,7 @@ function theme_file_widget_multiple($variables) { /** * Returns HTML for help text based on file upload validators. * - * @param $variables + * @param array $variables * An associative array containing: * - description: The normal description for this field, specified by the * user. @@ -226,7 +226,7 @@ function theme_file_upload_help($variables) { * @param Drupal\field\FieldConfigInterface $field * A field definition. * - * @return + * @return int * The field column if the field references {file_managed}.fid, typically * fid, FALSE if it doesn't. */ @@ -247,7 +247,7 @@ function file_field_find_file_reference_column(FieldConfigInterface $field) { /** * Returns HTML for a file attachments table. * - * @param $variables + * @param array $variables * An associative array containing: * - items: field values, as a FileFieldItemList object. * diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc index bd90aef..7e58d96 100644 --- a/core/modules/file/file.views.inc +++ b/core/modules/file/file.views.inc @@ -14,23 +14,23 @@ function file_views_data() { $data = array(); - // file_managed table + // file_managed table. $data['file_managed']['table']['group'] = t('File'); - // Advertise this table as a possible base table + // Advertise this table as a possible base table. $data['file_managed']['table']['base'] = array( 'field' => 'fid', 'title' => t('File'), 'help' => t("Files maintained by Drupal and various modules."), 'defaults' => array( - 'field' => 'filename' + 'field' => 'filename', ), ); $data['file_managed']['table']['entity type'] = 'file'; $data['file_managed']['table']['wizard_id'] = 'file_managed'; - // fid + // FID. $data['file_managed']['fid'] = array( 'title' => t('File ID'), 'help' => t('The ID of the file.'), @@ -39,7 +39,8 @@ function file_views_data() { ), 'argument' => array( 'id' => 'file_fid', - 'name field' => 'filename', // the field to display in the summary. + // The field to display in the summary. + 'name field' => 'filename', 'numeric' => TRUE, ), 'filter' => array( @@ -59,13 +60,13 @@ function file_views_data() { ), ); - // filename + // Filename. $data['file_managed']['filename'] = array( 'title' => t('Name'), 'help' => t('The name of the file.'), 'field' => array( 'id' => 'file', - ), + ), 'sort' => array( 'id' => 'standard', ), @@ -77,13 +78,13 @@ function file_views_data() { ), ); - // uri + // URI. $data['file_managed']['uri'] = array( 'title' => t('Path'), 'help' => t('The path of the file.'), 'field' => array( 'id' => 'file_uri', - ), + ), 'sort' => array( 'id' => 'standard', ), @@ -95,13 +96,13 @@ function file_views_data() { ), ); - // filemime + // Filemime. $data['file_managed']['filemime'] = array( 'title' => t('Mime type'), 'help' => t('The mime type of the file.'), 'field' => array( 'id' => 'file_filemime', - ), + ), 'sort' => array( 'id' => 'standard', ), @@ -113,7 +114,7 @@ function file_views_data() { ), ); - // extension + // Extension. $data['file_managed']['extension'] = array( 'title' => t('Extension'), 'help' => t('The extension of the file.'), @@ -121,16 +122,16 @@ function file_views_data() { 'field' => array( 'id' => 'file_extension', 'click sortable' => FALSE, - ), + ), ); - // filesize + // Filesize. $data['file_managed']['filesize'] = array( 'title' => t('Size'), 'help' => t('The size of the file.'), 'field' => array( 'id' => 'file_size', - ), + ), 'sort' => array( 'id' => 'standard', ), @@ -139,13 +140,13 @@ function file_views_data() { ), ); - // status + // Status. $data['file_managed']['status'] = array( 'title' => t('Status'), 'help' => t('The status of the file.'), 'field' => array( 'id' => 'file_status', - ), + ), 'sort' => array( 'id' => 'standard', ), @@ -184,7 +185,7 @@ function file_views_data() { ), ); - // uid + // UID. $data['file_managed']['uid'] = array( 'title' => t('User who uploaded'), 'help' => t('The user that uploaded the file.'), @@ -196,39 +197,47 @@ function file_views_data() { ), ); - // file_usage table + // file_usage table. $data['file_usage']['table']['group'] = t('File Usage'); - // Provide field-type-things to several base tables; on the core files table ("file_managed") so - // that we can create relationships from files to entities, and then on each core entity type base - // table so that we can provide general relationships between entities and files. + // Provide field-type-things to several base tables; + // on the core files table ("file_managed") so + // that we can create relationships from files to entities, + // and then on each core entity type base + // table so that we can provide general relationships + // between entities and files. $data['file_usage']['table']['join'] = array( - // Link ourself to the {node} table so we can provide node->file relationships. + // Link ourself to the {node} table so + // we can provide node->file relationships. 'node' => array( 'field' => 'id', 'left_field' => 'nid', 'extra' => array(array('field' => 'type', 'value' => 'node')), ), - // Link ourself to the {users} table so we can provide user->file relationships. + // Link ourself to the {users} table so + // we can provide user->file relationships. 'users' => array( 'field' => 'id', 'left_field' => 'uid', 'extra' => array(array('field' => 'type', 'value' => 'user')), ), - // Link ourself to the {comment} table so we can provide comment->file relationships. + // Link ourself to the {comment} table so + // we can provide comment->file relationships. 'comment' => array( 'field' => 'id', 'left_field' => 'cid', 'extra' => array(array('field' => 'type', 'value' => 'comment')), ), - // Link ourself to the {taxonomy_term_data} table so we can provide taxonomy_term->file relationships. + // Link ourself to the {taxonomy_term_data} table so + // we can provide taxonomy_term->file relationships. 'taxonomy_term_data' => array( 'field' => 'id', 'left_field' => 'tid', 'extra' => array(array('field' => 'type', 'value' => 'taxonomy_term')), ), - // Link ourself to the {taxonomy_vocabulary} table so we can provide taxonomy_vocabulary->file relationships. + // Link ourself to the {taxonomy_vocabulary} table so + // we can provide taxonomy_vocabulary->file relationships. 'taxonomy_vocabulary' => array( 'field' => 'id', 'left_field' => 'vid', @@ -236,17 +245,20 @@ function file_views_data() { ), ); - // Provide a relationship between the files table and each entity type, and between each entity - // type and the files table. Entity->file relationships are type-restricted in the joins - // declared above, and file->entity relationships are type-restricted in the relationship - // declarations below. + // Provide a relationship between the files table and each entity type, + // and between each entity type and the files table. + // Entity->file relationships are type-restricted in the joins + // declared above, and file->entity relationships are type-restricted + // in the relationship declarations below. // Relationships between files and nodes. $data['file_usage']['file_to_node'] = array( 'title' => t('Content'), 'help' => t('Content that is associated with this file, usually because this file is in a field on the content.'), - // Only provide this field/relationship/etc. when the 'file_managed' base table is present. - 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'file_managed' base table is present. + 'skip base' => array('node', 'node_field_revision', 'users', 'comment', + 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'id', 'relationship' => array( 'title' => t('Content'), @@ -254,14 +266,21 @@ function file_views_data() { 'base' => 'node', 'base field' => 'nid', 'relationship field' => 'id', - 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'node')), + 'extra' => array(array( + 'table' => 'file_usage', + 'field' => 'type', + 'operator' => '=', + 'value' => 'node', + )), ), ); $data['file_usage']['node_to_file'] = array( 'title' => t('File'), 'help' => t('A file that is associated with this node, usually because it is in a field on the node.'), - // Only provide this field/relationship/etc. when the 'node' base table is present. - 'skip base' => array('file_managed', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'node' base table is present. + 'skip base' => array('file_managed', 'users', 'comment', + 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'fid', 'relationship' => array( 'title' => t('File'), @@ -276,8 +295,10 @@ function file_views_data() { $data['file_usage']['file_to_user'] = array( 'title' => t('User'), 'help' => t('A user that is associated with this file, usually because this file is in a field on the user.'), - // Only provide this field/relationship/etc. when the 'file_managed' base table is present. - 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'file_managed' base table is present. + 'skip base' => array('node', 'node_field_revision', 'users', 'comment', + 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'id', 'relationship' => array( 'title' => t('User'), @@ -285,14 +306,21 @@ function file_views_data() { 'base' => 'users', 'base field' => 'uid', 'relationship field' => 'id', - 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'user')), + 'extra' => array(array( + 'table' => 'file_usage', + 'field' => 'type', + 'operator' => '=', + 'value' => 'user', + )), ), ); $data['file_usage']['user_to_file'] = array( 'title' => t('File'), 'help' => t('A file that is associated with this user, usually because it is in a field on the user.'), - // Only provide this field/relationship/etc. when the 'users' base table is present. - 'skip base' => array('file_managed', 'node', 'node_field_revision', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'users' base table is present. + 'skip base' => array('file_managed', 'node', 'node_field_revision', + 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'fid', 'relationship' => array( 'title' => t('File'), @@ -307,8 +335,10 @@ function file_views_data() { $data['file_usage']['file_to_comment'] = array( 'title' => t('Comment'), 'help' => t('A comment that is associated with this file, usually because this file is in a field on the comment.'), - // Only provide this field/relationship/etc. when the 'file_managed' base table is present. - 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'file_managed' base table is present. + 'skip base' => array('node', 'node_field_revision', 'users', 'comment', + 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'id', 'relationship' => array( 'title' => t('Comment'), @@ -316,14 +346,21 @@ function file_views_data() { 'base' => 'comment', 'base field' => 'cid', 'relationship field' => 'id', - 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'comment')), + 'extra' => array(array( + 'table' => 'file_usage', + 'field' => 'type', + 'operator' => '=', + 'value' => 'comment', + )), ), ); $data['file_usage']['comment_to_file'] = array( 'title' => t('File'), 'help' => t('A file that is associated with this comment, usually because it is in a field on the comment.'), - // Only provide this field/relationship/etc. when the 'comment' base table is present. - 'skip base' => array('file_managed', 'node', 'node_field_revision', 'users', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'comment' base table is present. + 'skip base' => array('file_managed', 'node', 'node_field_revision', + 'users', 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'fid', 'relationship' => array( 'title' => t('File'), @@ -338,8 +375,10 @@ function file_views_data() { $data['file_usage']['file_to_taxonomy_term'] = array( 'title' => t('Taxonomy Term'), 'help' => t('A taxonomy term that is associated with this file, usually because this file is in a field on the taxonomy term.'), - // Only provide this field/relationship/etc. when the 'file_managed' base table is present. - 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'file_managed' base table is present. + 'skip base' => array('node', 'node_field_revision', 'users', + 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'id', 'relationship' => array( 'title' => t('Taxonomy Term'), @@ -347,14 +386,21 @@ function file_views_data() { 'base' => 'taxonomy_term_data', 'base field' => 'tid', 'relationship field' => 'id', - 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_term')), + 'extra' => array(array( + 'table' => 'file_usage', + 'field' => 'type', + 'operator' => '=', + 'value' => 'taxonomy_term', + )), ), ); $data['file_usage']['taxonomy_term_to_file'] = array( 'title' => t('File'), 'help' => t('A file that is associated with this taxonomy term, usually because it is in a field on the taxonomy term.'), - // Only provide this field/relationship/etc. when the 'taxonomy_term_data' base table is present. - 'skip base' => array('file_managed', 'node', 'node_field_revision', 'users', 'comment', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'taxonomy_term_data' base table is present. + 'skip base' => array('file_managed', 'node', 'node_field_revision', + 'users', 'comment', 'taxonomy_vocabulary'), 'real field' => 'fid', 'relationship' => array( 'title' => t('File'), @@ -369,8 +415,10 @@ function file_views_data() { $data['file_usage']['file_to_taxonomy_vocabulary'] = array( 'title' => t('Taxonomy Vocabulary'), 'help' => t('A taxonomy vocabulary that is associated with this file, usually because this file is in a field on the taxonomy vocabulary.'), - // Only provide this field/relationship/etc. when the 'file_managed' base table is present. - 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), + // Only provide this field/relationship/etc. + // when the 'file_managed' base table is present. + 'skip base' => array('node', 'node_field_revision', 'users', + 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), 'real field' => 'id', 'relationship' => array( 'title' => t('Taxonomy Vocabulary'), @@ -378,14 +426,21 @@ function file_views_data() { 'base' => 'taxonomy_vocabulary', 'base field' => 'vid', 'relationship field' => 'id', - 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_vocabulary')), + 'extra' => array(array( + 'table' => 'file_usage', + 'field' => 'type', + 'operator' => '=', + 'value' => 'taxonomy_vocabulary', + )), ), ); $data['file_usage']['taxonomy_vocabulary_to_file'] = array( 'title' => t('File'), 'help' => t('A file that is associated with this taxonomy vocabulary, usually because it is in a field on the taxonomy vocabulary.'), - // Only provide this field/relationship/etc. when the 'taxonomy_vocabulary' base table is present. - 'skip base' => array('file_managed', 'node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data'), + // Only provide this field/relationship/etc. + // when the 'taxonomy_vocabulary' base table is present. + 'skip base' => array('file_managed', 'node', 'node_field_revision', + 'users', 'comment', 'taxonomy_term_data'), 'real field' => 'fid', 'relationship' => array( 'title' => t('File'), @@ -396,14 +451,15 @@ function file_views_data() { ), ); - // Provide basic fields from the {file_usage} table to all of the base tables we've declared - // joins to (because there is no 'skip base' property on these fields). + // Provide basic fields from the {file_usage} table to + // all of the base tables we've declared joins to + // (because there is no 'skip base' property on these fields). $data['file_usage']['module'] = array( 'title' => t('Module'), 'help' => t('The module managing this file relationship.'), 'field' => array( 'id' => 'standard', - ), + ), 'filter' => array( 'id' => 'string', ), @@ -419,7 +475,7 @@ function file_views_data() { 'help' => t('The type of entity that is related to the file.'), 'field' => array( 'id' => 'standard', - ), + ), 'filter' => array( 'id' => 'string', ), @@ -451,7 +507,7 @@ function file_views_data() { 'help' => t('The number of times the file is used by this entity.'), 'field' => array( 'id' => 'numeric', - ), + ), 'filter' => array( 'id' => 'numeric', ), diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php index afa6b0b..2a8689a 100644 --- a/core/modules/file/lib/Drupal/file/FileStorageController.php +++ b/core/modules/file/lib/Drupal/file/FileStorageController.php @@ -35,7 +35,7 @@ public function retrieveTemporaryFiles() { // of PHP. See http://drupal.org/node/352956. return $this->database->query('SELECT fid FROM {' . $this->entityType->getBaseTable() . '} WHERE status <> :permanent AND changed < :changed', array( ':permanent' => FILE_STATUS_PERMANENT, - ':changed' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE + ':changed' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE, )); } } diff --git a/core/modules/file/lib/Drupal/file/FileStorageControllerInterface.php b/core/modules/file/lib/Drupal/file/FileStorageControllerInterface.php index 913d172..be64afa 100644 --- a/core/modules/file/lib/Drupal/file/FileStorageControllerInterface.php +++ b/core/modules/file/lib/Drupal/file/FileStorageControllerInterface.php @@ -32,8 +32,8 @@ public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT); /** * Retrieve temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. * - * @return array - * A list of files to be deleted. + * @return array + * A list of files to be deleted. */ public function retrieveTemporaryFiles(); diff --git a/core/modules/file/lib/Drupal/file/FileUsage/FileUsageInterface.php b/core/modules/file/lib/Drupal/file/FileUsage/FileUsageInterface.php index de890e7..bdb34f6 100644 --- a/core/modules/file/lib/Drupal/file/FileUsage/FileUsageInterface.php +++ b/core/modules/file/lib/Drupal/file/FileUsage/FileUsageInterface.php @@ -69,7 +69,6 @@ public function delete(File $file, $module, $type = NULL, $id = NULL, $count = 1 * A nested array with usage data. The first level is keyed by module name, * the second by object type and the third by the object id. The value of * the third level contains the usage count. - * */ public function listUsage(File $file); } diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileFieldItemList.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileFieldItemList.php index a250229..db4a39d 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileFieldItemList.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileFieldItemList.php @@ -17,7 +17,7 @@ class FileFieldItemList extends FieldItemList { /** * {@inheritdoc} */ - public function defaultValuesForm(array &$form, array &$form_state) { } + public function defaultValuesForm(array &$form, array &$form_state) {} /** * {@inheritdoc} diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php index d72ccad..00c260e 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php @@ -17,7 +17,8 @@ * @FieldType( * id = "file", * label = @Translation("File"), - * description = @Translation("This field stores the ID of a file as an integer value."), + * description = @Translation("This field stores + * the ID of a file as an integer value."), * settings = { * "target_type" = "file", * "display_field" = "0", @@ -185,11 +186,11 @@ public function instanceSettingsForm(array $form, array &$form_state) { } /** - * Form API callback + * Form API callback. * * Removes slashes from the beginning and end of the destination value and - * ensures that the file directory path is not included at the beginning of the - * value. + * ensures that the file directory path is not included at the beginning of + * the value. * * This function is assigned as an #element_validate callback in * instanceSettingsForm(). @@ -208,7 +209,8 @@ public static function validateDirectory($element, &$form_state) { * * This doubles as a convenience clean-up function and a validation routine. * Commas are allowed by the end-user, but ultimately the value will be stored - * as a space-separated list for compatibility with file_validate_extensions(). + * as a space-separated list for compatibility with + * file_validate_extensions(). */ public static function validateExtensions($element, &$form_state) { if (!empty($element['#value'])) { @@ -235,17 +237,17 @@ public static function validateExtensions($element, &$form_state) { */ public static function validateMaxFilesize($element, &$form_state) { if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { - form_error($element, $form_state, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); + form_error($element, $form_state, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => $element['title']))); } } /** * Determines the URI for a file field instance. * - * @param $data + * @param array $data * An array of token objects to pass to token_replace(). * - * @return + * @return string * A file directory URI with tokens replaced. * * @see token_replace() @@ -263,7 +265,7 @@ public function getUploadLocation($data = array()) { /** * Retrieves the upload validators for a file field. * - * @return + * @return array * An array suitable for passing to file_save_upload() or the file field * element's '#upload_validators' property. */ diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php index 9267eae..81671ff 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php @@ -66,9 +66,9 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f $field_name = $this->fieldDefinition->getName(); $parents = $form['#parents']; - // Load the items for form rebuilds from the field state as they might not be - // in $form_state['values'] because of validation limitations. Also, they are - // only passed in as $items when editing existing entities. + // Load the items for form rebuilds from the field state as they might not + // be in $form_state['values'] because of validation limitations. + // Also, they are only passed in as $items when editing existing entities. $field_state = field_form_get_state($parents, $field_name, $form_state); if (isset($field_state['items'])) { $items->setValue($field_state['items']); @@ -269,7 +269,7 @@ public function massageFormValues(array $values, array $form, array &$form_state * * This method is assigned as a #value_callback in formElement() method. */ - public static function value($element, $input = FALSE, $form_state) { + public static function value($element, $input, $form_state) { if ($input) { // Checkboxes lose their value when empty. // If the display field is present make sure its unchecked value is saved. @@ -292,8 +292,9 @@ public static function value($element, $input = FALSE, $form_state) { } /** - * Form element validation callback for upload element on file widget. Checks - * if user has uploaded more files than allowed. + * Form element validation callback for upload element on file widget. + * + * Checks if user has uploaded more files than allowed. * * This validator is used only when cardinality not set to 1 or unlimited. */ @@ -315,7 +316,12 @@ public static function validateMultipleCount($element, &$form_state, $form) { $file = file_load($fid); $removed_names[] = $file->getFilename(); } - $args = array('%field' => $field->getFieldName(), '@max' => $field->cardinality, '@count' => $keep, '%list' => implode(', ', $removed_names)); + $args = array( + '%field' => $field->getFieldName(), + '@max' => $field->cardinality, + '@count' => $keep, + '%list' => implode(', ', $removed_names), + ); $message = t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args); drupal_set_message($message, 'warning'); $values['fids'] = array_slice($values['fids'], 0, $keep); @@ -394,7 +400,9 @@ public static function process($element, &$form_state, $form) { // not just the individual item, to be valid. foreach (array('upload_button', 'remove_button') as $key) { $element[$key]['#submit'][] = array(get_called_class(), 'submit'); - $element[$key]['#limit_validation_errors'] = array(array_slice($element['#parents'], 0, -1)); + $element[$key]['#limit_validation_errors'] = array( + array_slice($element['#parents'], 0, -1), + ); } return $element; diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/argument/Fid.php b/core/modules/file/lib/Drupal/file/Plugin/views/argument/Fid.php index 96fa5ab..42c7d2e 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/argument/Fid.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/argument/Fid.php @@ -48,7 +48,7 @@ class Fid extends Numeric implements ContainerFactoryPluginInterface { * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. - * @param \Drupal\Core\Entity\Query\QueryFactory + * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query * The entity query factory. */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManagerInterface $entity_manager, QueryFactory $entity_query) { diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php b/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php index 8381a1f..620a0bd 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php @@ -32,6 +32,9 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o } } + /** + * Define options for link to file. + */ protected function defineOptions() { $options = parent::defineOptions(); $options['link_to_file'] = array('default' => FALSE, 'bool' => TRUE); @@ -39,7 +42,7 @@ protected function defineOptions() { } /** - * Provide link to file option + * Provide link to file option. */ public function buildOptionsForm(&$form, &$form_state) { $form['link_to_file'] = array( diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php b/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php index 08adfac..0b9488d 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php @@ -10,7 +10,8 @@ use Drupal\views\ResultRow; /** - * Field handler to add rendering MIME type images as an option on the filemime field. + * Field handler to add rendering MIME type images as an option + * on the filemime field. * * @ingroup views_field_handlers * @@ -18,12 +19,18 @@ */ class FileMime extends File { + /** + * Define options for Image FileMime. + */ protected function defineOptions() { $options = parent::defineOptions(); $options['filemime_image'] = array('default' => FALSE, 'bool' => TRUE); return $options; } + /** + * Build options form for Image FileMime. + */ public function buildOptionsForm(&$form, &$form_state) { $form['filemime_image'] = array( '#title' => t('Display an icon representing the file type, instead of the MIME text (such as "image/jpeg")'), diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/field/Uri.php b/core/modules/file/lib/Drupal/file/Plugin/views/field/Uri.php index c503e5e..52e8fa5 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/field/Uri.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/Uri.php @@ -10,18 +10,25 @@ use Drupal\views\ResultRow; /** - * Field handler to add rendering file paths as file URLs instead of as internal file URIs. + * Field handler to add rendering file paths as file URLs + * instead of as internal file URIs. * * @PluginID("file_uri") */ class Uri extends File { + /** + * Define options for file download path. + */ protected function defineOptions() { $options = parent::defineOptions(); $options['file_download_path'] = array('default' => FALSE, 'bool' => TRUE); return $options; } + /** + * Build options form for file download path. + */ public function buildOptionsForm(&$form, &$form_state) { $form['file_download_path'] = array( '#title' => t('Display download path instead of file storage URI'), diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/filter/Status.php b/core/modules/file/lib/Drupal/file/Plugin/views/filter/Status.php index c3d0be2..444866c 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/filter/Status.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/filter/Status.php @@ -17,7 +17,9 @@ * @PluginID("file_status") */ class Status extends InOperator { - + /** + * Get value options for file status. + */ public function getValueOptions() { if (!isset($this->value_options)) { $this->value_options = _views_file_status(); diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php index 94529a0..91c271b 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php @@ -33,11 +33,11 @@ class File extends WizardPluginBase { 'table' => 'file_managed', 'field' => 'uri', 'exclude' => TRUE, - 'file_download_path' => TRUE + 'file_download_path' => TRUE, ); /** - * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions(). + * Overrides ..\..\..\views\wizard\WizardPluginBase::defaultDisplayOptions(). */ protected function defaultDisplayOptions() { $display_options = parent::defaultDisplayOptions(); diff --git a/core/modules/file/lib/Drupal/file/Tests/CopyTest.php b/core/modules/file/lib/Drupal/file/Tests/CopyTest.php index 9fb0ed1..4468abb 100644 --- a/core/modules/file/lib/Drupal/file/Tests/CopyTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/CopyTest.php @@ -11,6 +11,10 @@ * Copy related tests. */ class CopyTest extends FileManagedUnitTestBase { + + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File copying', @@ -22,7 +26,7 @@ public static function getInfo() { /** * Test file copying in the normal, base case. */ - function testNormal() { + public function testNormal() { $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); $desired_uri = 'public://' . $this->randomName(); @@ -51,7 +55,7 @@ function testNormal() { /** * Test renaming when copying over a file that already exists. */ - function testExistingRename() { + public function testExistingRename() { // Setup a file to overwrite. $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); @@ -91,7 +95,7 @@ function testExistingRename() { /** * Test replacement when copying over a file that already exists. */ - function testExistingReplace() { + public function testExistingReplace() { // Setup a file to overwrite. $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); @@ -127,10 +131,11 @@ function testExistingReplace() { } /** - * Test that copying over an existing file fails when FILE_EXISTS_ERROR is - * specified. + * Test that copying over an existing file fails. + * + * when FILE_EXISTS_ERROR is specified. */ - function testExistingError() { + public function testExistingError() { $contents = $this->randomName(10); $source = $this->createFile(); $target = $this->createFile(NULL, $contents); diff --git a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php index f345811..fe494a0 100644 --- a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php @@ -11,6 +11,9 @@ * Deletion related tests. */ class DeleteTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File delete', @@ -22,7 +25,7 @@ public static function getInfo() { /** * Tries deleting a normal file (as opposed to a directory, symlink, etc). */ - function testUnused() { + public function testUnused() { $file = $this->createFile(); // Check that deletion removes the file and database record. @@ -36,7 +39,7 @@ function testUnused() { /** * Tries deleting a file that is in use. */ - function testInUse() { + public function testInUse() { $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); $file_usage->add($file, 'testing', 'test', 1); @@ -71,7 +74,7 @@ function testInUse() { ->execute(); \Drupal::service('cron')->run(); - // system_cron() loads + // system_cron() loads. $this->assertFileHooksCalled(array('delete')); $this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php b/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php index e39b39c..9fa1e10 100644 --- a/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php @@ -13,6 +13,9 @@ * Tests for download/file transfer functions. */ class DownloadTest extends FileManagedTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File download', @@ -20,8 +23,10 @@ public static function getInfo() { 'group' => 'File Managed API', ); } - - function setUp() { + /** + * Set up file for test. + */ + public function setUp() { parent::setUp(); // Clear out any hook calls. file_test_reset(); @@ -30,12 +35,12 @@ function setUp() { /** * Test the public file transfer system. */ - function testPublicFileTransfer() { + public function testPublicFileTransfer() { // Test generating an URL to a created file. $file = $this->createFile(); $url = file_create_url($file->getFileUri()); - // URLs can't contain characters outside the ASCII set so $filename has to be - // encoded. + // URLs can't contain characters outside the ASCII set + // so $filename has to be encoded. $filename = $GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename()); $this->assertEqual($filename, $url, 'Correctly generated a URL for a created file.'); $this->drupalHead($url); @@ -53,7 +58,7 @@ function testPublicFileTransfer() { /** * Test the private file transfer system. */ - function testPrivateFileTransfer() { + public function testPrivateFileTransfer() { // Set file downloads to private so handler functions get called. // Create a file. @@ -85,14 +90,17 @@ function testPrivateFileTransfer() { /** * Test file_create_url(). */ - function testFileCreateUrl() { + public function testFileCreateUrl() { // Tilde (~) is excluded from this test because it is encoded by // rawurlencode() in PHP 5.2 but not in PHP 5.3, as per RFC 3986. // @see http://www.php.net/manual/function.rawurlencode.php#86506 - $basename = " -._!$'\"()*@[]?&+%#,;=:\n\x00" . // "Special" ASCII characters. - "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. - "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. + // "Special" ASCII characters. + $basename = " -._!$'\"()*@[]?&+%#,;=:\n\x00" . + // Characters that look like a percent-escaped string. + "%23%25%26%2B%2F%3F" . + // Characters from various non-ASCII alphabets. + "éøïвβ中國書۞";; $basename_encoded = '%20-._%21%24%27%22%28%29%2A%40%5B%5D%3F%26%2B%25%23%2C%3B%3D%3A__' . '%2523%2525%2526%252B%252F%253F' . '%C3%A9%C3%B8%C3%AF%D0%B2%CE%B2%E4%B8%AD%E5%9C%8B%E6%9B%B8%DB%9E'; @@ -121,13 +129,13 @@ function testFileCreateUrl() { * the URL generated by file_create_url() for the specified file equals the * specified URL; fetch the URL and then compare the contents to the file. * - * @param $scheme + * @param string $scheme * A scheme, e.g. "public" - * @param $directory + * @param string $directory * A directory, possibly "" - * @param $filename + * @param string $filename * A filename - * @param $expected_url + * @param string $expected_url * The expected URL */ private function checkUrl($scheme, $directory, $filename, $expected_url) { diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index 219c083..c99339e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -14,6 +14,9 @@ */ class FileFieldDisplayTest extends FileFieldTestBase { + /** + * Get info of File Field. + */ public static function getInfo() { return array( 'name' => 'File field display tests', @@ -25,7 +28,7 @@ public static function getInfo() { /** * Tests normal formatter display on node display. */ - function testNodeDisplay() { + public function testNodeDisplay() { $field_name = strtolower($this->randomName()); $type_name = 'article'; $field_settings = array( @@ -44,7 +47,8 @@ function testNodeDisplay() { $node = $this->drupalCreateNode(array('type' => $type_name)); // Check file_default last as the assertions below assume that this is the // case. - $file_formatters = array('file_table', 'file_url_plain', 'hidden', 'file_default'); + $file_formatters = array('file_table', 'file_url_plain', + 'hidden', 'file_default'); foreach ($file_formatters as $formatter) { $edit = array( "fields[$field_name][type]" => $formatter, @@ -69,7 +73,8 @@ function testNodeDisplay() { $default_output = drupal_render($file_link); $this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.'); - // Turn the "display" option off and check that the file is no longer displayed. + // Turn the "display" option off and + // Check that the file is no longer displayed. $edit = array($field_name . '[0][display]' => FALSE); $this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php index 3366b2b..9d4190c 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php @@ -13,6 +13,9 @@ * Tests that files are uploaded to proper locations. */ class FileFieldPathTest extends FileFieldTestBase { + /** + * Get info of File Field. + */ public static function getInfo() { return array( 'name' => 'File field file path tests', @@ -24,7 +27,7 @@ public static function getInfo() { /** * Tests the normal formatter display on node display. */ - function testUploadPath() { + public function testUploadPath() { $field_name = strtolower($this->randomName()); $type_name = 'article'; $this->createFileField($field_name, 'node', $type_name); @@ -61,7 +64,7 @@ function testUploadPath() { $node_file = file_load($node->{$field_name}->target_id); // Do token replacement using the same user which uploaded the file, not // the user running the test case. - $data = array('user' => $this->admin_user); + $data = array('user' => $this->adminUser); $subdirectory = \Drupal::token()->replace('[user:uid]/[user:name]', $data); $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->getFileUri()))); } @@ -69,15 +72,15 @@ function testUploadPath() { /** * Asserts that a file is uploaded to the right location. * - * @param $expected_path + * @param string $expected_path * The location where the file is expected to be uploaded. Duplicate file * names to not need to be taken into account. - * @param $actual_path + * @param string $actual_path * Where the file was actually uploaded. - * @param $message + * @param string $message * The message to display with this assertion. */ - function assertPathMatch($expected_path, $actual_path, $message) { + public function assertPathMatch($expected_path, $actual_path, $message) { // Strip off the extension of the expected path to allow for _0, _1, etc. // suffixes when the file hits a duplicate name. $pos = strrpos($expected_path, '.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php index ba46dc6..fedce5b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php @@ -21,6 +21,9 @@ class FileFieldRSSContentTest extends FileFieldTestBase { */ public static $modules = array('node', 'views'); + /** + * Get info of File Field. + */ public static function getInfo() { return array( 'name' => 'File field RSS content', @@ -32,7 +35,7 @@ public static function getInfo() { /** * Tests RSS enclosure formatter display for RSS feeds. */ - function testFileFieldRSSContent() { + public function testFileFieldRSSContent() { $field_name = strtolower($this->randomName()); $type_name = 'article'; $field_settings = array( @@ -78,7 +81,7 @@ function testFileFieldRSSContent() { 'attributes' => array( 'url' => url("$this->public_files_directory/$uploaded_filename", array('absolute' => TRUE)), 'length' => $node_file->getSize(), - 'type' => $node_file->getMimeType() + 'type' => $node_file->getMimeType(), ), ); $this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index f586446..c3d062a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -13,6 +13,9 @@ * Tests file handling with node revisions. */ class FileFieldRevisionTest extends FileFieldTestBase { + /** + * Get info of File field. + */ public static function getInfo() { return array( 'name' => 'File field revision test', @@ -32,7 +35,7 @@ public static function getInfo() { * - When the last revision that uses a file is deleted, the original file * should be deleted also. */ - function testRevisions() { + public function testRevisions() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 82d043a..ebc98f5 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -16,25 +16,30 @@ abstract class FileFieldTestBase extends WebTestBase { /** - * Modules to enable. - * - * @var array - */ + * Modules to enable. + * + * @var array + */ public static $modules = array('node', 'file', 'file_module_test', 'field_ui'); - protected $admin_user; - - function setUp() { + protected $adminUser; + /** + * Set up user and content type. + */ + public function setUp() { parent::setUp(); - $this->admin_user = $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->admin_user); + $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(array('type' => 'article', 'name' => 'Article')); } /** * Retrieves a sample file of the specified type. */ - function getTestFile($type_name, $size = NULL) { + public function getTestFile($type_name, $size = NULL) { // Get a file to upload. $file = current($this->drupalGetTestFiles($type_name, $size)); @@ -47,27 +52,27 @@ function getTestFile($type_name, $size = NULL) { /** * Retrieves the fid of the last inserted file. */ - function getLastFileId() { + public function getLastFileId() { return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField(); } /** * Creates a new file field. * - * @param $name + * @param string $name * The name of the new field (all lowercase), exclude the "field_" prefix. - * @param $entity_type + * @param string $entity_type * The entity type. - * @param $bundle + * @param string $bundle * The bundle that this field will be added to. - * @param $field_settings + * @param array $field_settings * A list of field settings that will be added to the defaults. - * @param $instance_settings + * @param array $instance_settings * A list of instance settings that will be added to the instance defaults. - * @param $widget_settings + * @param array $widget_settings * A list of widget settings that will be added to the widget defaults. */ - function createFileField($name, $entity_type, $bundle, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) { + public function createFileField($name, $entity_type, $bundle, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) { $field_definition = array( 'entity_type' => $entity_type, 'name' => $name, @@ -86,20 +91,18 @@ function createFileField($name, $entity_type, $bundle, $field_settings = array() /** * Attaches a file field to an entity. * - * @param $name + * @param string $name * The name of the new field (all lowercase), exclude the "field_" prefix. - * @param $entity_type + * @param string $entity_type * The entity type this field will be added to. - * @param $bundle + * @param string $bundle * The bundle this field will be added to. - * @param $field_settings - * A list of field settings that will be added to the defaults. - * @param $instance_settings + * @param array $instance_settings * A list of instance settings that will be added to the instance defaults. - * @param $widget_settings + * @param array $widget_settings * A list of widget settings that will be added to the widget defaults. */ - function attachFileField($name, $entity_type, $bundle, $instance_settings = array(), $widget_settings = array()) { + public function attachFileField($name, $entity_type, $bundle, $instance_settings = array(), $widget_settings = array()) { $instance = array( 'field_name' => $name, 'label' => $name, @@ -122,7 +125,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra /** * Updates an existing file field with new settings. */ - function updateFileField($name, $type_name, $instance_settings = array(), $widget_settings = array()) { + public function updateFileField($name, $type_name, $instance_settings = array(), $widget_settings = array()) { $instance = field_info_instance('node', $name, $type_name); $instance->settings = array_merge($instance->settings, $instance_settings); $instance->save(); @@ -137,7 +140,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge /** * Uploads a file to a node. */ - function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) { + public function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) { $edit = array( 'title[0][value]' => $this->randomName(), 'revision' => (string) (int) $new_revision, @@ -175,7 +178,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, * * Note that if replacing a file, it must first be removed then added again. */ - function removeNodeFile($nid, $new_revision = TRUE) { + public function removeNodeFile($nid, $new_revision = TRUE) { $edit = array( 'revision' => (string) (int) $new_revision, ); @@ -187,7 +190,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { /** * Replaces a file within a node. */ - function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { + public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { $edit = array( 'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()), 'revision' => (string) (int) $new_revision, @@ -200,7 +203,7 @@ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { /** * Asserts that a file exists physically on disk. */ - function assertFileExists($file, $message = NULL) { + public function assertFileExists($file, $message = NULL) { $message = isset($message) ? $message : format_string('File %file exists on the disk.', array('%file' => $file->getFileUri())); $this->assertTrue(is_file($file->getFileUri()), $message); } @@ -208,7 +211,7 @@ function assertFileExists($file, $message = NULL) { /** * Asserts that a file exists in the database. */ - function assertFileEntryExists($file, $message = NULL) { + public function assertFileEntryExists($file, $message = NULL) { $this->container->get('entity.manager')->getStorageController('file')->resetCache(); $db_file = file_load($file->id()); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); @@ -218,7 +221,7 @@ function assertFileEntryExists($file, $message = NULL) { /** * Asserts that a file does not exist on disk. */ - function assertFileNotExists($file, $message = NULL) { + public function assertFileNotExists($file, $message = NULL) { $message = isset($message) ? $message : format_string('File %file exists on the disk.', array('%file' => $file->getFileUri())); $this->assertFalse(is_file($file->getFileUri()), $message); } @@ -226,7 +229,7 @@ function assertFileNotExists($file, $message = NULL) { /** * Asserts that a file does not exist in the database. */ - function assertFileEntryNotExists($file, $message) { + public function assertFileEntryNotExists($file, $message) { $this->container->get('entity.manager')->getStorageController('file')->resetCache(); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); $this->assertFalse(file_load($file->id()), $message); @@ -235,7 +238,7 @@ function assertFileEntryNotExists($file, $message) { /** * Asserts that a file's status is set to permanent in the database. */ - function assertFileIsPermanent(FileInterface $file, $message = NULL) { + public function assertFileIsPermanent(FileInterface $file, $message = NULL) { $message = isset($message) ? $message : format_string('File %file is permanent.', array('%file' => $file->getFileUri())); $this->assertTrue($file->isPermanent(), $message); } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index b85b187..f36e8bf 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -15,8 +15,11 @@ */ class FileFieldValidateTest extends FileFieldTestBase { protected $field; - protected $node_type; + protected $nodeType; + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File field validation tests', @@ -28,7 +31,7 @@ public static function getInfo() { /** * Tests the required property on file fields. */ - function testRequired() { + public function testRequired() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $field = $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); @@ -44,7 +47,12 @@ function testRequired() { // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $this->assertTrue($nid !== FALSE, format_string('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name))); + $this->assertTrue($nid !== FALSE, format_string('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', + array( + '@test_file' => $test_file->getFileUri(), + '@field_name' => $field_name, + '@type_name' => $type_name, + ))); $node = node_load($nid, TRUE); @@ -73,13 +81,15 @@ function testRequired() { /** * Tests the max file size validator. */ - function testFileMaxSize() { + public function testFileMaxSize() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); - $small_file = $this->getTestFile('text', 131072); // 128KB. - $large_file = $this->getTestFile('text', 1310720); // 1.2MB + // 128KB. + $small_file = $this->getTestFile('text', 131072); + // 1.2MB + $large_file = $this->getTestFile('text', 1310720); // Test uploading both a large and small file with different increments. $sizes = array( @@ -119,7 +129,7 @@ function testFileMaxSize() { /** * Tests file extension checking. */ - function testFileExtension() { + public function testFileExtension() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index bf80c17..da5acbc 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -18,7 +18,9 @@ class FileFieldWidgetTest extends FileFieldTestBase { * @var array */ public static $modules = array('comment'); - + /** + * Get info of File field. + */ public static function getInfo() { return array( 'name' => 'File field widget test', @@ -30,7 +32,7 @@ public static function getInfo() { /** * Tests upload and remove buttons for a single-valued File field. */ - function testSingleValuedWidget() { + public function testSingleValuedWidget() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name); @@ -61,6 +63,7 @@ function testSingleValuedWidget() { case 'nojs': $this->drupalPostForm(NULL, array(), t('Remove')); break; + case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Remove') . '"]'); $this->drupalPostAjaxForm(NULL, array(), array((string) $button[0]['name'] => (string) $button[0]['value'])); @@ -84,7 +87,7 @@ function testSingleValuedWidget() { /** * Tests upload and remove buttons for multiple multi-valued File fields. */ - function testMultiValuedWidget() { + public function testMultiValuedWidget() { $type_name = 'article'; // Use explicit names instead of random names for those fields, because of a // bug in drupalPostForm() with multiple file uploads in one form, where the @@ -105,15 +108,15 @@ function testMultiValuedWidget() { // until after the 3rd file, and after that, isn't displayed. Because // SimpleTest triggers the last button with a given name, so upload to the // second field first. - // @todo This is only testing a non-Ajax upload, because drupalPostAjaxForm() - // does not yet emulate jQuery's file upload. + // @todo This is only testing a non-Ajax upload, because + // drupalPostAjaxForm() does not yet emulate jQuery's file upload. // $this->drupalGet("node/add/$type_name"); foreach (array($field_name2, $field_name) as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { $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. + // If the Upload button doesn't exist, + // drupalPostForm() will automatically fail with an assertion message. $this->drupalPostForm(NULL, $edit, t('Upload')); } } @@ -124,13 +127,13 @@ function testMultiValuedWidget() { 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 - // of sequential order. They are 0-indexed, and get renumbered after each - // iteration, so array(1, 1, 0) means: + // Test clicking each "Remove" button. For extra robustness, + // test them out of sequential order. They are 0-indexed, + // and get renumbered after each iteration, so array(1, 1, 0) means: // - First remove the 2nd file. - // - Then remove what is then the 2nd file (was originally the 3rd file). + // - Then remove what is then the 2nd file(was originally the 3rd file). // - Then remove the first file. - foreach (array(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"]'); @@ -142,20 +145,21 @@ function testMultiValuedWidget() { $check_field_name = $field_name; } - $this->assertIdentical((string) $button['name'], $check_field_name . '_' . $key. '_remove_button'); + $this->assertIdentical((string) $button['name'], $check_field_name . '_' . $key . '_remove_button'); } - // "Click" the remove button (emulating either a nojs or js submission). + // "Click" remove button (emulating either a nojs or js submission). $button_name = $current_field_name . '_' . $delta . '_remove_button'; switch ($type) { case 'nojs': - // drupalPostForm() takes a $submit parameter that is the value of the - // button whose click we want to emulate. Since we have multiple - // buttons with the value "Remove", and want to control which one we - // use, we change the value of the other ones to something else. - // Since non-clicked buttons aren't included in the submitted POST - // data, and since drupalPostForm() will result in $this being updated - // with a newly rebuilt form, this doesn't cause problems. + // drupalPostForm() takes a $submit parameter that is the value of + // the button whose click we want to emulate. Since we have + // multiple buttons with the value "Remove", and want to control + // which one we use, we change the value of the other ones to + // something else. Since non-clicked buttons aren't included in + // the submitted POST data, and since drupalPostForm() will result + // in $this being updated with a newly rebuilt form, this doesn't + // cause problems. foreach ($buttons as $button) { if ($button['name'] != $button_name) { $button['value'] = 'DUMMY'; @@ -163,17 +167,18 @@ function testMultiValuedWidget() { } $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. + // drupalPostAjaxForm() lets us target the button precisely, so + // we don't require the workaround used above for nojs. $this->drupalPostAjaxForm(NULL, array(), array($button_name => t('Remove'))); break; } $num_expected_remove_buttons--; $remaining--; - // Ensure an "Upload" button for the current field is displayed with the - // correct name. + // 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]', 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))); @@ -201,7 +206,7 @@ function testMultiValuedWidget() { /** * Tests a file field with a "Private files" upload destination setting. */ - function testPrivateFileSetting() { + public function testPrivateFileSetting() { // Grant the admin user required permissions. user_role_grant_permissions($this->admin_user->roles[0]->value, array('administer node fields')); @@ -238,7 +243,7 @@ function testPrivateFileSetting() { /** * Tests that download restrictions on private files work on comments. */ - function testPrivateFileComment() { + public function testPrivateFileComment() { $user = $this->drupalCreateUser(array('access comments')); // Grant the admin user required comment permissions. @@ -314,7 +319,7 @@ function testPrivateFileComment() { /** * Tests validation with the Upload button. */ - function testWidgetValidation() { + public function testWidgetValidation() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name); @@ -335,6 +340,7 @@ function testWidgetValidation() { case 'nojs': $this->drupalPostForm(NULL, $edit, t('Upload')); break; + case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]'); $this->drupalPostAjaxForm(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value'])); @@ -343,12 +349,14 @@ function testWidgetValidation() { $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. + // Upload file with correct extension, + // check that error message is removed. $edit[$name] = drupal_realpath($test_file_text->getFileUri()); switch ($type) { case 'nojs': $this->drupalPostForm(NULL, $edit, t('Upload')); break; + case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]'); $this->drupalPostAjaxForm(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value'])); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php index 0f40a14..d55b1ca 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php @@ -30,7 +30,9 @@ class FileItemTest extends FieldUnitTestBase { * @var \Drupal\file\Entity\File */ protected $file; - + /** + * Get info of File field item API. + */ public static function getInfo() { return array( 'name' => 'File field item API', @@ -38,7 +40,9 @@ public static function getInfo() { 'group' => 'File', ); } - + /** + * Set up file field item. + */ public function setUp() { parent::setUp(); @@ -67,7 +71,7 @@ public function setUp() { * Tests using entity fields of the file field type. */ public function testFileItem() { - // Create a test entity with the + // Create a test entity with the. $entity = entity_create('entity_test'); $entity->file_test->target_id = $this->file->id(); $entity->file_test->display = 1; diff --git a/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php b/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php index dd27484..26eefb0 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php @@ -19,6 +19,9 @@ class FileListingTest extends FileFieldTestBase { */ public static $modules = array('views', 'file', 'image'); + /** + * Get info of testing file. + */ public static function getInfo() { return array( 'name' => 'File listing', @@ -26,8 +29,10 @@ public static function getInfo() { 'group' => 'File', ); } - - function setUp() { + /** + * Set up file info. + */ + public function setUp() { parent::setUp(); $this->admin_user = $this->drupalCreateUser(array('access files overview', 'bypass node access')); @@ -38,8 +43,9 @@ function setUp() { /** * Calculates total count of usages for a file. * - * @param $usage array + * @param array $usage * Array of file usage information as returned from file_usage subsystem. + * * @return int * Total usage count. */ @@ -59,7 +65,7 @@ protected function sumUsages($usage) { /** * Tests file overview with different user permissions. */ - function testFileListingPages() { + public function testFileListingPages() { $file_usage = $this->container->get('file.usage'); // Users without sufficient permissions should not see file listing. $this->drupalLogin($this->base_user); @@ -149,7 +155,7 @@ function testFileListingPages() { * Creates and saves a test file. * * @return \Drupal\Core\Entity\EntityInterface - * A file entity. + * A file entity. */ protected function createFile() { // Create a new file entity. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php index 94b34ee..a5b65a6 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php @@ -14,6 +14,9 @@ * that aren't related to fields into it. */ class FileManagedFileElementTest extends FileFieldTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'Managed file element test', @@ -25,7 +28,7 @@ public static function getInfo() { /** * Tests the managed_file element type. */ - function testManagedFile() { + public function testManagedFile() { // Check that $element['#size'] is passed to the child upload element. $this->drupalGet('file/test'); $this->assertFieldByXpath('//input[@name="files[nested_file]" and @size="13"]', NULL, 'The custom #size attribute is passed to the child upload element.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php index c777691..f89ccc8 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php @@ -23,21 +23,25 @@ */ public static $modules = array('file_test', 'file'); - function setUp() { + /** + * Set up info of file. + */ + public function setUp() { parent::setUp(); // Clear out any hook calls. file_test_reset(); } /** - * Assert that all of the specified hook_file_* hooks were called once, other - * values result in failure. + * Assert that all of the specified hook_file_* hooks were called once. + * + * other values result in failure. * - * @param $expected + * @param array $expected * Array with string containing with the hook name, e.g. 'load', 'save', * 'insert', etc. */ - function assertFileHooksCalled($expected) { + public function assertFileHooksCalled($expected) { \Drupal::state()->resetCache(); // Determine which hooks were called. @@ -46,7 +50,11 @@ function assertFileHooksCalled($expected) { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { - $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', array('%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)))); + $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', + array( + '%expected' => implode(', ', $expected), + '%uncalled' => implode(', ', $uncalled), + ))); } else { $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', array('%expected' => empty($expected) ? '(none)' : implode(', ', $expected)))); @@ -65,14 +73,14 @@ function assertFileHooksCalled($expected) { /** * Assert that a hook_file_* hook was called a certain number of times. * - * @param $hook + * @param string $hook * String with the hook name, e.g. 'load', 'save', 'insert', etc. - * @param $expected_count + * @param int $expected_count * Optional integer count. - * @param $message + * @param string $message * Optional translated string message. */ - function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { + public function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $actual_count = count(file_test_get_calls($hook)); if (!isset($message)) { @@ -83,7 +91,12 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count)); } else { - $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array('@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count)); + $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', + array( + '@name' => $hook, + '%expected' => $expected_count, + '%actual' => $actual_count, + )); } } $this->assertEqual($actual_count, $expected_count, $message); @@ -97,7 +110,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { * @param \Drupal\file\FileInterface $after * File object to compare. */ - function assertFileUnchanged(FileInterface $before, FileInterface $after) { + public function assertFileUnchanged(FileInterface $before, FileInterface $after) { $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged'); $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged'); $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged'); @@ -115,7 +128,7 @@ function assertFileUnchanged(FileInterface $before, FileInterface $after) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ - function assertDifferentFile(FileInterface $file1, FileInterface $file2) { + public function assertDifferentFile(FileInterface $file1, FileInterface $file2) { $this->assertNotEqual($file1->id(), $file2->id(), t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->id(), '%file2' => $file2->id())), 'Different file'); $this->assertNotEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Different file'); } @@ -128,28 +141,30 @@ function assertDifferentFile(FileInterface $file1, FileInterface $file2) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ - function assertSameFile(FileInterface $file1, FileInterface $file2) { + public function assertSameFile(FileInterface $file1, FileInterface $file2) { $this->assertEqual($file1->id(), $file2->id(), t('Files have the same ids: %file1 == %file2.', array('%file1' => $file1->id(), '%file2-fid' => $file2->id())), 'Same file'); $this->assertEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Same file'); } /** - * Create a file and save it to the files table and assert that it occurs - * correctly. + * Create a file and save it to the files table and assert. * - * @param $filepath + * that it occurs correctly. + * + * @param string $filepath * Optional string specifying the file path. If none is provided then a * randomly named file will be created in the site's files directory. - * @param $contents + * @param string $contents * Optional contents to save into the file. If a NULL value is provided an * arbitrary string will be used. - * @param $scheme + * @param string $scheme * Optional string indicating the stream scheme to use. Drupal core includes * public, private, and temporary. The public wrapper is the default. - * @return \Drupal\file\FileInterface - * File entity. + * + * @return string + * \Drupal\file\FileInterface File entity. */ - function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { + public function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { $file = new \stdClass(); $file->uri = $this->createUri($filepath, $contents, $scheme); $file->filename = drupal_basename($file->uri); @@ -184,7 +199,7 @@ function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { * @return string * File URI. */ - function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { + public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { if (!isset($filepath)) { // Prefix with non-latin characters to ensure that all file-related // tests work with international filenames. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php index 324b1b5..5f60d7d 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedUnitTestBase.php @@ -11,8 +11,8 @@ use Drupal\simpletest\DrupalUnitTestBase; /** - * Base class for file unit tests that use the file_test module to test uploads and - * hooks. + * Base class for file unit tests that use the file_test module to test uploads + * and hooks. */ abstract class FileManagedUnitTestBase extends DrupalUnitTestBase { @@ -23,7 +23,10 @@ */ public static $modules = array('file_test', 'file', 'system', 'field', 'user'); - function setUp() { + /** + * Set up info of file. + */ + public function setUp() { parent::setUp(); // Clear out any hook calls. file_test_reset(); @@ -41,14 +44,15 @@ function setUp() { } /** - * Assert that all of the specified hook_file_* hooks were called once, other - * values result in failure. + * Assert that all of the specified hook_file_* hooks were called once. * - * @param $expected + * other values result in failure. + * + * @param array $expected * Array with string containing with the hook name, e.g. 'load', 'save', * 'insert', etc. */ - function assertFileHooksCalled($expected) { + public function assertFileHooksCalled($expected) { \Drupal::state()->resetCache(); // Determine which hooks were called. @@ -57,7 +61,11 @@ function assertFileHooksCalled($expected) { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { - $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', array('%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)))); + $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', + array( + '%expected' => implode(', ', $expected), + '%uncalled' => implode(', ', $uncalled), + ))); } else { $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', array('%expected' => empty($expected) ? '(none)' : implode(', ', $expected)))); @@ -76,14 +84,14 @@ function assertFileHooksCalled($expected) { /** * Assert that a hook_file_* hook was called a certain number of times. * - * @param $hook + * @param string $hook * String with the hook name, e.g. 'load', 'save', 'insert', etc. - * @param $expected_count + * @param int $expected_count * Optional integer count. - * @param $message + * @param string $message * Optional translated string message. */ - function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { + public function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $actual_count = count(file_test_get_calls($hook)); if (!isset($message)) { @@ -94,7 +102,12 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count)); } else { - $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array('@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count)); + $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', + array( + '@name' => $hook, + '%expected' => $expected_count, + '%actual' => $actual_count, + )); } } $this->assertEqual($actual_count, $expected_count, $message); @@ -108,7 +121,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { * @param \Drupal\file\FileInterface $after * File object to compare. */ - function assertFileUnchanged(FileInterface $before, FileInterface $after) { + public function assertFileUnchanged(FileInterface $before, FileInterface $after) { $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged'); $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged'); $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged'); @@ -126,7 +139,7 @@ function assertFileUnchanged(FileInterface $before, FileInterface $after) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ - function assertDifferentFile(FileInterface $file1, FileInterface $file2) { + public function assertDifferentFile(FileInterface $file1, FileInterface $file2) { $this->assertNotEqual($file1->id(), $file2->id(), t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->id(), '%file2' => $file2->id())), 'Different file'); $this->assertNotEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Different file'); } @@ -139,28 +152,30 @@ function assertDifferentFile(FileInterface $file1, FileInterface $file2) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ - function assertSameFile(FileInterface $file1, FileInterface $file2) { + public function assertSameFile(FileInterface $file1, FileInterface $file2) { $this->assertEqual($file1->id(), $file2->id(), t('Files have the same ids: %file1 == %file2.', array('%file1' => $file1->id(), '%file2-fid' => $file2->id())), 'Same file'); $this->assertEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Same file'); } /** - * Create a file and save it to the files table and assert that it occurs - * correctly. + * Create a file and save it to the files table and assert that. + * + * it occurs correctly. * - * @param $filepath + * @param string $filepath * Optional string specifying the file path. If none is provided then a * randomly named file will be created in the site's files directory. - * @param $contents + * @param string $contents * Optional contents to save into the file. If a NULL value is provided an * arbitrary string will be used. - * @param $scheme + * @param string $scheme * Optional string indicating the stream scheme to use. Drupal core includes * public, private, and temporary. The public wrapper is the default. + * * @return \Drupal\file\FileInterface * File entity. */ - function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { + public function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { $file = new \stdClass(); $file->uri = $this->createUri($filepath, $contents, $scheme); $file->filename = drupal_basename($file->uri); @@ -193,7 +208,7 @@ function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { * @return string * File URI. */ - function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { + public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { if (!isset($filepath)) { // Prefix with non-latin characters to ensure that all file-related // tests work with international filenames. diff --git a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php index e51ba64..c92d54d 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php @@ -15,12 +15,14 @@ class FilePrivateTest extends FileFieldTestBase { /** - * Modules to enable. - * - * @var array - */ + * Modules to enable. + * + * @var array + */ public static $modules = array('node_access_test', 'field_test'); - + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'Private file test', @@ -28,7 +30,9 @@ public static function getInfo() { 'group' => 'File', ); } - + /** + * Set up info of file. + */ public function setUp() { parent::setUp(); node_access_rebuild(); @@ -38,7 +42,7 @@ public function setUp() { /** * Tests file access for file uploaded to a private node. */ - function testPrivateFile() { + public function testPrivateFile() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 35bb593..0b843e9 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -13,6 +13,9 @@ * Tests the file token replacement in strings. */ class FileTokenReplaceTest extends FileFieldTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File token replacement', @@ -24,7 +27,7 @@ public static function getInfo() { /** * Creates a file, then tests the tokens generated from it. */ - function testFileTokenReplacement() { + public function testFileTokenReplacement() { $token_service = \Drupal::token(); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); diff --git a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php index bf6a1e9..2430398 100644 --- a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php @@ -11,6 +11,9 @@ * Tests the file_load() function. */ class LoadTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File loading', @@ -22,7 +25,7 @@ public static function getInfo() { /** * Try to load a non-existent file by fid. */ - function testLoadMissingFid() { + public function testLoadMissingFid() { $this->assertFalse(file_load(-1), 'Try to load an invalid fid fails.'); $this->assertFileHooksCalled(array()); } @@ -30,7 +33,7 @@ function testLoadMissingFid() { /** * Try to load a non-existent file by URI. */ - function testLoadMissingFilepath() { + public function testLoadMissingFilepath() { $files = entity_load_multiple_by_properties('file', array('uri' => 'foobar://misc/druplicon.png')); $this->assertFalse(reset($files), "Try to load a file that doesn't exist in the database fails."); $this->assertFileHooksCalled(array()); @@ -39,7 +42,7 @@ function testLoadMissingFilepath() { /** * Try to load a non-existent file by status. */ - function testLoadInvalidStatus() { + public function testLoadInvalidStatus() { $files = entity_load_multiple_by_properties('file', array('status' => -99)); $this->assertFalse(reset($files), 'Trying to load a file with an invalid status fails.'); $this->assertFileHooksCalled(array()); @@ -48,7 +51,7 @@ function testLoadInvalidStatus() { /** * Load a single file and ensure that the correct values are returned. */ - function testSingleValues() { + public function testSingleValues() { // Create a new file entity from scratch so we know the values. $file = $this->createFile('druplicon.txt', NULL, 'public'); @@ -66,7 +69,7 @@ function testSingleValues() { /** * This will test loading file data from the database. */ - function testMultiple() { + public function testMultiple() { // Create a new file entity. $file = $this->createFile('druplicon.txt', NULL, 'public'); diff --git a/core/modules/file/lib/Drupal/file/Tests/MoveTest.php b/core/modules/file/lib/Drupal/file/Tests/MoveTest.php index b063afa..083d82b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/MoveTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/MoveTest.php @@ -11,6 +11,9 @@ * Move related tests */ class MoveTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File moving', @@ -22,7 +25,7 @@ public static function getInfo() { /** * Move a normal file. */ - function testNormal() { + public function testNormal() { $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); $desired_filepath = 'public://' . $this->randomName(); @@ -52,7 +55,7 @@ function testNormal() { /** * Test renaming when moving onto a file that already exists. */ - function testExistingRename() { + public function testExistingRename() { // Setup a file to overwrite. $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); @@ -87,7 +90,7 @@ function testExistingRename() { /** * Test replacement when moving onto a file that already exists. */ - function testExistingReplace() { + public function testExistingReplace() { // Setup a file to overwrite. $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); @@ -119,7 +122,7 @@ function testExistingReplace() { /** * Test replacement when moving onto itself. */ - function testExistingReplaceSelf() { + public function testExistingReplaceSelf() { // Setup a file to overwrite. $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); @@ -139,10 +142,11 @@ function testExistingReplaceSelf() { } /** - * Test that moving onto an existing file fails when FILE_EXISTS_ERROR is - * specified. + * Test that moving onto an existing file fails when. + * + * FILE_EXISTS_ERROR is specified. */ - function testExistingError() { + public function testExistingError() { $contents = $this->randomName(10); $source = $this->createFile(); $target = $this->createFile(NULL, $contents); diff --git a/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php b/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php index 6f2000c..c26cbae 100644 --- a/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php @@ -19,13 +19,18 @@ class RemoteFileSaveUploadTest extends SaveUploadTest { */ public static $modules = array('file_test'); + /** + * Get info of file. + */ public static function getInfo() { $info = parent::getInfo(); $info['group'] = 'File Managed API (remote)'; return $info; } - - function setUp() { + /** + * Set up info of file. + */ + public function setUp() { parent::setUp(); \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save(); } diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php index 081b6b3..46b381f 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php @@ -11,6 +11,9 @@ * Tests the file_save_data() function. */ class SaveDataTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File save data', @@ -22,7 +25,7 @@ public static function getInfo() { /** * Test the file_save_data() function when no filename is provided. */ - function testWithoutFilename() { + public function testWithoutFilename() { $contents = $this->randomName(8); $result = file_save_data($contents); @@ -44,7 +47,7 @@ function testWithoutFilename() { /** * Test the file_save_data() function when a filename is provided. */ - function testWithFilename() { + public function testWithFilename() { $contents = $this->randomName(8); // Using filename with non-latin characters. @@ -69,7 +72,7 @@ function testWithFilename() { /** * Test file_save_data() when renaming around an existing file. */ - function testExistingRename() { + public function testExistingRename() { // Setup a file to overwrite. $existing = $this->createFile(); $contents = $this->randomName(8); @@ -97,7 +100,7 @@ function testExistingRename() { /** * Test file_save_data() when replacing an existing file. */ - function testExistingReplace() { + public function testExistingReplace() { // Setup a file to overwrite. $existing = $this->createFile(); $contents = $this->randomName(8); @@ -124,7 +127,7 @@ function testExistingReplace() { /** * Test that file_save_data() fails overwriting an existing file. */ - function testExistingError() { + public function testExistingError() { $contents = $this->randomName(8); $existing = $this->createFile(NULL, $contents); diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php index 50d6847..b4202fa 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php @@ -13,6 +13,9 @@ * Tests saving files. */ class SaveTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File saving', @@ -20,8 +23,10 @@ public static function getInfo() { 'group' => 'File Managed API', ); } - - function testFileSave() { + /** + * Test file save. + */ + public function testFileSave() { // Create a new file entity. $file = entity_create('file', array( 'uid' => 1, @@ -64,8 +69,9 @@ function testFileSave() { $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was saved correctly.'); - // Try to insert a second file with the same name apart from case insensitivity - // to ensure the 'uri' index allows for filenames with different cases. + // Try to insert a second file with the same name apart from case + // insensitivity to ensure the 'uri' index allows for filenames + // with different cases. $file = entity_create('file', array( 'uid' => 1, 'filename' => 'DRUPLICON.txt', diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php index 6596f87..49838eb 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php @@ -26,6 +26,9 @@ class SaveUploadTest extends FileManagedTestBase { */ protected $maxFidBefore; + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File uploading', @@ -34,7 +37,10 @@ public static function getInfo() { ); } - function setUp() { + /** + * Set up info of file. + */ + public function setUp() { parent::setUp(); $account = $this->drupalCreateUser(); $this->drupalLogin($account); @@ -68,7 +74,7 @@ function setUp() { /** * Test the file_save_upload() function. */ - function testNormal() { + public function testNormal() { $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); $this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.'); $file1 = file_load($max_fid_after); @@ -117,7 +123,7 @@ function testNormal() { /** * Test extension handling. */ - function testHandleExtension() { + public function testHandleExtension() { // The file being tested is a .gif which is in the default safe list // of extensions to allow when the extension validator isn't used. This is // implicitly tested at the testNormal() test. Here we tell @@ -178,7 +184,7 @@ function testHandleExtension() { /** * Test dangerous file handling. */ - function testHandleDangerousFile() { + public function testHandleDangerousFile() { $config = \Drupal::config('system.file'); // Allow the .php extension and make sure it gets renamed to .txt for // safety. Also check to make sure its MIME type was changed. @@ -221,7 +227,7 @@ function testHandleDangerousFile() { /** * Test file munge handling. */ - function testHandleFileMunge() { + public function testHandleFileMunge() { // Ensure insecure uploads are disabled for this test. \Drupal::config('system.file')->set('allow_insecure_uploads', 0)->save(); $this->image = file_move($this->image, $this->image->getFileUri() . '.foo.' . $this->image_extension); @@ -270,10 +276,10 @@ function testHandleFileMunge() { /** * Test renaming when uploading over a file that already exists. */ - function testExistingRename() { + public function testExistingRename() { $edit = array( 'file_test_replace' => FILE_EXISTS_RENAME, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -286,10 +292,10 @@ function testExistingRename() { /** * Test replacement when uploading over a file that already exists. */ - function testExistingReplace() { + public function testExistingReplace() { $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -302,10 +308,10 @@ function testExistingReplace() { /** * Test for failure when uploading over a file that already exists. */ - function testExistingError() { + public function testExistingError() { $edit = array( 'file_test_replace' => FILE_EXISTS_ERROR, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -318,7 +324,7 @@ function testExistingError() { /** * Test for no failures when not uploading a file. */ - function testNoUpload() { + public function testNoUpload() { $this->drupalPostForm('file-test/upload', array(), t('Submit')); $this->assertNoRaw(t('Epic upload FAIL!'), 'Failure message not found.'); } diff --git a/core/modules/file/lib/Drupal/file/Tests/SpaceUsedTest.php b/core/modules/file/lib/Drupal/file/Tests/SpaceUsedTest.php index 325990e..57987c2 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SpaceUsedTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SpaceUsedTest.php @@ -11,6 +11,9 @@ * This will run tests against the $file_managed->spaceUsed() function. */ class SpaceUsedTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File space used tests', @@ -18,38 +21,70 @@ public static function getInfo() { 'group' => 'File Managed API', ); } - - function setUp() { + /** + * Set up info of file. + */ + public function setUp() { parent::setUp(); // Create records for a couple of users with different sizes. - $file = array('uid' => 2, 'uri' => 'public://example1.txt', 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT); + $file = array( + 'uid' => 2, + 'uri' => 'public://example1.txt', + 'filesize' => 50, + 'status' => FILE_STATUS_PERMANENT, + ); db_insert('file_managed')->fields($file)->execute(); - $file = array('uid' => 2, 'uri' => 'public://example2.txt', 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT); + $file = array( + 'uid' => 2, + 'uri' => 'public://example2.txt', + 'filesize' => 20, + 'status' => FILE_STATUS_PERMANENT, + ); db_insert('file_managed')->fields($file)->execute(); - $file = array('uid' => 3, 'uri' => 'public://example3.txt', 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT); + $file = array( + 'uid' => 3, + 'uri' => 'public://example3.txt', + 'filesize' => 100, + 'status' => FILE_STATUS_PERMANENT, + ); db_insert('file_managed')->fields($file)->execute(); - $file = array('uid' => 3, 'uri' => 'public://example4.txt', 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT); + $file = array( + 'uid' => 3, + 'uri' => 'public://example4.txt', + 'filesize' => 200, + 'status' => FILE_STATUS_PERMANENT, + ); db_insert('file_managed')->fields($file)->execute(); // Now create some non-permanent files. - $file = array('uid' => 2, 'uri' => 'public://example5.txt', 'filesize' => 1, 'status' => 0); + $file = array( + 'uid' => 2, + 'uri' => 'public://example5.txt', + 'filesize' => 1, + 'status' => 0, + ); db_insert('file_managed')->fields($file)->execute(); - $file = array('uid' => 3, 'uri' => 'public://example6.txt', 'filesize' => 3, 'status' => 0); + $file = array( + 'uid' => 3, + 'uri' => 'public://example6.txt', + 'filesize' => 3, + 'status' => 0, + ); db_insert('file_managed')->fields($file)->execute(); } /** * Test different users with the default status. */ - function testFileSpaceUsed() { + public function testFileSpaceUsed() { $file = $this->container->get('entity.manager')->getStorageController('file'); // Test different users with default status. $this->assertEqual($file->spaceUsed(2), 70); $this->assertEqual($file->spaceUsed(3), 300); $this->assertEqual($file->spaceUsed(), 370); - // Test the status fields + // Test the status fields. $this->assertEqual($file->spaceUsed(NULL, 0), 4); $this->assertEqual($file->spaceUsed(NULL, FILE_STATUS_PERMANENT), 370); diff --git a/core/modules/file/lib/Drupal/file/Tests/UsageTest.php b/core/modules/file/lib/Drupal/file/Tests/UsageTest.php index 3cff7da..937532e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/UsageTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/UsageTest.php @@ -11,6 +11,9 @@ * Tests file usage functions. */ class UsageTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File usage', @@ -22,7 +25,7 @@ public static function getInfo() { /** * Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage(). */ - function testGetUsage() { + public function testGetUsage() { $file = $this->createFile(); db_insert('file_usage') ->fields(array( @@ -30,7 +33,7 @@ function testGetUsage() { 'module' => 'testing', 'type' => 'foo', 'id' => 1, - 'count' => 1 + 'count' => 1, )) ->execute(); db_insert('file_usage') @@ -39,7 +42,7 @@ function testGetUsage() { 'module' => 'testing', 'type' => 'bar', 'id' => 2, - 'count' => 2 + 'count' => 2, )) ->execute(); @@ -55,7 +58,7 @@ function testGetUsage() { /** * Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::add(). */ - function testAddUsage() { + public function testAddUsage() { $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); $file_usage->add($file, 'testing', 'foo', 1); @@ -81,7 +84,7 @@ function testAddUsage() { /** * Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::delete(). */ - function testRemoveUsage() { + public function testRemoveUsage() { $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); db_insert('file_usage') @@ -128,7 +131,7 @@ function testRemoveUsage() { * Create files for all the possible combinations of age and status. We are * using UPDATE statements because using the API would set the timestamp. */ - function testTempFileCleanup() { + public function testTempFileCleanup() { // Temporary file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. $temp_old = file_save_data(''); db_update('file_managed') diff --git a/core/modules/file/lib/Drupal/file/Tests/ValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/ValidateTest.php index 59fa014..102dd32 100644 --- a/core/modules/file/lib/Drupal/file/Tests/ValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/ValidateTest.php @@ -11,6 +11,9 @@ * Tests the file_validate() function. */ class ValidateTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File validate', @@ -22,7 +25,7 @@ public static function getInfo() { /** * Test that the validators passed into are checked. */ - function testCallerValidation() { + public function testCallerValidation() { $file = $this->createFile(); // Empty validators. @@ -41,7 +44,8 @@ function testCallerValidation() { file_test_reset(); file_test_set_return('validate', array('Epic fail')); $failing = array('file_test_validator' => array(array('Failed', 'Badly'))); - $this->assertEqual(file_validate($file, $failing), array('Failed', 'Badly', 'Epic fail'), 'Validating returns errors.'); + $this->assertEqual(file_validate($file, $failing), array( + 'Failed', 'Badly', 'Epic fail'), 'Validating returns errors.'); $this->assertFileHooksCalled(array('validate')); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php b/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php index f054602..e5b7a52 100644 --- a/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php @@ -11,6 +11,9 @@ * This will run tests against the file validation functions (file_validate_*). */ class ValidatorTest extends FileManagedUnitTestBase { + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'File validator tests', @@ -19,7 +22,10 @@ public static function getInfo() { ); } - function setUp() { + /** + * Set up info of file. + */ + public function setUp() { parent::setUp(); $this->image = entity_create('file'); @@ -34,7 +40,7 @@ function setUp() { /** * Test the file_validate_extensions() function. */ - function testFileValidateExtensions() { + public function testFileValidateExtensions() { $file = entity_create('file', array('filename' => 'asdf.txt')); $errors = file_validate_extensions($file, 'asdf txt pork'); $this->assertEqual(count($errors), 0, 'Valid extension accepted.', 'File'); @@ -45,9 +51,9 @@ function testFileValidateExtensions() { } /** - * This ensures a specific file is actually an image. + * This ensures a specific file is actually an image. */ - function testFileValidateIsImage() { + public function testFileValidateIsImage() { $this->assertTrue(file_exists($this->image->getFileUri()), 'The image being tested exists.', 'File'); $errors = file_validate_is_image($this->image); $this->assertEqual(count($errors), 0, 'No error reported for our image file.', 'File'); @@ -58,10 +64,11 @@ function testFileValidateIsImage() { } /** - * This ensures the resolution of a specific file is within bounds. - * The image will be resized if it's too large. + * This ensures the resolution of a specific file is within bounds. + * + * The image will be resized if it's too large. */ - function testFileValidateImageResolution() { + public function testFileValidateImageResolution() { // Non-images. $errors = file_validate_image_resolution($this->non_image); $this->assertEqual(count($errors), 0, 'Should not get any errors for a non-image file.', 'File'); @@ -94,16 +101,17 @@ function testFileValidateImageResolution() { drupal_unlink('temporary://druplicon.png'); } else { - // TODO: should check that the error is returned if no toolkit is available. + // TODO: should check that the error is returned + // if no toolkit is available. $errors = file_validate_image_resolution($this->image, '5x10'); $this->assertEqual(count($errors), 1, 'Oversize images that cannot be scaled get an error.', 'File'); } } /** - * This will ensure the filename length is valid. + * This will ensure the filename length is valid. */ - function testFileValidateNameLength() { + public function testFileValidateNameLength() { // Create a new file entity. $file = entity_create('file'); @@ -128,7 +136,7 @@ function testFileValidateNameLength() { /** * Test file_validate_size(). */ - function testFileValidateSize() { + public function testFileValidateSize() { // Run these tests as a regular user. $user = entity_create('user', array('uid' => 2, 'name' => $this->randomName())); $user->enforceIsNew(); diff --git a/core/modules/file/lib/Drupal/file/Tests/Views/ExtensionViewsFieldTest.php b/core/modules/file/lib/Drupal/file/Tests/Views/ExtensionViewsFieldTest.php index 1218e05..92df5b4 100644 --- a/core/modules/file/lib/Drupal/file/Tests/Views/ExtensionViewsFieldTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/Views/ExtensionViewsFieldTest.php @@ -28,6 +28,9 @@ class ExtensionViewsFieldTest extends ViewUnitTestBase { */ public static $testViews = array('file_extension_view'); + /** + * Get info of file. + */ public static function getInfo() { return array( 'name' => 'Field: File extension', diff --git a/core/modules/file/tests/file_module_test/lib/Drupal/file_module_test/Form/FileModuleTestForm.php b/core/modules/file/tests/file_module_test/lib/Drupal/file_module_test/Form/FileModuleTestForm.php index fdd3cdb..309b1a2 100644 --- a/core/modules/file/tests/file_module_test/lib/Drupal/file_module_test/Form/FileModuleTestForm.php +++ b/core/modules/file/tests/file_module_test/lib/Drupal/file_module_test/Form/FileModuleTestForm.php @@ -13,6 +13,8 @@ class FileModuleTestForm { /** + * Returns file module test form. + * * @todo Remove file_module_test_form(). */ public function managedFileTest($tree, $extended, $multiple, $default_fids) { diff --git a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyReadOnlyStreamWrapper.php b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyReadOnlyStreamWrapper.php index d230bc5..281e701 100644 --- a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyReadOnlyStreamWrapper.php +++ b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyReadOnlyStreamWrapper.php @@ -15,7 +15,10 @@ * Dummy stream wrapper implementation (dummy-readonly://). */ class DummyReadOnlyStreamWrapper extends LocalReadOnlyStream { - function getDirectoryPath() { + /** + * Get Directory path of files. + */ + public function getDirectoryPath() { return conf_path() . '/files'; } @@ -24,7 +27,7 @@ function getDirectoryPath() { * * Return a dummy path for testing. */ - function getInternalUri() { + public function getInternalUri() { return '/dummy/example.txt'; } @@ -33,7 +36,7 @@ function getInternalUri() { * * Return the HTML URI of a public file. */ - function getExternalUrl() { + public function getExternalUrl() { return '/dummy/example.txt'; } } diff --git a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyRemoteStreamWrapper.php b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyRemoteStreamWrapper.php index 2741196..299adc1 100644 --- a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyRemoteStreamWrapper.php +++ b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyRemoteStreamWrapper.php @@ -17,7 +17,10 @@ * Basically just the public scheme but not returning a local file for realpath. */ class DummyRemoteStreamWrapper extends PublicStream { - function realpath() { + /** + * Get real path of file. + */ + public function realpath() { return FALSE; } } diff --git a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php index cbea40f..d02a379 100644 --- a/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php +++ b/core/modules/file/tests/file_test/lib/Drupal/file_test/DummyStreamWrapper.php @@ -15,7 +15,10 @@ * Dummy stream wrapper implementation (dummy://). */ class DummyStreamWrapper extends LocalStream { - function getDirectoryPath() { + /** + * Get Directory path of file. + */ + public function getDirectoryPath() { return conf_path() . '/files'; } @@ -24,7 +27,7 @@ function getDirectoryPath() { * * Return a dummy path for testing. */ - function getInternalUri() { + public function getInternalUri() { return '/dummy/example.txt'; } @@ -33,7 +36,7 @@ function getInternalUri() { * * Return the HTML URI of a public file. */ - function getExternalUrl() { + public function getExternalUrl() { return '/dummy/example.txt'; } } diff --git a/core/modules/syslog/lib/Drupal/syslog/Tests/SyslogTest.php b/core/modules/syslog/lib/Drupal/syslog/Tests/SyslogTest.php index 1e1a545..bd84fe5 100644 --- a/core/modules/syslog/lib/Drupal/syslog/Tests/SyslogTest.php +++ b/core/modules/syslog/lib/Drupal/syslog/Tests/SyslogTest.php @@ -21,18 +21,21 @@ class SyslogTest extends WebTestBase { */ public static $modules = array('syslog'); + /** + * Modules to enable. + */ public static function getInfo() { return array( 'name' => 'Syslog functionality', 'description' => 'Test syslog settings.', - 'group' => 'Syslog' + 'group' => 'Syslog', ); } /** * Tests the syslog settings page. */ - function testSettings() { + public function testSettings() { $admin_user = $this->drupalCreateUser(array('administer site configuration')); $this->drupalLogin($admin_user); @@ -43,7 +46,8 @@ function testSettings() { $this->drupalGet('admin/config/development/logging'); if ($this->parse()) { - $field = $this->xpath('//option[@value=:value]', array(':value' => LOG_LOCAL6)); // Should be one field. + // Should be one field. + $field = $this->xpath('//option[@value=:value]', array(':value' => LOG_LOCAL6)); $this->assertTrue($field[0]['selected'] == 'selected', 'Facility value saved.'); } }