class UserFieldsAccessChangeTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest
- 10 core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest
- 8.9.x core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest
Checks changing entity and field access.
@group user
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\user\Functional\Views\UserTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\user\Functional\Views\UserFieldsAccessChangeTest extends \Drupal\Tests\user\Functional\Views\UserTestBase
- class \Drupal\Tests\user\Functional\Views\UserTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of UserFieldsAccessChangeTest
File
-
core/
modules/ user/ tests/ src/ Functional/ Views/ UserFieldsAccessChangeTest.php, line 10
Namespace
Drupal\Tests\user\Functional\ViewsView source
class UserFieldsAccessChangeTest extends UserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'user_access_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_user_fields_access',
];
/**
* Tests if another module can change field access.
*/
public function testUserFieldAccess() {
$this->drupalGet('test_user_fields_access');
// User has access to name and created date by default.
$this->assertSession()
->pageTextContains('Name');
$this->assertSession()
->pageTextContains('Created');
// User does not by default have access to init, mail and status.
$this->assertSession()
->pageTextNotContains('Init');
$this->assertSession()
->pageTextNotContains('Email');
$this->assertSession()
->pageTextNotContains('Status');
// Assign sub-admin role to grant extra access.
$user = $this->drupalCreateUser([
'sub-admin',
]);
$this->drupalLogin($user);
$this->drupalGet('test_user_fields_access');
// Access for init, mail and status is added in hook_entity_field_access().
$this->assertSession()
->pageTextContains('Init');
$this->assertSession()
->pageTextContains('Email');
$this->assertSession()
->pageTextContains('Status');
}
/**
* Test user name link.
*
* Tests that the user name formatter shows a link to the user when there is
* access but not otherwise.
*/
public function testUserNameLink() {
$test_user = $this->drupalCreateUser();
$xpath = "//td/a[.='" . $test_user->getAccountName() . "']/@href[.='" . $test_user->toUrl()
->toString() . "']";
$attributes = [
'title' => 'View user profile.',
];
$link = $test_user->toLink(NULL, 'canonical', [
'attributes' => $attributes,
])
->toString();
// No access, so no link.
$this->drupalGet('test_user_fields_access');
$this->assertSession()
->pageTextContains($test_user->getAccountName());
$this->assertSession()
->elementNotExists('xpath', $xpath);
// Assign sub-admin role to grant extra access.
$user = $this->drupalCreateUser([
'sub-admin',
]);
$this->drupalLogin($user);
$this->drupalGet('test_user_fields_access');
$this->assertSession()
->elementsCount('xpath', $xpath, 1);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.