RevisionLinkTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/Views/RevisionLinkTest.php
View source
<?php
namespace Drupal\Tests\node\Functional\Views;
class RevisionLinkTest extends NodeTestBase {
public static $testViews = [
'test_node_revision_links',
];
protected $defaultTheme = 'stark';
public function testRevisionLinks() {
$this
->drupalCreateContentType([
'name' => 'page',
'type' => 'page',
]);
$account = $this
->drupalCreateUser([
'revert all revisions',
'view all revisions',
'delete all revisions',
'edit any page content',
'delete any page content',
]);
$this
->drupalLogin($account);
$nodes = [
$this
->drupalCreateNode(),
$this
->drupalCreateNode(),
];
$first_revision = $nodes[1]
->getRevisionId();
$nodes[1]
->setNewRevision();
$nodes[1]
->save();
$second_revision = $nodes[1]
->getRevisionId();
$this
->drupalGet('test-node-revision-links');
$this
->assertSession()
->statusCodeEquals(200);
$url = $nodes[0]
->toUrl()
->toString();
$this
->assertSession()
->linkByHrefExists($url);
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $nodes[0]
->getRevisionId() . '/view');
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $nodes[0]
->getRevisionId() . '/delete');
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $nodes[0]
->getRevisionId() . '/revert');
$url = $nodes[1]
->toUrl()
->toString();
$this
->assertSession()
->linkByHrefExists($url);
$this
->assertSession()
->linkByHrefExists($url . '/revisions/' . $first_revision . '/view');
$this
->assertSession()
->linkByHrefExists($url . '/revisions/' . $first_revision . '/delete');
$this
->assertSession()
->linkByHrefExists($url . '/revisions/' . $first_revision . '/revert');
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $second_revision . '/view');
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $second_revision . '/delete');
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $second_revision . '/revert');
$accounts = [
'view' => $this
->drupalCreateUser([
'view all revisions',
]),
'revert' => $this
->drupalCreateUser([
'revert all revisions',
'edit any page content',
]),
'delete' => $this
->drupalCreateUser([
'delete all revisions',
'delete any page content',
]),
];
$url = $nodes[1]
->toUrl()
->toString();
foreach ($accounts as $allowed_operation => $account) {
$this
->drupalLogin($account);
$this
->drupalGet('test-node-revision-links');
foreach ([
'revert',
'delete',
] as $operation) {
if ($operation == $allowed_operation) {
$this
->assertSession()
->linkByHrefExists($url . '/revisions/' . $first_revision . '/' . $operation);
}
else {
$this
->assertSession()
->linkByHrefNotExists($url . '/revisions/' . $first_revision . '/' . $operation);
}
}
}
}
}