[TASK] Codeception login success and click about module 89/46689/6
authorRoland Golla <rolandgolla@gmail.com>
Mon, 15 Feb 2016 22:59:03 +0000 (23:59 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 26 Feb 2016 12:15:14 +0000 (13:15 +0100)
Adds a test to login and logout an admin and an editor user.

Resolves: #73448
Releases: master
Change-Id: I8f7657a569230f910c58610095691b59fa45346b
Reviewed-on: https://review.typo3.org/46689
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Build/Configuration/Acceptance/acceptance.suite.yml
typo3/sysext/core/Tests/Acceptance/Backend/LoginAdminCest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Acceptance/Backend/LoginEditorCest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Acceptance/Fixtures/be_groups.xml [new file with mode: 0644]
typo3/sysext/core/Tests/Acceptance/Fixtures/be_users.xml [new file with mode: 0644]
typo3/sysext/core/Tests/AcceptanceCoreEnvironment.php
typo3/sysext/core/Tests/FunctionalTestCase.php
typo3/sysext/core/Tests/Testbase.php

index 4602ac3..4c42852 100644 (file)
@@ -9,10 +9,10 @@ modules:
       url: http://localhost:8000/typo3temp/var/tests/acceptance
       browser: phantomjs
       http_proxy: direct
+      window_size: 1024x768
 env:
   firefox:
     modules:
       config:
         WebDriver:
-          browser: 'firefox'
-          window_size: 1024x768
\ No newline at end of file
+          browser: 'firefox'
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/LoginAdminCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/LoginAdminCest.php
new file mode 100644 (file)
index 0000000..b1b5b7f
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Acceptance\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!
+ */
+
+/**
+ * Acceptance test
+ */
+class LoginAdminCest
+{
+
+    /**
+     * Login a admin user and logout again
+     *
+     * @param \AcceptanceTester $I
+     */
+    public function tryToTest(\AcceptanceTester $I)
+    {
+        $I->wantTo('login with admin');
+        $I->amOnPage('/typo3/index.php');
+        $I->waitForElement('#t3-username');
+        $I->fillField('#t3-username', 'admin');
+        $I->fillField('#t3-password', 'password');
+        $I->click('#t3-login-submit-section > button');
+        $I->waitForElement('.nav');
+        $I->seeCookie('be_lastLoginProvider');
+        $I->seeCookie('be_typo_user');
+        // user is redirected to 'about modules' after login, and must see the 'admin tools' section
+        $I->see('Admin tools');
+        $I->click('#typo3-cms-backend-backend-toolbaritems-usertoolbaritem > a');
+        $I->click('Logout');
+        $I->waitForElement('#t3-username');
+    }
+}
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/LoginEditorCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/LoginEditorCest.php
new file mode 100644 (file)
index 0000000..8dd3d04
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Acceptance\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!
+ */
+
+/**
+ * Acceptance test
+ */
+class LoginEditorCest
+{
+
+    /**
+     * Login a non-admin user and logout again
+     *
+     * @param \AcceptanceTester $I
+     */
+    public function tryToTest(\AcceptanceTester $I)
+    {
+        $I->wantTo('login with admin');
+        $I->amOnPage('/typo3/index.php');
+        $I->waitForElement('#t3-username');
+        $I->fillField('#t3-username', 'editor');
+        $I->fillField('#t3-password', 'password');
+        $I->click('#t3-login-submit-section > button');
+        $I->waitForElement('.nav');
+        $I->seeCookie('be_lastLoginProvider');
+        $I->seeCookie('be_typo_user');
+        // user is redirected to 'about modules' after login, but must not see the 'admin tools' section
+        $I->cantSee('Admin tools');
+        $I->click('#typo3-cms-backend-backend-toolbaritems-usertoolbaritem > a');
+        $I->click('Logout');
+        $I->waitForElement('#t3-username');
+    }
+}
diff --git a/typo3/sysext/core/Tests/Acceptance/Fixtures/be_groups.xml b/typo3/sysext/core/Tests/Acceptance/Fixtures/be_groups.xml
new file mode 100644 (file)
index 0000000..7394d26
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+       <be_groups>
+               <uid>1</uid>
+               <pid>0</pid>
+               <tstamp>1452959228</tstamp>
+               <title>editor-group</title>
+               <tables_modify>pages</tables_modify>
+               <crdate>1452959228</crdate>
+               <cruser_id>1</cruser_id>
+       </be_groups>
+</dataset>
diff --git a/typo3/sysext/core/Tests/Acceptance/Fixtures/be_users.xml b/typo3/sysext/core/Tests/Acceptance/Fixtures/be_users.xml
new file mode 100644 (file)
index 0000000..c386c25
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+       <be_users>
+               <uid>1</uid>
+               <pid>0</pid>
+               <tstamp>1366642540</tstamp>
+               <username>admin</username>
+               <password>$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1</password> <!-- password -->
+               <admin>1</admin>
+               <disable>0</disable>
+               <starttime>0</starttime>
+               <endtime>0</endtime>
+               <options>0</options>
+               <crdate>1366642540</crdate>
+               <cruser_id>0</cruser_id>
+               <workspace_perms>1</workspace_perms>
+               <disableIPlock>1</disableIPlock>
+               <deleted>0</deleted>
+               <TSconfig>NULL</TSconfig>
+               <lastlogin>1371033743</lastlogin>
+               <createdByAction>0</createdByAction>
+               <workspace_id>0</workspace_id>
+               <workspace_preview>1</workspace_preview>
+       </be_users>
+       <be_users>
+               <uid>2</uid>
+               <pid>0</pid>
+               <tstamp>1452944912</tstamp>
+               <username>editor</username>
+               <password>$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1</password> <!-- password -->
+               <admin>0</admin>
+               <disable>0</disable>
+               <starttime>0</starttime>
+               <endtime>0</endtime>
+               <options>0</options>
+               <crdate>1452944912</crdate>
+               <cruser_id>1</cruser_id>
+               <workspace_perms>1</workspace_perms>
+               <disableIPlock>1</disableIPlock>
+               <deleted>0</deleted>
+               <TSconfig>NULL</TSconfig>
+               <lastlogin>1452944915</lastlogin>
+               <createdByAction>0</createdByAction>
+               <workspace_id>0</workspace_id>
+               <workspace_preview>1</workspace_preview>
+               <db_mountpoints>1</db_mountpoints>
+               <usergroup>1</usergroup>
+       </be_users>
+</dataset>
index d3f28b2..efcd25a 100644 (file)
@@ -121,6 +121,18 @@ class AcceptanceCoreEnvironment extends Extension
     protected $additionalFoldersToCreate = [];
 
     /**
+     * XML database fixtures to be loaded into database.
+     *
+     * Given paths are expected to be relative to your document root.
+     *
+     * @var array
+     */
+    protected $xmlDatabaseFixtures = [
+        'typo3/sysext/core/Tests/Acceptance/Fixtures/be_users.xml',
+        'typo3/sysext/core/Tests/Acceptance/Fixtures/be_groups.xml',
+    ];
+
+    /**
      * Events to listen to
      */
     public static $events = [
@@ -210,6 +222,10 @@ class AcceptanceCoreEnvironment extends Extension
         // unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['extbase']);
         $suite = $suiteEvent->getSuite();
         $suite->setBackupGlobals(FALSE);
+
+        foreach ($this->xmlDatabaseFixtures as $fixture) {
+            $testbase->importXmlDatabaseFixture(ORIGINAL_ROOT . $fixture);
+        }
     }
 
 }
