[TASK] Refactor acceptance tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / Backend / Login / BackendLoginCest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Login;
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
18 use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
19 use TYPO3\TestingFramework\Core\Acceptance\Helper\Topbar;
20
21 /**
22 * Various backend login related tests
23 */
24 class BackendLoginCest
25 {
26 /**
27 * Call backend login page and verify login button changes color on mouse over,
28 * verifies page is available and CSS is properly loaded.
29 *
30 * @param BackendTester $I
31 */
32 public function loginButtonMouseOver(BackendTester $I)
33 {
34 $I->wantTo('check login functions');
35 $I->amOnPage('/typo3/index.php');
36 $I->waitForElement('#t3-username', 10);
37 $I->wantTo('mouse over css change login button');
38
39 // Make sure mouse is not over submit button from a previous test
40 $I->moveMouseOver('#t3-username');
41 $bs = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
42 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
43 });
44
45 $I->moveMouseOver('#t3-login-submit');
46 $I->wait(1);
47 $bsmo = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
48 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
49 });
50 $I->assertFalse($bs === $bsmo);
51 }
52
53 /**
54 * Call backend login page and submit invalid login data.
55 * Verifies login is not accepted and an error message is rendered.
56 *
57 * @param BackendTester $I
58 */
59 public function loginDeniedWithInvalidCredentials(BackendTester $I)
60 {
61 $I->wantTo('check login functions');
62 $I->amOnPage('/typo3/index.php');
63 $I->waitForElement('#t3-username');
64
65 $I->wantTo('check empty credentials');
66 $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
67 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-username'))->getAttribute('required');
68 });
69 $I->assertEquals('true', $required, '#t3-username');
70
71 $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
72 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-password'))->getAttribute('required');
73 });
74 $I->assertEquals('true', $required, '#t3-password');
75
76 $I->wantTo('use bad credentials');
77 $I->fillField('#t3-username', 'testify');
78 $I->fillField('#t3-password', '123456');
79 $I->click('#t3-login-submit-section > button');
80 $I->waitForElement('#t3-login-error', 30);
81 $I->see('Your login attempt did not succeed');
82 }
83
84 /**
85 * Login a admin user and logout again
86 *
87 * @param BackendTester $I
88 */
89 public function loginWorksAsAdminUser(BackendTester $I)
90 {
91 $I->wantTo('login with admin');
92 $this->login($I, 'admin', 'password');
93
94 // user is redirected to 'about modules' after login, and must see the 'admin tools' section
95 $I->see('Admin tools');
96
97 $this->logout($I);
98 $I->waitForElement('#t3-username');
99 }
100
101 /**
102 * Login as a non-admin user, check visible modules and logout again
103 *
104 * @param BackendTester $I
105 */
106 public function loginWorksAsEditorUser(BackendTester $I)
107 {
108 $this->login($I, 'editor', 'password');
109
110 // user is redirected to 'about modules' after login, but must not see the 'admin tools' section
111 $I->cantSee('Admin tools', '#menu');
112
113 $topBarItemSelector = Topbar::$containerSelector . ' ' . Topbar::$dropdownToggleSelector . ' *';
114
115 // can see bookmarks
116 $I->seeElement($topBarItemSelector, ['title' => 'Bookmarks']);
117
118 // can't see clear cache
119 $I->cantSeeElement($topBarItemSelector, ['title' => 'Clear cache']);
120
121 $this->logout($I);
122 $I->waitForElement('#t3-username');
123 }
124
125 /**
126 * Helper method for user login on backend login screen
127 *
128 * @param BackendTester $I
129 * @param string $username
130 * @param string $password
131 */
132 protected function login(BackendTester $I, string $username, string $password)
133 {
134 $I->amGoingTo('Step\Backend\Login username: ' . $username);
135 $I->amOnPage('/typo3/index.php');
136 $I->waitForElement('#t3-username');
137 $I->fillField('#t3-username', $username);
138 $I->fillField('#t3-password', $password);
139 $I->click('#t3-login-submit-section > button');
140 // wait for the next to element to indicate if the backend was loaded successful
141 $I->waitForElement('.nav', 30);
142 $I->waitForElement('.scaffold-content iframe', 30);
143 $I->seeCookie('be_lastLoginProvider');
144 $I->seeCookie('be_typo_user');
145 }
146
147 /**
148 * Logout user by clicking logout button in toolbar
149 *
150 * @param BackendTester $I
151 */
152 protected function logout(BackendTester $I)
153 {
154 $I->amGoingTo('step backend login');
155 $I->amGoingTo('logout');
156 // ensure that we are on the main frame
157 $I->switchToMainFrame();
158 $I->click('#typo3-cms-backend-backend-toolbaritems-usertoolbaritem > a');
159 $I->click('Logout');
160 $I->waitForElement('#t3-username');
161 }
162 }