You are here

public function AccessUnpublishedTest::testAccessUnpublished in Access unpublished 8

Testing integration of "access_unpublished" module.

File

tests/src/FunctionalJavascript/AccessUnpublishedTest.php, line 85

Class

AccessUnpublishedTest
Test for access unpublished integration.

Namespace

Drupal\Tests\access_unpublished\FunctionalJavascript

Code

public function testAccessUnpublished() {

  // Edit node and generate access unpubplished token.
  $this
    ->drupalGet($this->entity
    ->toUrl('edit-form'));
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->clickLink('Temporary unpublished access');
  $page
    ->find('xpath', '//*[@data-drupal-selector="edit-generate-token"]')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $copyToClipboard = $page
    ->find('xpath', '//*[@data-drupal-selector="access-token-list"]//a[contains(@class, "clipboard-button")]');
  $tokenUrl = $copyToClipboard
    ->getAttribute('data-unpublished-access-url');

  // Log-Out and check that URL with token works, but not URL without it.
  $loggedInUser = $this->loggedInUser;
  $this
    ->drupalLogout();
  $this
    ->drupalGet($tokenUrl);
  $this
    ->assertSession()
    ->pageTextContains($this->entity
    ->label());
  $this
    ->drupalGet($this->entity
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextContains('Access denied');

  // Log-In and delete token -> check page can't be accessed.
  $this
    ->drupalLogin($loggedInUser);
  $this
    ->drupalGet($this->entity
    ->toUrl('edit-form'));
  $page
    ->clickLink('Temporary unpublished access');
  $page
    ->find('css', '[data-drupal-selector="access-token-list"] li.dropbutton-toggle > button')
    ->click();
  $page
    ->find('css', '[data-drupal-selector="access-token-list"] li.delete > a')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Log-Out and check that URL with token doesn't work anymore.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($tokenUrl);
  $this
    ->assertSession()
    ->pageTextContains('Access denied');

  // Log-In and publish node.
  $this
    ->drupalLogin($loggedInUser);
  $this
    ->drupalGet($this->entity
    ->toUrl('edit-form'));
  $page
    ->checkField('Published');
  $page
    ->pressButton('Save');

  // Log-Out and check that URL to node works.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($this->entity
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextContains($this->entity
    ->label());
}