index 16cb328..8d6f8f7 100644 (file)
@@ -309,56 +309,8 @@ abstract class FunctionalTestCase extends BaseTestCase
      */
     protected function importDataSet($path)
     {
-        if (!is_file($path)) {
-            throw new Exception(
-                'Fixture file ' . $path . ' not found',
-                1376746261
-            );
-        }
-
-        $database = $this->getDatabaseConnection();
-
-        $fileContent = file_get_contents($path);
-        // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
-        $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
-        $xml = simplexml_load_string($fileContent);
-        libxml_disable_entity_loader($previousValueOfEntityLoader);
-        $foreignKeys = array();
-
-        /** @var $table \SimpleXMLElement */
-        foreach ($xml->children() as $table) {
-            $insertArray = array();
-
-            /** @var $column \SimpleXMLElement */
-            foreach ($table->children() as $column) {
-                $columnName = $column->getName();
-                $columnValue = null;
-
-                if (isset($column['ref'])) {
-                    list($tableName, $elementId) = explode('#', $column['ref']);
-                    $columnValue = $foreignKeys[$tableName][$elementId];
-                } elseif (isset($column['is-NULL']) && ($column['is-NULL'] === 'yes')) {
-                    $columnValue = null;
-                } else {
-                    $columnValue = (string)$table->$columnName;
-                }
-
-                $insertArray[$columnName] = $columnValue;
-            }
-
-            $tableName = $table->getName();
-            $result = $database->exec_INSERTquery($tableName, $insertArray);
-            if ($result === false) {
-                throw new Exception(
-                    'Error when processing fixture file: ' . $path . ' Can not insert data to table ' . $tableName . ': ' . $database->sql_error(),
-                    1376746262
-                );
-            }
-            if (isset($table['id'])) {
-                $elementId = (string)$table['id'];
-                $foreignKeys[$tableName][$elementId] = $database->sql_insert_id();
-            }
-        }
+        $testbase = new Testbase();
+        $testbase->importXmlDatabaseFixture($path);
     }
 
     /**
index 626b198..d1ced4c 100644 (file)
@@ -616,6 +616,68 @@ class Testbase {
     }
 
     /**
+     * Imports a data set represented as XML into the test database,
+     *
+     * @param string $path Absolute path to the XML file containing the data set to load
+     * @return void
+     * @throws Exception
+     */
+    public function importXmlDatabaseFixture($path)
+    {
+        if (!is_file($path)) {
+            throw new Exception(
+                'Fixture file ' . $path . ' not found',
+                1376746261
+            );
+        }
+
+        /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
+        $database = $GLOBALS['TYPO3_DB'];
+
+        $fileContent = file_get_contents($path);
+        // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
+        $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
+        $xml = simplexml_load_string($fileContent);
+        libxml_disable_entity_loader($previousValueOfEntityLoader);
+        $foreignKeys = array();
+
+        /** @var $table \SimpleXMLElement */
+        foreach ($xml->children() as $table) {
+            $insertArray = array();
+
+            /** @var $column \SimpleXMLElement */
+            foreach ($table->children() as $column) {
+                $columnName = $column->getName();
+                $columnValue = null;
+
+                if (isset($column['ref'])) {
+                    list($tableName, $elementId) = explode('#', $column['ref']);
+                    $columnValue = $foreignKeys[$tableName][$elementId];
+                } elseif (isset($column['is-NULL']) && ($column['is-NULL'] === 'yes')) {
+                    $columnValue = null;
+                } else {
+                    $columnValue = (string)$table->$columnName;
+                }
+
+                $insertArray[$columnName] = $columnValue;
+            }
+
+            $tableName = $table->getName();
+            $result = $database->exec_INSERTquery($tableName, $insertArray);
+            if ($result === false) {
+                throw new Exception(
+                    'Error when processing fixture file: ' . $path . ' Can not insert data to table ' . $tableName . ': ' . $database->sql_error(),
+                    1376746262
+                );
+            }
+            if (isset($table['id'])) {
+                $elementId = (string)$table['id'];
+                $foreignKeys[$tableName][$elementId] = $database->sql_insert_id();
+            }
+        }
+    }
+
+    /**
      * Returns the absolute path the TYPO3 document root.
      * This is the "original" document root, not the "instance" root for functional / acceptance tests.
      *