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