047bf477a7a11871fac6871e09eb21d0bc95efa0
[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\Helper\Topbar;
18
19 /**
20 * Various backend login related tests
21 */
22 class BackendLoginCest
23 {
24 /**
25 * Call backend login page and verify login button changes color on mouse over,
26 * verifies page is available and CSS is properly loaded.
27 *
28 * @param \AcceptanceTester $I
29 */
30 public function loginButtonMouseOver(\AcceptanceTester $I)
31 {
32 $I->wantTo('check login functions');
33 $I->amOnPage('/typo3/index.php');
34 $I->waitForElement('#t3-username', 10);
35 $I->wantTo('mouse over css change login button');
36
37 // Make sure mouse is not over submit button from a previous test
38 $I->moveMouseOver('#t3-username');
39 $bs = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
40 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
41 });
42
43 $I->moveMouseOver('#t3-login-submit');
44 $I->wait(1);
45 $bsmo = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
46 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
47 });
48 $I->assertFalse($bs === $bsmo);
49 }
50
51 /**
52 * Call backend login page and submit invalid login data.
53 * Verifies login is not accepted and an error message is rendered.
54 *
55 * @param \AcceptanceTester $I
56 */
57 public function loginDeniedWithInvalidCredentials(\AcceptanceTester $I)
58 {
59 $I->wantTo('check login functions');
60 $I->amOnPage('/typo3/index.php');
61 $I->waitForElement('#t3-username');
62
63 $I->wantTo('check empty credentials');
64 $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
65 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-username'))->getAttribute('required');
66 });
67 $I->assertEquals('true', $required, '#t3-username');
68
69 $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
70 return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-password'))->getAttribute('required');
71 });
72 $I->assertEquals('true', $required, '#t3-password');
73
74 $I->wantTo('use bad credentials');
75 $I->fillField('#t3-username', 'testify');
76 $I->fillField('#t3-password', '123456');
77 $I->click('#t3-login-submit-section > button');
78 $I->waitForText('Verifying Login Data');
79 $I->waitForElement('#t3-login-error');
80 $I->see('Your login attempt did not succeed');
81 }
82
83 /**
84 * Login a admin user and logout again
85 *
86 * @param \AcceptanceTester $I
87 */
88 public function loginWorksAsAdminUser(\AcceptanceTester $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 \AcceptanceTester $I
104 */
105 public function loginWorksAsEditorUser(\AcceptanceTester $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', '#typo3-menu');
111
112 $topBarItemSelector = Topbar::$containerSelector . ' ' . Topbar::$dropdownToggleSelector . ' *';
113
114 // can see bookmarks
115 $I->seeElement($topBarItemSelector, ['title' => 'Bookmarks']);
116
117 // cant 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 \AcceptanceTester $I
128 * @param string $username
129 * @param string $password
130 * @return void
131 */
132 protected function login(\AcceptanceTester $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('#typo3-contentContainer 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 \AcceptanceTester $I
151 * @return void
152 */
153 protected function logout(\AcceptanceTester $I)
154 {
155 $I->amGoingTo('step backend login');
156 $I->amGoingTo('logout');
157 // ensure that we are on the main frame
158 $I->switchToIFrame();
159 $I->click('#typo3-cms-backend-backend-toolbaritems-usertoolbaritem > a');
160 $I->click('Logout');
161 $I->waitForElement('#t3-username');
162 }
163 }