AgreementCustomUnprivilegedUserTest.php in Agreement 3.0.x
File
tests/src/Functional/AgreementCustomUnprivilegedUserTest.php
View source
<?php
namespace Drupal\Tests\agreement\Functional;
class AgreementCustomUnprivilegedUserTest extends AgreementTestBase {
protected $account;
protected function setUp() : void {
parent::setUp();
$this->account = $this
->createUnprivilegedUser();
}
public function testAgreementPages() {
$settings = $this->agreement
->getSettings();
$settings['visibility']['settings'] = 1;
$settings['visibility']['pages'] = [
'<front>',
];
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$this
->drupalLogin($this->account);
$this
->assertNotAgreementPage($this->agreement);
$this
->drupalGet('/node');
$this
->assertAgreementPage($this->agreement);
$this
->drupalGet('/user/' . $this->account
->id() . '/edit');
$this
->assertNotAgreementPage($this->agreement);
$privilegedUser = $this
->createPrivilegedUser();
$this
->drupalLogin($privilegedUser);
$this
->drupalGet('/admin/config/people/agreement/manage/' . $this->agreement
->id() . '/delete');
$this
->submitForm([], 'Confirm');
$this
->assertSession()
->pageTextContains('Successfully deleted agreement');
}
public function testAgreementFrequency() {
$settings = $this->agreement
->getSettings();
$settings['visibility']['settings'] = 1;
$settings['visibility']['pages'] = [
'<front>',
];
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$this
->drupalLogin($this->account);
$this
->drupalGet('/node');
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$this
->drupalLogin($this->account);
$this
->drupalGet('/node');
$this
->assertNotAgreementPage($this->agreement);
$this
->drupalLogout();
$settings['frequency'] = 0;
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$this
->drupalLogin($this->account);
$this
->drupalGet('/node');
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$this
->drupalLogin($this->account);
$this
->drupalGet('/node');
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$settings['visibility']['pages'] = [];
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$edit = [
'current_pass' => $this->account->passRaw,
'pass[pass1]' => $pass = $this
->randomString(),
'pass[pass2]' => $pass,
];
$this
->drupalGet('/user/' . $this->account
->id() . '/edit');
$this
->submitForm($edit, 'Save');
if ($this
->checkForMetaRefresh()) {
$this->metaRefreshCount = 0;
}
$this
->assertNotAgreementPage($this->agreement);
$this
->assertSession()
->pageTextContains('The changes have been saved.');
}
public function testAgreementDestination() {
$settings = $this->agreement
->getSettings();
$settings['frequency'] = 0;
$settings['visibility']['pages'] = [
'/user',
'/user/*',
];
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$this
->drupalLogin($this->account);
$this
->drupalGet($this->agreement
->get('path'));
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$this
->assertFrontPage();
$this
->drupalLogout();
$this
->drupalLogin($this->account);
$this
->drupalGet('/node/' . $this->node
->id());
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$this
->assertSession()
->addressMatches('/node\\/' . $this->node
->id() . '$/');
$this
->drupalLogout();
$settings = $this->agreement
->getSettings();
$settings['destination'] = '/node/1';
$this->agreement
->set('settings', $settings);
$this->agreement
->save();
$this
->drupalLogin($this->account);
$this
->drupalGet('/node');
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$this
->assertSession()
->addressMatches('/node\\/' . $this->node
->id() . '$/');
$this
->drupalLogout();
$this
->drupalLogin($this->account);
$this
->drupalGet('/node/' . $this->otherNode
->id());
$this
->assertAgreementPage($this->agreement);
$this
->assertAgreed($this->agreement);
$this
->assertSession()
->addressMatches('/node\\/' . $this->node
->id() . '$/');
}
}