1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php
declare(strict_types=1);
namespace Drupal\Tests\toolbar\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests that the active trail is maintained in the toolbar.
*
* @group toolbar
*/
class ToolbarActiveTrailTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['toolbar', 'node', 'field_ui'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
$this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'administer content types',
'administer node fields',
'access toolbar',
]));
}
/**
* Tests that the active trail is maintained even when traversed deeper.
*
* @param string $orientation
* The toolbar orientation.
*
* @testWith ["vertical"]
* ["horizontal"]
*
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function testToolbarActiveTrail(string $orientation): void {
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
$this->drupalGet('<front>');
$this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
$this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '.toolbar-tray'));
$this->assertSession()->waitForElementRemoved('css', '.toolbar-loading');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#toolbar-item-administration.is-active'));
// If testing for vertical orientation of the toolbar then switch to it.
if ($orientation === 'vertical') {
$page->pressButton('Vertical orientation');
}
// Traverse deeper.
$this->clickLink('Structure');
$this->clickLink('Content types');
$this->clickLink('Manage fields');
$this->clickLink('Edit');
if ($orientation === 'vertical') {
$this->assertNotEmpty($assert_session->waitForElementVisible('named',
['link', 'Structure']));
// Assert that menu-item--active-trail was maintained.
$this->assertTrue($assert_session->waitForElementVisible('named',
['link', 'Structure'])->getParent()->getParent()->hasClass('menu-item--active-trail'));
$this->assertTrue($assert_session->waitForElementVisible('named',
['link', 'Content types'])->getParent()->getParent()->hasClass('menu-item--active-trail'));
// Change orientation and check focus is maintained.
$page->pressButton('Horizontal orientation');
$this->assertTrue($assert_session->waitForElementVisible('css',
'#toolbar-link-system-admin_structure')->hasClass('is-active'));
}
else {
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#toolbar-link-system-admin_structure'));
// Assert that is-active was maintained.
$this->assertTrue($assert_session->waitForElementVisible('css', '#toolbar-link-system-admin_structure')->hasClass('is-active'));
// Change orientation and check focus is maintained.
$page->pressButton('Vertical orientation');
// Introduce a delay to let the focus load.
$this->getSession()->wait(150);
$this->assertTrue($assert_session->waitForElementVisible('named',
['link', 'Structure'])->getParent()->getParent()->hasClass('menu-item--active-trail'));
$this->assertTrue($assert_session->waitForElementVisible('named',
['link', 'Content types'])->getParent()->getParent()->hasClass('menu-item--active-trail'));
}
}
}
|