summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-03-22 15:40:34 (GMT)
committerAlex Pott2015-03-22 15:40:34 (GMT)
commite53131ddd16eb1e0d08c0fa98cbbfd02c31ea280 (patch)
tree27bf118f24736133f1b7bb9fba60408feef86b78
parent505e39393b9a28d411d1a5d805db1a43c2c43e8b (diff)
Issue #2394419 by hussainweb, cilefen, sachinwable: Clean-up file module test members - ensure property definition and use of camelCase naming convention
-rw-r--r--core/modules/file/src/Tests/FileFieldPathTest.php2
-rw-r--r--core/modules/file/src/Tests/FileFieldTestBase.php11
-rw-r--r--core/modules/file/src/Tests/FileFieldValidateTest.php2
-rw-r--r--core/modules/file/src/Tests/FileFieldWidgetTest.php6
-rw-r--r--core/modules/file/src/Tests/FileListingTest.php15
-rw-r--r--core/modules/file/src/Tests/FilePrivateTest.php2
-rw-r--r--core/modules/file/src/Tests/FileTokenReplaceTest.php2
-rw-r--r--core/modules/file/src/Tests/SaveUploadTest.php19
-rw-r--r--core/modules/file/src/Tests/ValidatorTest.php22
9 files changed, 52 insertions, 29 deletions
diff --git a/core/modules/file/src/Tests/FileFieldPathTest.php b/core/modules/file/src/Tests/FileFieldPathTest.php
index bf166ed..6de342a 100644
--- a/core/modules/file/src/Tests/FileFieldPathTest.php
+++ b/core/modules/file/src/Tests/FileFieldPathTest.php
@@ -57,7 +57,7 @@ class FileFieldPathTest extends FileFieldTestBase {
$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 0cf36c3..25ef7f2 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 21d93af..51d7402 100644
--- a/core/modules/file/src/Tests/FileFieldValidateTest.php
+++ b/core/modules/file/src/Tests/FileFieldValidateTest.php
@@ -17,8 +17,6 @@ use Drupal\field\Entity\FieldConfig;
* @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 b26bfaf..8ebb696 100644
--- a/core/modules/file/src/Tests/FileFieldWidgetTest.php
+++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php
@@ -222,7 +222,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
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 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$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 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$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 38293ec..b752c3f 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 @@ class FileListingTest extends FileFieldTestBase {
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 4ff4ea7..9c7762b 100644
--- a/core/modules/file/src/Tests/FilePrivateTest.php
+++ b/core/modules/file/src/Tests/FilePrivateTest.php
@@ -62,7 +62,7 @@ class FilePrivateTest extends FileFieldTestBase {
$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 84d599f..bc53e68 100644
--- a/core/modules/file/src/Tests/FileTokenReplaceTest.php
+++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php
@@ -54,7 +54,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
$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 032a3d4..5b0dbc1 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 @@ class SaveUploadTest extends FileManagedTestBase {
$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 @@ class SaveUploadTest extends FileManagedTestBase {
// 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 @@ class SaveUploadTest extends FileManagedTestBase {
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 @@ class SaveUploadTest extends FileManagedTestBase {
$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 304a84c..a17fa8f 100644
--- a/core/modules/file/src/Tests/ValidatorTest.php
+++ b/core/modules/file/src/Tests/ValidatorTest.php
@@ -15,14 +15,18 @@ namespace Drupal\file\Tests;
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 @@ class ValidatorTest extends FileManagedUnitTestBase {
$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 @@ class ValidatorTest extends FileManagedUnitTestBase {
$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 @@ class ValidatorTest extends FileManagedUnitTestBase {
*/
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.