You are here

public function AgreementCustomUnprivilegedUserTest::testAgreementFrequency in Agreement 8.2

Same name and namespace in other branches
  1. 3.0.x tests/src/Functional/AgreementCustomUnprivilegedUserTest.php \Drupal\Tests\agreement\Functional\AgreementCustomUnprivilegedUserTest::testAgreementFrequency()

Asserts the agreement frequency option.

File

tests/src/Functional/AgreementCustomUnprivilegedUserTest.php, line 61

Class

AgreementCustomUnprivilegedUserTest
Tests custom agreement settings.

Namespace

Drupal\Tests\agreement\Functional

Code

public function testAgreementFrequency() {

  // A) Agreement required once.
  $settings = $this->agreement
    ->getSettings();
  $settings['visibility']['settings'] = 1;
  $settings['visibility']['pages'] = [
    '<front>',
  ];
  $this->agreement
    ->set('settings', $settings);
  $this->agreement
    ->save();

  // Log in, go to front page, open agreement.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('/node');
  $this
    ->assertAgreementPage($this->agreement);
  $this
    ->assertAgreed($this->agreement);

  // Log out, log back in, open agreement.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('/node');
  $this
    ->assertNotAgreementPage($this->agreement);
  $this
    ->drupalLogout();

  // B) Agreement required on every login.
  $settings['frequency'] = 0;
  $this->agreement
    ->set('settings', $settings);
  $this->agreement
    ->save();

  // Log in, go to front page, open agreement.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('/node');
  $this
    ->assertAgreementPage($this->agreement);
  $this
    ->assertAgreed($this->agreement);

  // Log out, log back in, open agreement.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('/node');
  $this
    ->assertAgreementPage($this->agreement);
  $this
    ->assertAgreed($this->agreement);

  // Change password, no 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
    ->drupalPostForm('/user/' . $this->account
    ->id() . '/edit', $edit, 'Save');
  if ($this
    ->checkForMetaRefresh()) {
    $this->metaRefreshCount = 0;
  }
  $this
    ->assertNotAgreementPage($this->agreement);
  $this
    ->assertSession()
    ->pageTextContains('The changes have been saved.');
}