public function AccessUnpublishedTest::testAccessUnpublished in Thunder 6.1.x
Same name and namespace in other branches
- 8.5 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
- 8.2 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
- 8.3 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
- 8.4 tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
- 6.2.x tests/src/FunctionalJavascript/Integration/AccessUnpublishedTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\AccessUnpublishedTest::testAccessUnpublished()
- 6.0.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\IntegrationCode
public function testAccessUnpublished() {
$term = $this
->loadTermByUuid('bfc251bc-de35-467d-af44-1f7a7012b845');
// Create article and save it as unpublished.
$this
->articleFillNew([
'field_channel' => $term
->id(),
'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.
$node = $this
->drupalGetNodeByTitle('Article 1');
$this
->drupalGet($node
->toUrl('edit-form'));
$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($node
->toUrl());
$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
->toUrl('edit-form'));
$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
->toUrl('edit-form'));
$this
->setModerationState('published');
$this
->clickSave();
// Log-Out and check that URL to article works.
$this
->drupalLogout();
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->pageTextContains('Article Text 1');
}