ViewProfilesPermsTest.php in View profiles permissions 2.0.x
File
tests/src/Functional/ViewProfilesPermsTest.php
View source
<?php
namespace Drupal\Tests\view_profiles_perms\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
class ViewProfilesPermsTest extends BrowserTestBase {
use UserCreationTrait;
public static $modules = [
'view_profiles_perms_test',
];
protected $defaultTheme = 'stark';
protected $developer;
protected $manager;
protected $admin;
public function setUp() {
parent::setUp();
$developer = $this
->drupalCreateUser();
$developer
->addRole('developer');
$developer
->save();
$this->developer = $developer;
$manager = $this
->drupalCreateUser();
$manager
->addRole('manager');
$manager
->save();
$this->manager = $manager;
$this->admin = $this
->drupalCreateUser([], NULL, TRUE);
}
public function testViewProfilePerms() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->admin);
$this
->drupalGet('admin/people/permissions');
$assert
->pageTextContains('View profiles permissions');
$assert
->pageTextContains('Access Manager users profiles');
$assert
->pageTextContains('Access Developer users profiles');
$assert
->checkboxChecked('developer[access manager users profiles]');
$assert
->checkboxNotChecked('anonymous[access user profiles]');
$assert
->checkboxNotChecked('authenticated[access user profiles]');
$assert
->pageTextNotContains('Access Authenticated users profiles');
$assert
->pageTextNotContains('Access Anonymous users profiles');
$this
->drupalLogin($this->developer);
$this
->drupalGet('user/' . $this->manager
->id());
$assert
->statusCodeEquals(200);
$this
->drupalLogin($this->manager);
$this
->drupalGet('user/' . $this->developer
->id());
$assert
->statusCodeEquals(403);
$user = $this
->drupalCreateUser();
$user
->addRole('developer');
$user
->addRole('manager');
$user
->save();
$this
->drupalLogin($this->developer);
$this
->drupalGet('user/' . $user
->id());
$assert
->statusCodeEquals(200);
$this
->drupalLogin($this->admin);
$this
->drupalPostForm('admin/people/permissions', [
'authenticated[access user profiles]' => TRUE,
], 'Save permissions');
$assert
->checkboxChecked('authenticated[access user profiles]');
$this
->drupalLogin($this->manager);
$this
->drupalGet('user/' . $this->developer
->id());
$assert
->statusCodeEquals(200);
$this
->drupalGet('user/' . $this->manager
->id());
$assert
->statusCodeEquals(200);
$this
->drupalLogout();
$this->manager
->block();
$this->manager
->save();
$this
->drupalLogin($this->developer);
$this
->drupalGet('user/' . $this->manager
->id());
$assert
->statusCodeEquals(403);
}
}