You are here

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

Tests the agreement destination functionality.

1. Agreement destination = blank.

  • user goes to regular get URL -> redirect to front.
  • user goes to node/1 -> redirect to node/1.
  • user needs to change password -> redirect to user/%/edit

2. Agreement destination = node/1.

  • user goes to regular get URL -> redirect to node/1.
  • user goes to user profile -> redirect to node/1.
  • user needs to change password -> redirect to user/%/edit.

File

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

Class

AgreementCustomUnprivilegedUserTest
Tests custom agreement settings.

Namespace

Drupal\Tests\agreement\Functional

Code

public function testAgreementDestination() {

  // A) Agreement destination = blank.
  $settings = $this->agreement
    ->getSettings();
  $settings['frequency'] = 0;
  $settings['visibility']['pages'] = [
    '/user',
    '/user/*',
  ];
  $this->agreement
    ->set('settings', $settings);
  $this->agreement
    ->save();

  // Log in, open agreement directly (no destination), go to front page.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet($this->agreement
    ->get('path'));
  $this
    ->assertAgreementPage($this->agreement);
  $this
    ->assertAgreed($this->agreement);
  $this
    ->assertFrontPage();
  $this
    ->drupalLogout();

  // Log in, go somewhere other than front page, open agreement, go to user's
  // original destination.
  $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();

  // B) Agreement destination = node/1.
  $settings = $this->agreement
    ->getSettings();
  $settings['destination'] = '/node/1';
  $this->agreement
    ->set('settings', $settings);
  $this->agreement
    ->save();

  // Log in, open agreement via the front page, go to node/1.
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('/node');
  $this
    ->assertAgreementPage($this->agreement);
  $this
    ->assertAgreed($this->agreement);
  $this
    ->assertSession()
    ->addressMatches('/node\\/' . $this->node
    ->id() . '$/');
  $this
    ->drupalLogout();

  // Log in, go somewhere other than front page, open agreement, go to node/1.
  $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() . '$/');

  // @todo: Log in following password reset link, go somewhere other than
  // front page, open agreement, go to user profile.
}