[BUGFIX] Make Topbar bookmark acceptance test more stable
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / Backend / Topbar / BookmarkCest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Topbar;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Codeception\Scenario;
18 use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Admin;
19 use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\ModalDialog;
20 use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Topbar;
21
22 /**
23 * Test for the "Bookmark" functionality
24 */
25 class BookmarkCest
26 {
27 /**
28 * Selector for the module container in the topbar
29 *
30 * @var string
31 */
32 public static $topBarModuleSelector = '#typo3-cms-backend-backend-toolbaritems-shortcuttoolbaritem';
33
34 /**
35 * Selector for the "Add to bookmark" button
36 *
37 * @var string
38 */
39 protected static $docHeaderBookmarkButtonSelector = '.module-docheader .btn[title="Create a bookmark to this page"]';
40
41 /**
42 * @param Admin $I
43 */
44 public function _before(Admin $I)
45 {
46 $I->useExistingSession();
47 $I->switchToIFrame('content');
48 // Ensure main content frame is fully loaded, otherwise there are load-race-conditions
49 $I->waitForText('Web>Page module');
50 }
51
52 /**
53 * @param Admin $I
54 * @return Admin
55 */
56 public function checkThatBookmarkListIsInitiallyEmpty(Admin $I)
57 {
58 $this->clickBookmarkDropdownToggleInTopbar($I);
59 $I->cantSeeElement(self::$topBarModuleSelector . ' .shortcut');
60 return $I;
61 }
62
63 /**
64 * @depends checkThatBookmarkListIsInitiallyEmpty
65 * @param Admin $I
66 * @param ModalDialog $dialog
67 * @return Admin
68 */
69 public function checkThatAddingABookmarkAddsItemToTheBookmarkList(Admin $I, ModalDialog $dialog, Scenario $scenario)
70 {
71 $I->switchToIFrame();
72 // open the scheduler module as we would like to put it into the bookmark liste
73 $I->click('Scheduler', '#typo3-module-menu');
74
75 $I->switchToIFrame('content');
76
77 $I->click(self::$docHeaderBookmarkButtonSelector);
78 // cancel the action to test the functionality
79 $dialog->clickButtonInDialog('Cancel');
80
81 // check if the list is still empty
82 $this->checkThatBookmarkListIsInitiallyEmpty($I);
83
84 $I->switchToIFrame('content');
85 $I->click(self::$docHeaderBookmarkButtonSelector);
86
87 $dialog->clickButtonInDialog('OK');
88
89 $this->clickBookmarkDropdownToggleInTopbar($I);
90 $I->waitForText('Scheduled tasks', 15, self::$topBarModuleSelector . ' ' . Topbar::$dropdownContainerSelector);
91
92 // @test complete test when https://forge.typo3.org/issues/75689 is fixed
93 $scenario->comment(
94 'Tests for deleting the item in the list and readding it are missing ' .
95 'as this is currently broken in the core. See https://forge.typo3.org/issues/75689'
96 );
97
98 return $I;
99 }
100
101 /**
102 * @param Admin $I
103 * @depends checkThatAddingABookmarkAddsItemToTheBookmarkList
104 */
105 public function checkIfBookmarkItemLinksToTarget(Admin $I)
106 {
107 $this->clickBookmarkDropdownToggleInTopbar($I);
108 $I->click('Scheduled tasks', self::$topBarModuleSelector);
109 $I->switchToIFrame('content');
110 $I->canSee('Scheduled tasks', 'h1');
111 }
112
113 /**
114 * @param Admin $I
115 * @depends checkThatAddingABookmarkAddsItemToTheBookmarkList
116 */
117 public function checkIfEditBookmarkItemWorks(Admin $I)
118 {
119 $this->clickBookmarkDropdownToggleInTopbar($I);
120 $firstShortcutSelector = self::$topBarModuleSelector . ' .shortcut';
121 $I->click('.shortcut-edit', $firstShortcutSelector);
122
123 $I->fillField($firstShortcutSelector . ' input[name="shortcut-title"]', 'Scheduled tasks renamed');
124 $I->click('.shortcut-form-save', $firstShortcutSelector);
125
126 // searching in a specific context fails with an "Stale Element Reference Exception"
127 // see http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp
128 // currently don't know how to fix that so we search in the whole context.
129 $I->waitForText('Scheduled tasks renamed');
130 }
131
132 /**
133 * @param Admin $I
134 * @depends checkThatAddingABookmarkAddsItemToTheBookmarkList
135 */
136 public function checkIfDeleteBookmarkWorks(Admin $I, ModalDialog $dialog)
137 {
138 $this->clickBookmarkDropdownToggleInTopbar($I);
139
140 $I->canSee('Scheduled tasks renamed', self::$topBarModuleSelector);
141 $I->click('.shortcut-delete', self::$topBarModuleSelector . ' .shortcut');
142 $dialog->clickButtonInDialog('OK');
143
144 $I->cantSee('Scheduled tasks renamed', self::$topBarModuleSelector);
145 }
146
147 /**
148 * @param Admin $I
149 */
150 protected function clickBookmarkDropdownToggleInTopbar(Admin $I)
151 {
152 $I->switchToIFrame();
153 $I->click(Topbar::$dropdownToggleSelector, self::$topBarModuleSelector);
154 }
155 }