MassPasswordTestBase.php in Mass Password Change 8
File
tests/src/Functional/MassPasswordTestBase.php
View source
<?php
namespace Drupal\Tests\mass_password_change\Functional;
use Drupal\Tests\BrowserTestBase;
class MassPasswordTestBase extends BrowserTestBase {
public static $modules = [
'mass_password_change',
];
protected $adminUser;
protected $accounts;
public function setUp() {
parent::setUp();
$roles = [];
for ($i = 0; $i < 3; $i++) {
$role = $this
->drupalCreateRole([]);
$roles[$role] = $role;
}
for ($i = 0; $i < 8; $i++) {
if ($i % 5 == 0) {
$account = $this
->drupalCreateUser([], NULL, TRUE);
}
else {
$account = $this
->drupalCreateUser();
}
$account->roles[] = array_rand($roles);
$account
->save();
}
$this->adminUser = $this
->drupalCreateUser([
'administer users',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/people');
$this->accounts = $this
->getUserObjectsFromAccountsPage();
}
public function getUserObjectsFromAccountsPage() {
$accounts = [];
$domElements = $this
->getSession()
->getPage()
->findAll('css', '.views-field-name a.username');
foreach ($domElements as $domElement) {
$account = user_load_by_name($domElement
->getText());
$accounts[$account
->id()] = $account;
}
return $accounts;
}
public function getUserWeightFromAccountsArray(array $accounts, $uid) {
$weight = 0;
foreach ($accounts as $account) {
if ($account
->id() == $uid) {
return $weight;
}
$weight++;
}
return FALSE;
}
}