View source
<?php
namespace Drupal\Tests\domain_content\Functional;
use Drupal\domain_access\DomainAccessManagerInterface;
class DomainContentPermissionsTest extends DomainContentTestBase {
public function testDomainContentPermissions() {
$this->admin_user = $this
->drupalCreateUser([
'administer domains',
'access administration pages',
'access domain content',
'access domain content editors',
'publish to any domain',
'assign editors to any domain',
]);
$this
->drupalLogin($this->admin_user);
$this
->createDomainContent();
$this
->createDomainUsers();
$urls = [
'admin/content/domain-content',
'admin/content/domain-editors',
];
foreach ($urls as $url) {
$this
->drupalGet($url);
$this
->assertResponse(200);
$this
->findLink('All affiliates');
foreach ($this->domains as $id => $domain) {
$this
->findLink($domain
->label());
}
$this
->drupalGet($url . '/all_affiliates');
$this
->assertResponse(200);
foreach ($this->domains as $id => $domain) {
$this
->drupalGet($url . '/' . $id);
$this
->assertResponse(200);
}
}
$this->limited_user = $this
->drupalCreateUser([
'administer domains',
'access administration pages',
'access domain content',
'access domain content editors',
'publish to any assigned domain',
'assign domain editors',
]);
$this
->addDomainsToEntity('user', $this->limited_user
->id(), array_keys($this->domains), DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD);
$this
->drupalLogin($this->limited_user);
foreach ($urls as $url) {
$this
->drupalGet($url);
$this
->assertResponse(200);
$this
->assertNoRaw('All affiliates');
foreach ($this->domains as $id => $domain) {
$this
->findLink($domain
->label());
}
$this
->drupalGet($url . '/all_affiliates');
$this
->assertResponse(403);
foreach ($this->domains as $id => $domain) {
$this
->drupalGet($url . '/' . $id);
$this
->assertResponse(200);
}
}
$this->editor_user = $this
->drupalCreateUser([
'access administration pages',
'access domain content',
'publish to any assigned domain',
]);
$this
->addDomainsToEntity('user', $this->editor_user
->id(), array_keys($this->domains), DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD);
$this
->drupalLogin($this->editor_user);
foreach ($urls as $url) {
$expected = 200;
if ($url == 'admin/content/domain-editors') {
$expected = 403;
}
$this
->drupalGet($url);
$this
->assertResponse($expected);
$this
->assertNoRaw('All affiliates');
foreach ($this->domains as $id => $domain) {
if ($expected == 200) {
$this
->findLink($domain
->label());
}
else {
$this
->findNoLink($domain
->label());
}
}
$this
->drupalGet($url . '/all_affiliates');
$this
->assertResponse(403);
foreach ($this->domains as $id => $domain) {
$this
->drupalGet($url . '/' . $id);
$this
->assertResponse($expected);
}
}
$this->assign_user = $this
->drupalCreateUser([
'access administration pages',
'access domain content editors',
'assign domain editors',
]);
$ids = array_keys($this->domains);
$assigned_id = end($ids);
$this
->addDomainsToEntity('user', $this->assign_user
->id(), [
$assigned_id,
], DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD);
$this
->drupalLogin($this->assign_user);
foreach ($urls as $url) {
$expected = 200;
if ($url == 'admin/content/domain-content') {
$expected = 403;
}
$this
->drupalGet($url);
$this
->assertResponse($expected);
$this
->assertNoRaw('All affiliates');
foreach ($this->domains as $id => $domain) {
if ($expected == 200 && $id == $assigned_id) {
$this
->findLink($domain
->label());
}
else {
$this
->findNoLink($domain
->label());
}
}
$this
->drupalGet($url . '/all_affiliates');
$this
->assertResponse(403);
foreach ($this->domains as $id => $domain) {
$this
->drupalGet($url . '/' . $id);
if ($expected == 200 && $id == $assigned_id) {
$this
->assertResponse(200);
}
else {
$this
->assertResponse(403);
}
}
}
}
}