Mercurial > hg > isophonics-drupal-site
comparison core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\contextual\FunctionalJavascript; | |
4 | |
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase; | |
6 use Drupal\user\Entity\Role; | |
7 | |
8 /** | |
9 * Tests the UI for correct contextual links. | |
10 * | |
11 * @group contextual | |
12 */ | |
13 class ContextualLinksTest extends JavascriptTestBase { | |
14 | |
15 use ContextualLinkClickTrait; | |
16 | |
17 /** | |
18 * {@inheritdoc} | |
19 */ | |
20 public static $modules = ['block', 'contextual']; | |
21 | |
22 /** | |
23 * {@inheritdoc} | |
24 */ | |
25 protected function setUp() { | |
26 parent::setUp(); | |
27 | |
28 $this->drupalLogin($this->createUser(['access contextual links'])); | |
29 $this->placeBlock('system_branding_block', ['id' => 'branding']); | |
30 } | |
31 | |
32 /** | |
33 * Tests the visibility of contextual links. | |
34 */ | |
35 public function testContextualLinksVisibility() { | |
36 $this->drupalGet('user'); | |
37 $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); | |
38 $this->assertEmpty($contextualLinks); | |
39 | |
40 // Ensure visibility remains correct after cached paged load. | |
41 $this->drupalGet('user'); | |
42 $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); | |
43 $this->assertEmpty($contextualLinks); | |
44 | |
45 // Grant permissions to use contextual links on blocks. | |
46 $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [ | |
47 'access contextual links', | |
48 'administer blocks', | |
49 ]); | |
50 | |
51 $this->drupalGet('user'); | |
52 $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); | |
53 $this->assertNotEmpty($contextualLinks); | |
54 | |
55 // Ensure visibility remains correct after cached paged load. | |
56 $this->drupalGet('user'); | |
57 $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button'); | |
58 $this->assertNotEmpty($contextualLinks); | |
59 } | |
60 | |
61 /** | |
62 * Test clicking contextual links. | |
63 */ | |
64 public function testContextualLinksClick() { | |
65 $this->container->get('module_installer')->install(['contextual_test']); | |
66 // Test clicking contextual link without toolbar. | |
67 $this->drupalGet('user'); | |
68 $this->assertSession()->assertWaitOnAjaxRequest(); | |
69 $this->clickContextualLink('#block-branding', 'Test Link'); | |
70 $this->assertSession()->pageTextContains('Everything is contextual!'); | |
71 | |
72 // Test clicking contextual link with toolbar. | |
73 $this->container->get('module_installer')->install(['toolbar']); | |
74 $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), ['access toolbar']); | |
75 $this->drupalGet('user'); | |
76 $this->assertSession()->assertWaitOnAjaxRequest(); | |
77 | |
78 // Click "Edit" in toolbar to show contextual links. | |
79 $this->getSession()->getPage()->find('css', '.contextual-toolbar-tab button')->press(); | |
80 $this->clickContextualLink('#block-branding', 'Test Link', FALSE); | |
81 $this->assertSession()->pageTextContains('Everything is contextual!'); | |
82 } | |
83 | |
84 } |