View source
<?php
namespace Drupal\Tests\node\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
class ContextualLinksTest extends WebDriverTestBase {
use ContextualLinkClickTrait;
protected $nodes;
protected static $modules = [
'node',
'contextual',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
$node = $this
->drupalCreateNode();
$nodes = [];
$nodes[] = clone $node;
$revision_count = 2;
for ($i = 0; $i < $revision_count; $i++) {
$node->title = $this
->randomMachineName();
$node->body = [
'value' => $this
->randomMachineName(32),
'format' => filter_default_format(),
];
$node
->setNewRevision();
$node
->save();
$node = Node::load($node
->id());
$nodes[] = clone $node;
}
$this->nodes = $nodes;
$this
->drupalLogin($this
->createUser([
'view page revisions',
'revert page revisions',
'delete page revisions',
'edit any page content',
'delete any page content',
'access contextual links',
'administer content types',
]));
}
public function testRevisionContextualLinks() {
$this
->drupalGet('node/' . $this->nodes[0]
->id());
$page = $this
->getSession()
->getPage();
$page
->waitFor(10, function () use ($page) {
return $page
->find('css', "main .contextual");
});
$this
->toggleContextualTriggerVisibility('main');
$page
->find('css', 'main .contextual button')
->press();
$links = $page
->findAll('css', "main .contextual-links li a");
$this
->assertEquals('Edit', $links[0]
->getText());
$this
->assertEquals('Delete', $links[1]
->getText());
$this
->drupalGet("node/" . $this->nodes[0]
->id() . "/revisions/" . $this->nodes[1]
->getRevisionId() . "/view");
$this
->assertSession()
->pageTextContains($this->nodes[1]
->getTitle());
$page
->waitFor(10, function () use ($page) {
return $page
->find('css', "main .contextual");
});
$this
->toggleContextualTriggerVisibility('main');
$contextual_button = $page
->find('css', 'main .contextual button');
$this
->assertEmpty(0, $contextual_button ?: '');
}
}