From 2133c552a838dffa41580fa914c8718e915f0971 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Fri, 27 May 2016 16:46:47 +0200
Subject: [PATCH] [TASK] Clean up acceptance tests

Merge the login related tests into one test case
and use the default \AcceptanceTester to do the tests.

Change-Id: I7e018fb1cdf10aada9854931736f87593ceeff10
Resolves: #76331
Releases: master
Reviewed-on: https://review.typo3.org/48340
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Acceptance/Backend/Login/AdminCest.php    |  41 -----
 .../Backend/Login/BackendLoginCest.php        | 163 ++++++++++++++++++
 .../Backend/Login/BadCredentialsCest.php      |  56 ------
 .../Acceptance/Backend/Login/EditorCest.php   |  48 ------
 .../Backend/Login/MouseOverCest.php           |  51 ------
 .../Backend/Page/AddPageInPageModuleCest.php  |   8 +-
 .../Backend/Topbar/UsernameOnAvatarCest.php   |   6 +-
 .../Tests/Acceptance/Step/Backend/Kasper.php  |  81 ---------
 8 files changed, 172 insertions(+), 282 deletions(-)
 delete mode 100644 typo3/sysext/core/Tests/Acceptance/Backend/Login/AdminCest.php
 create mode 100644 typo3/sysext/core/Tests/Acceptance/Backend/Login/BackendLoginCest.php
 delete mode 100644 typo3/sysext/core/Tests/Acceptance/Backend/Login/BadCredentialsCest.php
 delete mode 100644 typo3/sysext/core/Tests/Acceptance/Backend/Login/EditorCest.php
 delete mode 100644 typo3/sysext/core/Tests/Acceptance/Backend/Login/MouseOverCest.php
 delete mode 100644 typo3/sysext/core/Tests/Acceptance/Step/Backend/Kasper.php

diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Login/AdminCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Login/AdminCest.php
deleted file mode 100644
index 587d0a53c1d6..000000000000
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Login/AdminCest.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Login;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Kasper;
-
-/**
- * Acceptance test
- */
-class AdminCest
-{
-
-    /**
-     * Login a admin user and logout again
-     *
-     * @param Kasper $I
-     */
-    public function tryToTest(Kasper $I)
-    {
-        $I->wantTo('login with admin');
-        $I->loginAsAdmin();
-
-        // user is redirected to 'about modules' after login, and must see the 'admin tools' section
-        $I->see('Admin tools');
-
-        $I->logout();
-        $I->waitForElement('#t3-username');
-    }
-}
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Login/BackendLoginCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Login/BackendLoginCest.php
new file mode 100644
index 000000000000..61984f8be3b8
--- /dev/null
+++ b/typo3/sysext/core/Tests/Acceptance/Backend/Login/BackendLoginCest.php
@@ -0,0 +1,163 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Login;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Topbar;
+
+/**
+ * Various backend login related tests
+ */
+class BackendLoginCest
+{
+    /**
+     * Call backend login page and verify login button changes color on mouse over,
+     * verifies page is available and CSS is properly loaded.
+     *
+     * @param \AcceptanceTester $I
+     */
+    public function loginButtonMouseOver(\AcceptanceTester $I)
+    {
+        $I->wantTo('check login functions');
+        $I->amOnPage('/typo3/index.php');
+        $I->waitForElement('#t3-username', 10);
+        $I->wantTo('mouse over css change login button');
+
+        // Make sure mouse is not over submit button from a previous test
+        $I->moveMouseOver('#t3-username');
+        $bs = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
+            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
+        });
+
+        $I->moveMouseOver('#t3-login-submit');
+        $I->wait(1);
+        $bsmo = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
+            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
+        });
+        $I->assertFalse($bs === $bsmo);
+    }
+
+    /**
+     * Call backend login page and submit invalid login data.
+     * Verifies login is not accepted and an error message is rendered.
+     *
+     * @param \AcceptanceTester $I
+     */
+    public function loginDeniedWithInvalidCredentials(\AcceptanceTester $I)
+    {
+        $I->wantTo('check login functions');
+        $I->amOnPage('/typo3/index.php');
+        $I->waitForElement('#t3-username');
+
+        $I->wantTo('check empty credentials');
+        $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
+            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-username'))->getAttribute('required');
+        });
+        $I->assertEquals('true', $required, '#t3-username');
+
+        $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
+            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-password'))->getAttribute('required');
+        });
+        $I->assertEquals('true', $required, '#t3-password');
+
+        $I->wantTo('use bad credentials');
+        $I->fillField('#t3-username', 'testify');
+        $I->fillField('#t3-password', '123456');
+        $I->click('#t3-login-submit-section > button');
+        $I->waitForText('Verifying Login Data');
+        $I->waitForElement('#t3-login-error');
+        $I->see('Your login attempt did not succeed');
+    }
+
+    /**
+     * Login a admin user and logout again
+     *
+     * @param \AcceptanceTester $I
+     */
+    public function loginWorksAsAdminUser(\AcceptanceTester $I)
+    {
+        $I->wantTo('login with admin');
+        $this->login($I, 'admin', 'password');
+
+        // user is redirected to 'about modules' after login, and must see the 'admin tools' section
+        $I->see('Admin tools');
+
+        $this->logout($I);
+        $I->waitForElement('#t3-username');
+    }
+
+    /**
+     * Login as a non-admin user, check visible modules and logout again
+     *
+     * @param \AcceptanceTester $I
+     */
+    public function loginWorksAsEditorUser(\AcceptanceTester $I)
+    {
+        $this->login($I, 'editor', 'password');
+
+        // user is redirected to 'about modules' after login, but must not see the 'admin tools' section
+        $I->cantSee('Admin tools', '#typo3-menu');
+
+        $topBarItemSelector = Topbar::$containerSelector . ' ' . Topbar::$dropdownToggleSelector . ' *';
+
+        // can see bookmarks
+        $I->seeElement($topBarItemSelector, ['title' => 'Bookmarks']);
+
+        // cant see clear cache
+        $I->cantSeeElement($topBarItemSelector, ['title' => 'Clear cache']);
+
+        $this->logout($I);
+        $I->waitForElement('#t3-username');
+    }
+
+    /**
+     * Helper method for user login on backend login screen
+     *
+     * @param \AcceptanceTester $I
+     * @param string $username
+     * @param string $password
+     * @return void
+     */
+    protected function login(\AcceptanceTester $I, string $username, string $password)
+    {
+        $I->amGoingTo('Step\Backend\Login username: ' . $username);
+        $I->amOnPage('/typo3/index.php');
+        $I->waitForElement('#t3-username');
+        $I->fillField('#t3-username', $username);
+        $I->fillField('#t3-password', $password);
+        $I->click('#t3-login-submit-section > button');
+        // wait for the next to element to indicate if the backend was loaded successful
+        $I->waitForElement('.nav', 30);
+        $I->waitForElement('#typo3-contentContainer iframe', 30);
+        $I->seeCookie('be_lastLoginProvider');
+        $I->seeCookie('be_typo_user');
+    }
+
+    /**
+     * Logout user by clicking logout button in toolbar
+     *
+     * @param \AcceptanceTester $I
+     * @return void
+     */
+    protected function logout(\AcceptanceTester $I)
+    {
+        $I->amGoingTo('step backend login');
+        $I->amGoingTo('logout');
+        // ensure that we are on the main frame
+        $I->switchToIFrame();
+        $I->click('#typo3-cms-backend-backend-toolbaritems-usertoolbaritem > a');
+        $I->click('Logout');
+        $I->waitForElement('#t3-username');
+    }
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Login/BadCredentialsCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Login/BadCredentialsCest.php
deleted file mode 100644
index 4afe49c4ed46..000000000000
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Login/BadCredentialsCest.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Login;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Kasper;
-
-/**
- * Acceptance test
- */
-class BadCredentialsCest
-{
-
-    /**
-     * Call backend login page and submit invalid login data.
-     * Verifies login is not accepted and an error message is rendered.
-     *
-     * @param Kasper $I
-     */
-    public function tryToTest(Kasper $I)
-    {
-        $I->wantTo('check login functions');
-        $I->amOnPage('/typo3/index.php');
-        $I->waitForElement('#t3-username');
-
-        $I->wantTo('check empty credentials');
-        $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
-            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-username'))->getAttribute('required');
-        });
-        $I->assertEquals('true', $required, '#t3-username');
-
-        $required = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
-            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-password'))->getAttribute('required');
-        });
-        $I->assertEquals('true', $required, '#t3-password');
-
-        $I->wantTo('use bad credentials');
-        $I->fillField('#t3-username', 'testify');
-        $I->fillField('#t3-password', '123456');
-        $I->click('#t3-login-submit-section > button');
-        $I->waitForText('Verifying Login Data');
-        $I->waitForElement('#t3-login-error');
-        $I->see('Your login attempt did not succeed');
-    }
-}
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Login/EditorCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Login/EditorCest.php
deleted file mode 100644
index d5920aa92228..000000000000
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Login/EditorCest.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Login;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Kasper;
-use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Topbar;
-
-/**
- * Editor login tests
- */
-class EditorCest
-{
-    /**
-     * Login as a non-admin user, check visible modules and logout again
-     *
-     * @param Kasper $I
-     */
-    public function loginAsEditor(Kasper $I)
-    {
-        $I->loginAsEditor();
-
-        // user is redirected to 'about modules' after login, but must not see the 'admin tools' section
-        $I->cantSee('Admin tools', '#typo3-menu');
-
-        $topBarItemSelector = Topbar::$containerSelector . ' ' . Topbar::$dropdownToggleSelector . ' *';
-
-        // can see bookmarks
-        $I->seeElement($topBarItemSelector, ['title' => 'Bookmarks']);
-
-        // cant see clear cache
-        $I->cantSeeElement($topBarItemSelector, ['title' => 'Clear cache']);
-
-        $I->logout();
-        $I->waitForElement('#t3-username');
-    }
-}
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Login/MouseOverCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Login/MouseOverCest.php
deleted file mode 100644
index 1aeb17cdb48c..000000000000
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Login/MouseOverCest.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Login;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Kasper;
-
-/**
- * Acceptance test
- */
-class MouseOverCest
-{
-
-    /**
-     * Call backend login page and verify login button changes color on mouse over,
-     * verifies page is available and CSS is properly loaded.
-     *
-     * @param Kasper $I
-     */
-    public function tryToTest(Kasper $I)
-    {
-        $I->wantTo('check login functions');
-        $I->amOnPage('/typo3/index.php');
-        $I->waitForElement('#t3-username', 10);
-        $I->wantTo('mouse over css change login button');
-
-        // Make sure mouse is not over submit button from a previous test
-        $I->moveMouseOver('#t3-username');
-        $bs = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
-            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
-        });
-
-        $I->moveMouseOver('#t3-login-submit');
-        $I->wait(1);
-        $bsmo = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
-            return $webdriver->findElement(\WebDriverBy::cssSelector('#t3-login-submit'))->getCSSValue('box-shadow');
-        });
-        $I->assertFalse($bs === $bsmo);
-    }
-}
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Page/AddPageInPageModuleCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Page/AddPageInPageModuleCest.php
index 924db8a27e83..1a9f5a3599f7 100644
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Page/AddPageInPageModuleCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Backend/Page/AddPageInPageModuleCest.php
@@ -17,8 +17,7 @@ namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Page;
 use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Admin;
 
 /**
- * This testcase is used to check if a page can be added with the page module.
- * It also tests to remove the new page with the page tree context menu.
+ * Page and page tree related tests.
  */
 class AddPageInPageModuleCest
 {
@@ -32,9 +31,12 @@ class AddPageInPageModuleCest
     }
 
     /**
+     * This test case is used to check if a page can be added with the page module.
+     * It also tests to remove the new page with the page tree context menu.
+     *
      * @param Admin $I
      */
