PathautoUserWebTest.php in Pathauto 8
File
tests/src/Functional/PathautoUserWebTest.php
View source
<?php
namespace Drupal\Tests\pathauto\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\views\Views;
class PathautoUserWebTest extends BrowserTestBase {
use PathautoTestHelperTrait;
protected $defaultTheme = 'stable';
public static $modules = [
'pathauto',
'views',
];
protected $adminUser;
protected function setUp() {
parent::setUp();
$permissions = [
'administer pathauto',
'administer url aliases',
'create url aliases',
'administer users',
];
$this->adminUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->adminUser);
$this
->createPattern('user', '/users/[user:name]');
}
public function testUserEditing() {
$this
->drupalGet('user/' . $this->adminUser
->id() . '/edit');
$this
->assertNoFieldById('path[0][pathauto]');
}
public function testUserOperations() {
$account = $this
->drupalCreateUser();
$this
->deleteAllAliases();
$view = Views::getView('user_admin_people');
$view
->initDisplay();
$view
->preview('page_1');
foreach ($view->result as $key => $row) {
if ($view->field['name']
->getValue($row) == $account
->getDisplayName()) {
break;
}
}
$edit = [
'action' => 'pathauto_update_alias_user',
"user_bulk_form[{$key}]" => TRUE,
];
$this
->drupalPostForm('admin/people', $edit, t('Apply to selected items'));
$this
->assertText('Update URL alias was applied to 1 item.');
$this
->assertEntityAlias($account, '/users/' . mb_strtolower($account
->getDisplayName()));
$this
->assertEntityAlias($this->adminUser, '/user/' . $this->adminUser
->id());
}
}