You are here

public function AgreementCustomUnprivilegedUserTest::testAgreementPages 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::testAgreementPages()

Asserts that agreement only functions on the front page.

File

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

Class

AgreementCustomUnprivilegedUserTest
Tests custom agreement settings.

Namespace

Drupal\Tests\agreement\Functional

Code

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);

  // Not sent to agreement page.
  $this
    ->assertNotAgreementPage($this->agreement);

  // Go to front page, open agreement.
  $this
    ->drupalGet('/node');
  $this
    ->assertAgreementPage($this->agreement);

  // Go anywhere else, no agreement.
  $this
    ->drupalGet('/user/' . $this->account
    ->id() . '/edit');
  $this
    ->assertNotAgreementPage($this->agreement);
  $privilegedUser = $this
    ->createPrivilegedUser();
  $this
    ->drupalLogin($privilegedUser);
  $this
    ->drupalPostForm('/admin/config/people/agreement/manage/' . $this->agreement
    ->id() . '/delete', [], 'Confirm');
  $this
    ->assertSession()
    ->pageTextContains('Successfully deleted agreement');
}