‪TYPO3CMS  ‪main
SelectPagetreeWithKeyboardCest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Facebook\WebDriver\WebDriverBy;
21 use Facebook\WebDriver\WebDriverKeys;
24 
29 {
33  public function ‪_before(‪ApplicationTester $I, ‪PageTree $pageTree): void
34  {
35  $I->useExistingSession('admin');
36  $I->click('List');
37  $pageTree->‪openPath(['Root']);
38  $I->waitForElement('#typo3-pagetree-treeContainer [role="treeitem"][data-id="1"]', 5);
39  }
40 
45  {
46  $I->seeElement('#typo3-pagetree-tree [role="treeitem"].node-selected');
47  $I->pressKey('#typo3-pagetree-tree [role="treeitem"].node-selected', WebDriverKeys::DOWN);
48  $I->assertEquals(
49  'Dummy 1-2',
50  $this->‪grabFocussedText($I)
51  );
52  $this->‪sendKey($I, WebDriverKeys::ENTER);
53  $I->switchToContentFrame();
54  $I->see('Dummy 1-2');
55  }
56 
61  {
62  $I->seeElement('#typo3-pagetree-tree [role="treeitem"].node-selected');
63  $I->pressKey('#typo3-pagetree-tree [role="treeitem"].node-selected', WebDriverKeys::DOWN);
64  $this->‪sendKey($I, WebDriverKeys::DOWN);
65  $I->assertEquals(
66  'Dummy 1-3',
67  $this->‪grabFocussedText($I)
68  );
69  $this->‪sendKey($I, WebDriverKeys::UP);
70  $I->assertEquals(
71  'Dummy 1-2',
72  $this->‪grabFocussedText($I)
73  );
74  }
75 
80  {
81  $I->seeElement('#typo3-pagetree-tree [role="treeitem"].node-selected');
82  $I->amGoingTo('use keyboard to navigate through the tree');
83  $I->pressKey('#typo3-pagetree-tree [role="treeitem"].node-selected', WebDriverKeys::DOWN);
84  $this->‪sendKey($I, WebDriverKeys::DOWN);
85  $this->‪sendKey($I, WebDriverKeys::DOWN);
86  $I->amGoingTo('check if the parent key is selected and child is not visible');
87  $I->assertEquals(
88  'Dummy 1-4',
89  $this->‪grabFocussedText($I)
90  );
91  $I->amGoingTo('check if parent is still selected and child is visible');
92  $this->‪sendKey($I, WebDriverKeys::RIGHT);
93  $I->assertEquals(
94  'Dummy 1-4',
95  $this->‪grabFocussedText($I)
96  );
97  $I->see('Dummy 1-4-5');
98  $I->amGoingTo('check if first child node is selected');
99  $this->‪sendKey($I, WebDriverKeys::RIGHT);
100  $I->assertEquals(
101  'Dummy 1-4-5',
102  $this->‪grabFocussedText($I)
103  );
104  $this->‪sendKey($I, WebDriverKeys::RIGHT);
105  $I->amGoingTo('check if first child node is still selected');
106  $I->assertEquals(
107  'Dummy 1-4-5',
108  $this->‪grabFocussedText($I)
109  );
110  $I->amGoingTo('check if second child node is selected');
111  $this->‪sendKey($I, WebDriverKeys::DOWN);
112  $I->assertEquals(
113  'Dummy 6',
114  $this->‪grabFocussedText($I)
115  );
116  }
117 
122  {
123  $I->seeElement('#typo3-pagetree-tree [role="treeitem"].node-selected');
124  $I->assertEquals(
125  'Root',
126  $I->grabTextFrom('#typo3-pagetree-tree [role="treeitem"].node-selected')
127  );
128  $I->see('Dummy 1-2');
129  $I->amGoingTo('collapse the current tree using left key');
130  $I->pressKey('#typo3-pagetree-tree [role="treeitem"].node-selected', WebDriverKeys::LEFT);
131  $I->assertEquals(
132  'Root',
133  $this->‪grabFocussedText($I)
134  );
135  $I->cantSee('Dummy 1-2');
136  $I->amGoingTo('go to parent of the current collapsed node using left key');
137  $this->‪sendKey($I, WebDriverKeys::LEFT);
138  $I->amGoingTo('check if parent (root) is selected and child is visible');
139  $I->assertEquals(
140  'New TYPO3 site',
141  $this->‪grabFocussedText($I)
142  );
143  $I->canSee('Root');
144  $I->canSee('styleguide TCA demo');
145  }
146 
151  {
152  $I->seeElement('#typo3-pagetree-tree [role="treeitem"].node-selected');
153  $I->pressKey('#typo3-pagetree-tree [role="treeitem"].node-selected', WebDriverKeys::DOWN);
154  for ($times = 0; $times < 14; $times++) {
155  $this->‪sendKey($I, WebDriverKeys::DOWN);
156  }
157  $I->assertEquals(
158  'Dummy 1-21',
159  $this->‪grabFocussedText($I)
160  );
161 
162  $this->‪sendKey($I, WebDriverKeys::HOME);
163  $I->assertEquals(
164  'New TYPO3 site',
165  $this->‪grabFocussedText($I)
166  );
167  }
168 
169  private function ‪getFocusedNode(‪ApplicationTester $I): ?WebDriverBy
170  {
171  $treeId = $I->executeJS('return document.querySelector(\'#typo3-pagetree-tree [role="treeitem"]:focus\')?.getAttribute("data-tree-id")');
172  if ($treeId !== null) {
173  return WebDriverBy::xpath('//*[@id="typo3-pagetree-tree"]//*[@role="treeitem" and @data-tree-id="' . $treeId . '"]');
174  }
175  return null;
176  }
177 
178  private function ‪sendKey(‪ApplicationTester $I, string $key): void
179  {
180  $I->pressKey($this->‪getFocusedNode($I), $key);
181  }
182 
183  private function ‪grabFocussedText(‪ApplicationTester $I): string
184  {
185  return $I->grabTextFrom($this->‪getFocusedNode($I));
186  }
187 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\getFocusedNode
‪getFocusedNode(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:169
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\focusPageWithDownKeyAndOpenItWithEnter
‪focusPageWithDownKeyAndOpenItWithEnter(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:44
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree
Definition: PageCreationWithDragAndDropCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\focusPageWithDownAndUpKey
‪focusPageWithDownAndUpKey(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:60
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\collapseSubtreeWithLeftArrow
‪collapseSubtreeWithLeftArrow(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:121
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\AbstractTree\openPath
‪openPath(array $path)
Definition: AbstractTree.php:55
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest
Definition: SelectPagetreeWithKeyboardCest.php:29
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\_before
‪_before(ApplicationTester $I, PageTree $pageTree)
Definition: SelectPagetreeWithKeyboardCest.php:33
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\focusFirstPageTreeItemWithHomeKey
‪focusFirstPageTreeItemWithHomeKey(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:150
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\sendKey
‪sendKey(ApplicationTester $I, string $key)
Definition: SelectPagetreeWithKeyboardCest.php:178
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:26
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\expandSubtreeWithRightArrow
‪expandSubtreeWithRightArrow(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:79
‪TYPO3\CMS\Core\Tests\Acceptance\Application\PageTree\SelectPagetreeWithKeyboardCest\grabFocussedText
‪grabFocussedText(ApplicationTester $I)
Definition: SelectPagetreeWithKeyboardCest.php:183