-    public function tryToTest(Admin $I)
+    public function addAndDeletePage(Admin $I)
     {
         // Select page module
         $I->wantToTest('Add a page with page module');
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Topbar/UsernameOnAvatarCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Topbar/UsernameOnAvatarCest.php
index 4c913cf491f0..b412d587d3cf 100644
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Topbar/UsernameOnAvatarCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Backend/Topbar/UsernameOnAvatarCest.php
@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Topbar;
 use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Admin;
 
 /**
- * This test case is used to check if username is visible in the toolbar.
+ * Topbar username and avatar module tests.
  */
 class UsernameOnAvatarCest
 {
@@ -31,9 +31,11 @@ class UsernameOnAvatarCest
     }
 
     /**
+     * This test case is used to check if username is visible in the toolbar.
+     *
      * @param Admin $I
      */
-    public function tryToTest(Admin $I)
+    public function usernameIsShown(Admin $I)
     {
         $I->see('admin', '#typo3-cms-backend-backend-toolbaritems-usertoolbaritem');
     }
diff --git a/typo3/sysext/core/Tests/Acceptance/Step/Backend/Kasper.php b/typo3/sysext/core/Tests/Acceptance/Step/Backend/Kasper.php
deleted file mode 100644
index 110aa7bd6148..000000000000
--- a/typo3/sysext/core/Tests/Acceptance/Step/Backend/Kasper.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Acceptance\Step\Backend;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-class Kasper extends \AcceptanceTester
-{
-    /**
-     * Login as user "admin" with password "password".
-     * This user was added as fixture during test bootstrap.
-     *
-     * @return void
-     */
-    public function loginAsAdmin()
-    {
-        $I = $this;
-        $I->login('admin', 'password');
-    }
-
-    /**
-     * Login as user "editor" with password "passowrd".
-     * This user was added as fixture during test bootsrap.
-     *
-     * @return void
-     */
-    public function loginAsEditor()
-    {
-        $I = $this;
-        $I->login('editor', 'password');
-    }
-
-    /**
-     * Logout user by clicking logout button in toolbar
-     *
-     * @return void
-     */
-    public function logout()
-    {
-        $I = $this;
-        $I->amGoingTo('step backend login');
-        $I->amGoingTo('logout');
-        // ensure that we are on the main frame
-        $I->switchToIFrame();
-        $I->click('#typo3-cms-backend-backend-toolbaritems-usertoolbaritem > a');
-        $I->click('Logout');
-        $I->waitForElement('#t3-username');
-    }
-
-    /**
-     * Helper method for user login.
-     *
-     * @param string $username
-     * @param string $password
-     */
-    protected function login(string $username, string $password)
-    {
-        $I = $this;
-        $I->amGoingTo('Step\Backend\Login username: ' . $username);
-        $I->amOnPage('/typo3/index.php');
-        $I->waitForElement('#t3-username');
-        $I->fillField('#t3-username', $username);
-        $I->fillField('#t3-password', $password);
-        $I->click('#t3-login-submit-section > button');
-        // wait for the next to element to indicate if the backend was loaded successful
-        $I->waitForElement('.nav', 30);
-        $I->waitForElement('#typo3-contentContainer iframe', 30);
-        $I->seeCookie('be_lastLoginProvider');
-        $I->seeCookie('be_typo_user');
-    }
-}
-- 
GitLab