3 namespace Drupal\Tests\node\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\node\Entity\Node;
7 use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
10 * Create a node with revisions and test contextual links.
14 class ContextualLinksTest extends WebDriverTestBase {
16 use ContextualLinkClickTrait;
19 * An array of node revisions.
21 * @var \Drupal\node\NodeInterface[]
29 protected static $modules = ['node', 'contextual'];
34 protected function setUp() {
37 $this->drupalCreateContentType([
39 'name' => 'Basic page',
40 'display_submitted' => FALSE,
43 // Create initial node.
44 $node = $this->drupalCreateNode();
49 $nodes[] = clone $node;
51 // Create two revisions.
53 for ($i = 0; $i < $revision_count; $i++) {
55 // Create revision with a random title and body and update variables.
56 $node->title = $this->randomMachineName();
58 'value' => $this->randomMachineName(32),
59 'format' => filter_default_format(),
61 $node->setNewRevision();
65 // Make sure we get revision information.
66 $node = Node::load($node->id());
67 $nodes[] = clone $node;
70 $this->nodes = $nodes;
72 $this->drupalLogin($this->createUser(
74 'view page revisions',
75 'revert page revisions',
76 'delete page revisions',
77 'edit any page content',
78 'delete any page content',
79 'access contextual links',
80 'administer content types',
86 * Tests the contextual links on revisions.
88 public function testRevisionContextualLinks() {
89 // Confirm that the "Edit" and "Delete" contextual links appear for the
91 $this->drupalGet('node/' . $this->nodes[0]->id());
92 $page = $this->getSession()->getPage();
93 $page->waitFor(10, function () use ($page) {
94 return $page->find('css', "main .contextual");
97 $this->toggleContextualTriggerVisibility('main');
98 $page->find('css', 'main .contextual button')->press();
99 $links = $page->findAll('css', "main .contextual-links li a");
101 $this->assertEquals('Edit', $links[0]->getText());
102 $this->assertEquals('Delete', $links[1]->getText());
104 // Confirm that "Edit" and "Delete" contextual links don't appear for
105 // non-default revision.
106 $this->drupalGet("node/" . $this->nodes[0]->id() . "/revisions/" . $this->nodes[1]->getRevisionId() . "/view");
107 $this->assertSession()->pageTextContains($this->nodes[1]->getTitle());
108 $page->waitFor(10, function () use ($page) {
109 return $page->find('css', "main .contextual");
112 $this->toggleContextualTriggerVisibility('main');
113 $contextual_button = $page->find('css', 'main .contextual button');
114 $this->assertEmpty(0, $contextual_button);