Commit 353a1609 authored by alexpott's avatar alexpott

Issue #2385211 by tadityar, subhojit777, hussainweb, cilefen, tibbsa: Clean-up...

Issue #2385211 by tadityar, subhojit777, hussainweb, cilefen, tibbsa: Clean-up user module test members - ensure property definition and use of camelCase naming convention
parent 610e90e3
......@@ -29,21 +29,21 @@ class UserRoleConditionTest extends KernelTestBase {
/**
* An anonymous user for testing purposes.
*
* @var \Drupal\user\Entity\User
* @var \Drupal\user\UserInterface
*/
protected $anonymous;
/**
* An authenticated user for testing purposes.
*
* @var \Drupal\user\Entity\User
* @var \Drupal\user\UserInterface
*/
protected $authenticated;
/**
* A custom role for testing purposes.
*
* @var \Drupal\user\Entity\Role
* @var \Drupal\user\Entity\RoleInterface
*/
protected $role;
......
......@@ -28,13 +28,6 @@ class UserActionConfigSchemaTest extends KernelTestBase {
*/
public static $modules = array('system', 'user');
/**
* A user with administrative permissions.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Tests whether the user action config schema are valid.
*/
......
......@@ -18,16 +18,16 @@
class UserAdminLanguageTest extends WebTestBase {
/**
* Administrator user for this test.
* A user with permission to access admin pages and administer languages.
*
* @var \Drupal\user\Entity\User
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Non-administrator user for this test.
* A non-administrator user for this test.
*
* @var \Drupal\user\Entity\User
* @var \Drupal\user\UserInterface
*/
protected $regularUser;
......
......@@ -17,12 +17,27 @@
* @group user
*/
class UserAutocompleteTest extends WebTestBase {
/**
* A regular user for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $unprivilegedUser;
/**
* A user with permission to access user profiles.
*
* @var \Drupal\user\UserInterface
*/
protected $privilegedUser;
protected function setUp() {
parent::setUp();
// Set up two users with different permissions to test access.
$this->unprivileged_user = $this->drupalCreateUser();
$this->privileged_user = $this->drupalCreateUser(array('access user profiles'));
$this->unprivilegedUser = $this->drupalCreateUser();
$this->privilegedUser = $this->drupalCreateUser(array('access user profiles'));
}
/**
......@@ -30,19 +45,20 @@ protected function setUp() {
*/
function testUserAutocomplete() {
// Check access from unprivileged user, should be denied.
$this->drupalLogin($this->unprivileged_user);
$username = $this->unprivileged_user->getUsername();
$this->drupalLogin($this->unprivilegedUser);
$username = $this->unprivilegedUser->getUsername();
$this->drupalGet('user/autocomplete', array('query' => array('q' => $username[0])));
$this->assertResponse(403, 'Autocompletion access denied to user without permission.');
// Check access from privileged user.
$this->drupalLogout();
$this->drupalLogin($this->privileged_user);
$this->drupalLogin($this->privilegedUser);
$this->drupalGet('user/autocomplete', array('query' => array('q' => $username[0])));
$this->assertResponse(200, 'Autocompletion access allowed.');
// Using first letter of the user's name, make sure the user's full name is in the results.
$this->assertRaw($this->unprivileged_user->getUsername(), 'User name found in autocompletion results.');
// Using first letter of the user's name, make sure the user's full name is
// in the results.
$this->assertRaw($this->unprivilegedUser->getUsername(), 'User name found in autocompletion results.');
$anonymous_name = $this->randomString() . '<script>alert();</script>';
$this->config('user.settings')->set('anonymous', $anonymous_name)->save();
......
......@@ -24,7 +24,7 @@ class UserBlocksTest extends WebTestBase {
public static $modules = array('block', 'views');
/**
* The admin user used in this test.
* A user with the 'administer blocks' permission.
*
* @var \Drupal\user\UserInterface
*/
......
......@@ -111,8 +111,8 @@ function testUserCancelUid1() {
$user1->pass_raw = $password;
// Try to cancel uid 1's account with a different user.
$this->admin_user = $this->drupalCreateUser(array('administer users'));
$this->drupalLogin($this->admin_user);
$admin_user = $this->drupalCreateUser(array('administer users'));
$this->drupalLogin($admin_user);
$edit = array(
'action' => 'user_cancel_user_action',
'user_bulk_form[0]' => TRUE,
......
......@@ -25,10 +25,19 @@ class UserEntityCallbacksTest extends WebTestBase {
public static $modules = array('user');
/**
* An authenticated user to use for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $account;
/**
* An anonymous user to use for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $anonymous;
protected function setUp() {
parent::setUp();
......
<?php
/**
* @file
* Contains \Drupal\user\Tests\UserEntityReferenceTest.
......@@ -17,12 +18,16 @@
class UserEntityReferenceTest extends EntityUnitTestBase {
/**
* @var \Drupal\user\Entity\Role
* A randomly-generated role for testing purposes.
*
* @var \Drupal\user\Entity\RoleInterface
*/
protected $role1;
/**
* @var \Drupal\user\Entity\Role
* A randomly-generated role for testing purposes.
*
* @var \Drupal\user\Entity\RoleInterface
*/
protected $role2;
......@@ -79,7 +84,9 @@ function testUserSelectionByRole() {
$user3->save();
/** @var \Drupal\entity_reference\EntityReferenceAutocomplete $autocomplete */
/**
* @var \Drupal\entity_reference\EntityReferenceAutocomplete $autocomplete
*/
$autocomplete = \Drupal::service('entity_reference.autocomplete');
$matches = $autocomplete->getMatches($field_definition, 'user', 'user', 'NULL', '', 'aabb');
......
......@@ -17,16 +17,28 @@
* @group user
*/
class UserPermissionsTest extends WebTestBase {
protected $admin_user;
/**
* User with admin privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* User's role ID.
*
* @var string
*/
protected $rid;
protected function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer account settings'));
$this->adminUser = $this->drupalCreateUser(array('administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer account settings'));
// Find the new role ID.
$all_rids = $this->admin_user->getRoles();
$all_rids = $this->adminUser->getRoles();
unset($all_rids[array_search(DRUPAL_AUTHENTICATED_RID, $all_rids)]);
$this->rid = reset($all_rids);
}
......@@ -37,9 +49,9 @@ protected function setUp() {
function testUserPermissionChanges() {
$permissions_hash_generator = $this->container->get('user.permissions_hash');
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$rid = $this->rid;
$account = $this->admin_user;
$account = $this->adminUser;
$previous_permissions_hash = $permissions_hash_generator->generate($account);
$this->assertIdentical($previous_permissions_hash, $permissions_hash_generator->generate($this->loggedInUser));
......@@ -74,7 +86,7 @@ function testUserPermissionChanges() {
* Test assigning of permissions for the administrator role.
*/
function testAdministratorRole() {
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/people/accounts');
// Verify that the administration role is none by default.
......@@ -89,7 +101,7 @@ function testAdministratorRole() {
// permission is assigned by default.
\Drupal::service('module_installer')->install(array('aggregator'));
$this->assertTrue($this->admin_user->hasPermission('administer news feeds'), 'The permission was automatically assigned to the administrator role');
$this->assertTrue($this->adminUser->hasPermission('administer news feeds'), 'The permission was automatically assigned to the administrator role');
}
/**
......@@ -99,7 +111,7 @@ function testUserRoleChangePermissions() {
$permissions_hash_generator = $this->container->get('user.permissions_hash');
$rid = $this->rid;
$account = $this->admin_user;
$account = $this->adminUser;
$previous_permissions_hash = $permissions_hash_generator->generate($account);
// Verify current permissions.
......
......@@ -27,13 +27,17 @@ class UserPictureTest extends WebTestBase {
*/
protected $profile = 'standard';
protected $user;
protected $_directory_test;
/**
* A regular user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array(
$this->webUser = $this->drupalCreateUser(array(
'access content',
'access comments',
'post comments',
......@@ -45,7 +49,7 @@ protected function setUp() {
* Tests creation, display, and deletion of user pictures.
*/
function testCreateDeletePicture() {
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
// Save a new picture.
$image = current($this->drupalGetTestFiles('image'));
......@@ -57,7 +61,7 @@ function testCreateDeletePicture() {
// Delete the picture.
$edit = array();
$this->drupalPostForm('user/' . $this->web_user->id() . '/edit', $edit, t('Remove'));
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Remove'));
$this->drupalPostForm(NULL, array(), t('Save'));
// Call file_cron() to clean up the file. Make sure the timestamp
......@@ -82,7 +86,7 @@ function testCreateDeletePicture() {
* Tests embedded users on node pages.
*/
function testPictureOnNodeComment() {
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
// Save a new picture.
$image = current($this->drupalGetTestFiles('image'));
......@@ -124,10 +128,10 @@ function testPictureOnNodeComment() {
*/
function saveUserPicture($image) {
$edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
$this->drupalPostForm('user/' . $this->web_user->id() . '/edit', $edit, t('Save'));
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
// Load actual user data from database.
$account = user_load($this->web_user->id(), TRUE);
$account = user_load($this->webUser->id(), TRUE);
return file_load($account->user_picture->target_id, TRUE);
}
}
......@@ -17,16 +17,23 @@
*/
class UserRoleAdminTest extends WebTestBase {
/**
* User with admin privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
$this->adminUser = $this->drupalCreateUser(array('administer permissions', 'administer users'));
}
/**
* Test adding, renaming and deleting roles.
*/
function testRoleAdministration() {
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
// Test presence of tab.
$this->drupalGet('admin/people/permissions');
......@@ -85,7 +92,7 @@ function testRoleAdministration() {
* Test user role weight change operation and ordering.
*/
function testRoleWeightOrdering() {
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$roles = user_roles();
$weight = count($roles);
$new_role_weights = array();
......
......@@ -15,12 +15,11 @@
* @group user
*/
class UserRolesAssignmentTest extends WebTestBase {
protected $admin_user;
protected function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
$this->drupalLogin($this->admin_user);
$admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
$this->drupalLogin($admin_user);
}
/**
......
......@@ -16,6 +16,34 @@
*/
class UserSignatureTest extends WebTestBase {
/**
* A regular user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* User with admin privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Filtered HTML format.
*
* @var \Drupal\filter\FilterFormatInterface
*/
protected $filteredHtmlFormat;
/**
* Full HTML format.
*
* @var \Drupal\filter\FilterFormatInterface
*/
protected $fullHtmlFormat;
/**
* Modules to enable.
*
......@@ -35,7 +63,7 @@ protected function setUp() {
$this->container->get('comment.manager')->addDefaultField('node', 'page');
// Prefetch and create text formats.
$this->filtered_html_format = entity_create('filter_format', array(
$this->filteredHtmlFormat = entity_create('filter_format', array(
'format' => 'filtered_html_format',
'name' => 'Filtered HTML',
'weight' => -1,
......@@ -49,18 +77,18 @@ protected function setUp() {
),
),
));
$this->filtered_html_format->save();
$this->filteredHtmlFormat->save();
$this->full_html_format = entity_create('filter_format', array(
$this->fullHtmlFormat = entity_create('filter_format', array(
'format' => 'full_html',
'name' => 'Full HTML',
));
$this->full_html_format->save();
$this->fullHtmlFormat->save();
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filtered_html_format->getPermissionName()));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filteredHtmlFormat->getPermissionName()));
// Create regular and administrative users.
$this->web_user = $this->drupalCreateUser(array('post comments'));
$this->webUser = $this->drupalCreateUser(array('post comments'));
$admin_permissions = array('post comments', 'administer comments', 'administer user form display', 'administer account settings');
foreach (filter_formats() as $format) {
......@@ -68,7 +96,7 @@ protected function setUp() {
$admin_permissions[] = $permission;
}
}
$this->admin_user = $this->drupalCreateUser($admin_permissions);
$this->adminUser = $this->drupalCreateUser($admin_permissions);
}
/**
......@@ -90,12 +118,12 @@ function testUserSignature() {
$this->assertNoText(t('Signature'));
// Log in as a regular user and create a signature.
$this->drupalLogin($this->web_user);
$this->drupalLogin($this->webUser);
$signature_text = "<h1>" . $this->randomMachineName() . "</h1>";
$edit = array(
'signature[value]' => $signature_text,
);
$this->drupalPostForm('user/' . $this->web_user->id() . '/edit', $edit, t('Save'));
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
// Verify that values were stored.
$this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');
......@@ -118,14 +146,14 @@ function testUserSignature() {
// Log in as an administrator and edit the comment to use Full HTML, so
// that the comment text itself is not filtered at all.
$this->drupalLogin($this->admin_user);
$edit['comment_body[0][format]'] = $this->full_html_format->id();
$this->drupalLogin($this->adminUser);
$edit['comment_body[0][format]'] = $this->fullHtmlFormat->id();
$this->drupalPostForm('comment/' . $comment_id . '/edit', $edit, t('Save'));
// Assert that the signature did not make it through unfiltered.
$this->drupalGet('node/' . $node->id());
$this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
$this->assertRaw(check_markup($signature_text, $this->filtered_html_format->id()), 'Filtered signature text found.');
$this->assertRaw(check_markup($signature_text, $this->filteredHtmlFormat->id()), 'Filtered signature text found.');
// Verify that the user signature's text format's cache tag is present.
$this->drupalGet('node/' . $node->id());
$this->assertTrue(in_array('config:filter.format.filtered_html_format', explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'))));
......
......@@ -18,6 +18,8 @@ class UserTranslationUITest extends ContentTranslationUITest {
/**
* The user name of the test user.
*
* @var string
*/
protected $name;
......
......@@ -25,6 +25,13 @@ class ArgumentValidateTest extends UserTestBase {
*/
public static $testViews = array('test_view_argument_validate_user', 'test_view_argument_validate_username');
/**
* A user for this test.
*
* @var \Drupal\user\UserInterface
*/
protected $account;
protected function setUp() {
parent::setUp();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment