diff --git a/core/modules/file/src/Tests/FileFieldPathTest.php b/core/modules/file/src/Tests/FileFieldPathTest.php index bf166ed702d0e462cf2fb06b7e36b6e95147a3b1..6de342a7cd8720ef463ec1e4ac52adb6564c7e4a 100644 --- a/core/modules/file/src/Tests/FileFieldPathTest.php +++ b/core/modules/file/src/Tests/FileFieldPathTest.php @@ -57,7 +57,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()))); } diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 0cf36c3f88562361419143c2e78fc38e9703f5a8..25ef7f281e21a2d2ef9f994fd93124651083258b 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -24,12 +24,17 @@ abstract class FileFieldTestBase extends WebTestBase { */ public static $modules = array('node', 'file', 'file_module_test', 'field_ui'); - protected $admin_user; + /** + * An user with administration permissions. + * + * @var \Drupal\user\UserInterface + */ + protected $adminUser; protected 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')); } diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index 21d93af1631dd3738b9ebc949006ec2c2d3bda1f..51d740231d6cae17a7fc4dc0cf19d930c9a7c740 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -17,8 +17,6 @@ * @group file */ class FileFieldValidateTest extends FileFieldTestBase { - protected $field; - protected $node_type; /** * Tests the required property on file fields. diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index b26bfaf5885822909e74b6118875f1c9e48940ae..8ebb6962c9b931795d16fc27dee86948d397dc9c 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -222,7 +222,7 @@ function testMultiValuedWidget() { function testPrivateFileSetting() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Grant the admin user required permissions. - user_role_grant_permissions($this->admin_user->roles[0]->target_id, array('administer node fields')); + user_role_grant_permissions($this->adminUser->roles[0]->target_id, array('administer node fields')); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -262,7 +262,7 @@ function testPrivateFileComment() { $user = $this->drupalCreateUser(array('access comments')); // Grant the admin user required comment permissions. - $roles = $this->admin_user->getRoles(); + $roles = $this->adminUser->getRoles(); user_role_grant_permissions($roles[1], array('administer comment fields', 'administer comments')); // Revoke access comments permission from anon user, grant post to @@ -318,7 +318,7 @@ function testPrivateFileComment() { $this->assertResponse(403, 'Confirmed that access is denied for the file without the needed permission.'); // Unpublishes node. - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish')); // Ensures normal user can no longer download the file. diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index 38293ec242d9977505f9ccfbe4b4fd6b7b4016a3..b752c3ffd012bfc134adca3ab9122f2d32573729 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -23,11 +23,18 @@ class FileListingTest extends FileFieldTestBase { */ public static $modules = array('views', 'file', 'image'); + /** + * An authenticated user. + * + * @var \Drupal\user\UserInterface + */ + protected $baseUser; + protected function setUp() { parent::setUp(); - $this->admin_user = $this->drupalCreateUser(array('access files overview', 'bypass node access')); - $this->base_user = $this->drupalCreateUser(); + $this->adminUser = $this->drupalCreateUser(array('access files overview', 'bypass node access')); + $this->baseUser = $this->drupalCreateUser(); $this->createFileField('file', 'node', 'article', array(), array('file_extensions' => 'txt png')); } @@ -58,12 +65,12 @@ protected function sumUsages($usage) { function testFileListingPages() { $file_usage = $this->container->get('file.usage'); // Users without sufficient permissions should not see file listing. - $this->drupalLogin($this->base_user); + $this->drupalLogin($this->baseUser); $this->drupalGet('admin/content/files'); $this->assertResponse(403); // Login with user with right permissions and test listing. - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); for ($i = 0; $i < 5; $i++) { $nodes[] = $this->drupalCreateNode(array('type' => 'article')); diff --git a/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php index 4ff4ea70436193d1f8d2ed900d44e5c79b208216..9c7762be92dce6637b6feac46c848724985e29eb 100644 --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -62,7 +62,7 @@ function testPrivateFile() { $no_access_field_name = 'field_no_view_access'; $this->createFileField($no_access_field_name, 'node', $type_name, array('uri_scheme' => 'private')); // Test with the field that should deny access through field access. - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); \Drupal::entityManager()->getStorage('node')->resetCache(array($nid)); $node = $node_storage->load($nid); diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 84d599fede49570418fb05685983a9e60a31b6a8..bc53e68caa2160fdf6c7b6e18f9633ed2f7aaa4c 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -54,7 +54,7 @@ function testFileTokenReplacement() { $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId()); $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId()); $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->getId()); - $tests['[file:owner]'] = String::checkPlain(user_format_name($this->admin_user)); + $tests['[file:owner]'] = String::checkPlain(user_format_name($this->adminUser)); $tests['[file:owner:uid]'] = $file->getOwnerId(); // Test to make sure that we generated something for each token. diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php index 032a3d4d8538f75d57043c79c64f005a01a065e6..5b0dbc1713fa826d1d2f576d1917dd8377eb6eb7 100644 --- a/core/modules/file/src/Tests/SaveUploadTest.php +++ b/core/modules/file/src/Tests/SaveUploadTest.php @@ -22,6 +22,8 @@ class SaveUploadTest extends FileManagedTestBase { /** * An image file path for uploading. + * + * @var \Drupal\file\FileInterface */ protected $image; @@ -35,6 +37,13 @@ class SaveUploadTest extends FileManagedTestBase { */ protected $maxFidBefore; + /** + * Extension of the image filename. + * + * @var string + */ + protected $imageExtension; + protected function setUp() { parent::setUp(); $account = $this->drupalCreateUser(array('access site reports')); @@ -43,7 +52,7 @@ protected function setUp() { $image_files = $this->drupalGetTestFiles('image'); $this->image = entity_create('file', (array) current($image_files)); - list(, $this->image_extension) = explode('.', $this->image->getFilename()); + list(, $this->imageExtension) = explode('.', $this->image->getFilename()); $this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists."); $this->phpfile = current($this->drupalGetTestFiles('php')); @@ -142,7 +151,7 @@ function testHandleExtension() { // Reset the hook counters. file_test_reset(); - $extensions = 'foo ' . $this->image_extension; + $extensions = 'foo ' . $this->imageExtension; // Now tell file_save_upload() to allow the extension of our test image. $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, @@ -225,12 +234,12 @@ function testHandleDangerousFile() { function testHandleFileMunge() { // Ensure insecure uploads are disabled for this test. $this->config('system.file')->set('allow_insecure_uploads', 0)->save(); - $this->image = file_move($this->image, $this->image->getFileUri() . '.foo.' . $this->image_extension); + $this->image = file_move($this->image, $this->image->getFileUri() . '.foo.' . $this->imageExtension); // Reset the hook counters to get rid of the 'move' we just called. file_test_reset(); - $extensions = $this->image_extension; + $extensions = $this->imageExtension; $edit = array( 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), 'extensions' => $extensions, @@ -238,7 +247,7 @@ function testHandleFileMunge() { $munged_filename = $this->image->getFilename(); $munged_filename = substr($munged_filename, 0, strrpos($munged_filename, '.')); - $munged_filename .= '_.' . $this->image_extension; + $munged_filename .= '_.' . $this->imageExtension; $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); diff --git a/core/modules/file/src/Tests/ValidatorTest.php b/core/modules/file/src/Tests/ValidatorTest.php index 304a84c44ffee2c01de31dad9a6510138e33f5dd..a17fa8fd5777debc108c07cf3511863f9941e9d7 100644 --- a/core/modules/file/src/Tests/ValidatorTest.php +++ b/core/modules/file/src/Tests/ValidatorTest.php @@ -15,14 +15,18 @@ class ValidatorTest extends FileManagedUnitTestBase { /** - * @var \Drupal\file\Entity\File + * An image file. + * + * @var \Drupal\file\FileInterface */ protected $image; /** + * A file which is not an image. + * * @var \Drupal\file\Entity\File */ - protected $non_image; + protected $nonImage; protected function setUp() { parent::setUp(); @@ -31,9 +35,9 @@ protected function setUp() { $this->image->setFileUri('core/misc/druplicon.png'); $this->image->setFilename(drupal_basename($this->image->getFileUri())); - $this->non_image = entity_create('file'); - $this->non_image->setFileUri('core/assets/vendor/jquery/jquery.min.js'); - $this->non_image->setFilename(drupal_basename($this->non_image->getFileUri())); + $this->nonImage = entity_create('file'); + $this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.min.js'); + $this->nonImage->setFilename(drupal_basename($this->nonImage->getFileUri())); } /** @@ -57,8 +61,8 @@ function testFileValidateIsImage() { $errors = file_validate_is_image($this->image); $this->assertEqual(count($errors), 0, 'No error reported for our image file.', 'File'); - $this->assertTrue(file_exists($this->non_image->getFileUri()), 'The non-image being tested exists.', 'File'); - $errors = file_validate_is_image($this->non_image); + $this->assertTrue(file_exists($this->nonImage->getFileUri()), 'The non-image being tested exists.', 'File'); + $errors = file_validate_is_image($this->nonImage); $this->assertEqual(count($errors), 1, 'An error reported for our non-image file.', 'File'); } @@ -68,9 +72,9 @@ function testFileValidateIsImage() { */ function testFileValidateImageResolution() { // Non-images. - $errors = file_validate_image_resolution($this->non_image); + $errors = file_validate_image_resolution($this->nonImage); $this->assertEqual(count($errors), 0, 'Should not get any errors for a non-image file.', 'File'); - $errors = file_validate_image_resolution($this->non_image, '50x50', '100x100'); + $errors = file_validate_image_resolution($this->nonImage, '50x50', '100x100'); $this->assertEqual(count($errors), 0, 'Do not check the resolution on non files.', 'File'); // Minimum size.