AgreementMultipleRoleTest.php in Agreement 3.0.x
File
tests/src/Functional/AgreementMultipleRoleTest.php
View source
<?php
namespace Drupal\Tests\agreement\Functional;
class AgreementMultipleRoleTest extends AgreementTestBase {
protected $requiredRole;
protected $requiredSecondRole;
protected function setUp() : void {
parent::setUp();
$this->requiredRole = $this
->createRole([
'access content',
]);
$this->requiredSecondRole = $this
->createRole([
'access content',
'create page content',
]);
$settings = $this->agreement
->getSettings();
$settings['roles'] = [
$this->requiredRole,
$this->requiredSecondRole,
];
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$this
->assertEquals($settings['roles'], $this->agreement
->getSettings()['roles']);
}
public function testAgreementForFirstRole() {
$requiredUser = $this
->createUnprivilegedUser();
$requiredUser
->addRole($this->requiredRole);
$requiredUser
->save();
$this
->drupalLogin($requiredUser);
$this
->assertAgreementPage($this->agreement);
$this
->drupalGet('/node');
$this
->assertNotAgreementPage($this->agreement);
$this
->drupalGet('/user/' . $requiredUser
->id());
$this
->assertAgreementPage($this->agreement);
$this
->assertNotAgreed($this->agreement);
$this
->assertAgreementPage($this->agreement);
}
public function testAgreementForSecondRole() {
$requiredUser = $this
->createUnprivilegedUser();
$requiredUser
->addRole($this->requiredSecondRole);
$requiredUser
->save();
$this
->drupalLogin($requiredUser);
$this
->assertAgreementPage($this->agreement);
$this
->drupalGet('/node');
$this
->assertNotAgreementPage($this->agreement);
$this
->drupalGet('/user/' . $requiredUser
->id());
$this
->assertAgreementPage($this->agreement);
$this
->assertNotAgreed($this->agreement);
$this
->assertAgreementPage($this->agreement);
}
public function testNoAgreementWithoutRole() {
$unprivilegedUser = $this
->createUnprivilegedUser();
$this
->drupalLogin($unprivilegedUser);
$this
->assertNotAgreementPage($this->agreement);
$this
->drupalGet('/node');
$this
->assertNotAgreementPage($this->agreement);
$this
->drupalGet('/user/' . $unprivilegedUser
->id());
$this
->assertNotAgreementPage($this->agreement);
}
}