Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / node / tests / src / FunctionalJavascript / ContextualLinksTest.php
1 <?php
2
3 namespace Drupal\Tests\node\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\node\Entity\Node;
7 use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
8
9 /**
10  * Create a node with revisions and test contextual links.
11  *
12  * @group node
13  */
14 class ContextualLinksTest extends WebDriverTestBase {
15
16   use ContextualLinkClickTrait;
17
18   /**
19    * An array of node revisions.
20    *
21    * @var \Drupal\node\NodeInterface[]
22    */
23   protected $nodes;
24
25
26   /**
27    * {@inheritdoc}
28    */
29   protected static $modules = ['node', 'contextual'];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36
37     $this->drupalCreateContentType([
38       'type' => 'page',
39       'name' => 'Basic page',
40       'display_submitted' => FALSE,
41     ]);
42
43     // Create initial node.
44     $node = $this->drupalCreateNode();
45
46     $nodes = [];
47
48     // Get original node.
49     $nodes[] = clone $node;
50
51     // Create two revisions.
52     $revision_count = 2;
53     for ($i = 0; $i < $revision_count; $i++) {
54
55       // Create revision with a random title and body and update variables.
56       $node->title = $this->randomMachineName();
57       $node->body = [
58         'value' => $this->randomMachineName(32),
59         'format' => filter_default_format(),
60       ];
61       $node->setNewRevision();
62
63       $node->save();
64
65       // Make sure we get revision information.
66       $node = Node::load($node->id());
67       $nodes[] = clone $node;
68     }
69
70     $this->nodes = $nodes;
71
72     $this->drupalLogin($this->createUser(
73       [
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',
81       ]
82     ));
83   }
84
85   /**
86    * Tests the contextual links on revisions.
87    */
88   public function testRevisionContextualLinks() {
89     // Confirm that the "Edit" and "Delete" contextual links appear for the
90     // default revision.
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");
95     });
96
97     $this->toggleContextualTriggerVisibility('main');
98     $page->find('css', 'main .contextual button')->press();
99     $links = $page->findAll('css', "main .contextual-links li a");
100
101     $this->assertEquals('Edit', $links[0]->getText());
102     $this->assertEquals('Delete', $links[1]->getText());
103
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");
110     });
111
112     $this->toggleContextualTriggerVisibility('main');
113     $contextual_button = $page->find('css', 'main .contextual button');
114     $this->assertEmpty(0, $contextual_button);
115   }
116
117 }