You are here

public function AccessUnpublishedTest::testAccessUnpublished in Thunder 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
  2. 8.2 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
  3. 8.4 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
  4. 6.2.x tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
  5. 6.0.x tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
  6. 6.1.x tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()

Testing integration of "access_unpublished" module.

File

tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php, line 24

Class

AccessUnpublishedTest
Test for access unpublished integration.

Namespace

Drupal\Tests\thunder\FunctionalJavascript\Integration

Code

public function testAccessUnpublished() {

  // Create article and save it as unpublished.
  $this
    ->articleFillNew([
    'field_channel' => 1,
    'title[0][value]' => 'Article 1',
    'field_seo_title[0][value]' => 'Article 1',
  ]);
  $this
    ->addTextParagraph('field_paragraphs', 'Article Text 1');
  $this
    ->setModerationState('draft');
  $this
    ->clickSave();

  // Edit article and generate access unpublished token.
  $this
    ->drupalGet('node/10/edit');
  $this
    ->expandAllTabs();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->scrollElementInView('[data-drupal-selector="edit-generate-token"]');
  $page
    ->find('xpath', '//*[@data-drupal-selector="edit-generate-token"]')
    ->click();
  $this
    ->waitUntilVisible('[data-drupal-selector="access-token-list"] a.clipboard-button', 5000);
  $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('Article Text 1');
  $this
    ->drupalGet('/article-1');
  $noAccess = $this
    ->xpath('//h1[contains(@class, "page-title")]//span[text() = "403"]');
  $this
    ->assertEquals(1, count($noAccess));

  // Log-In and delete token -> check page can't be accessed.
  $this
    ->drupalLogin($loggedInUser);
  $this
    ->drupalGet('node/10/edit');
  $this
    ->expandAllTabs();
  $this
    ->scrollElementInView('[data-drupal-selector="edit-generate-token"]');
  $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();
  $this
    ->clickSave();

  // Log-Out and check that URL with token doesn't work anymore.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($tokenUrl);
  $noAccess = $this
    ->xpath('//h1[contains(@class, "page-title")]//span[text() = "403"]');
  $this
    ->assertEquals(1, count($noAccess));

  // Log-In and publish article.
  $this
    ->drupalLogin($loggedInUser);
  $this
    ->drupalGet('node/10/edit');
  $this
    ->setModerationState('published');
  $this
    ->clickSave();

  // Log-Out and check that URL to article works.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('article-1');
  $this
    ->assertSession()
    ->pageTextContains('Article Text 1');
}