Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117749652
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/index-test.php b/index-test.php
new file mode 100644
index 000000000..b880f7c1f
--- /dev/null
+++ b/index-test.php
@@ -0,0 +1,27 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | Roundcube Webmail Selenium Tests Entry Point |
+ | |
+ | Copyright (C) 2005-2014, The Roundcube Dev Team |
+ | |
+ | Licensed under the GNU General Public License version 3 or |
+ | any later version with exceptions for skins & plugins. |
+ | See the README file for a full license statement. |
+ | |
+ | PURPOSE: |
+ | This is the public entry point for all HTTP requests to the |
+ | Roundcube webmail application loading the 'tests' environment. |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <thomas@roundcube.net> |
+ +-----------------------------------------------------------------------+
+*/
+
+define('INSTALL_PATH', realpath(__DIR__) . '/');
+
+$GLOBALS['env'] = 'test';
+
+// include index.php from application root directory
+include INSTALL_PATH . 'index.php';
+
diff --git a/tests/Selenium/Login.php b/tests/Selenium/Login.php
index a3f0ab6b4..65b082851 100644
--- a/tests/Selenium/Login.php
+++ b/tests/Selenium/Login.php
@@ -1,21 +1,27 @@
<?php
class Selenium_Login extends Selenium_Test
{
+ protected function setUp()
+ {
+ bootstrap::init_db();
+ parent::setUp();
+ }
+
public function testLogin()
{
// first test, we're already on the login page
$this->url(TESTS_URL);
// task should be set to 'login'
$env = $this->get_env();
$this->assertEquals('login', $env['task']);
// test valid login
$this->login();
// task should be set to 'mail' now
$env = $this->get_env();
$this->assertEquals('mail', $env['task']);
}
}
diff --git a/tests/Selenium/README.md b/tests/Selenium/README.md
new file mode 100644
index 000000000..5610fae71
--- /dev/null
+++ b/tests/Selenium/README.md
@@ -0,0 +1,49 @@
+Running Selenium Tests
+======================
+
+In order to run the Selenium-based web tests, some configuration for the
+Roundcube test instance need to be created. Along with the default config for a
+given Roundcube instance, you should provide a config specifically for running
+tests. To do so, create a config file named `config-test.inc.php` in the
+regular Roundcube config dir. That should provide specific `db_dsnw` and
+`default_host` values for testing purposes as well as the credentials of a
+valid IMAP user account used for running the tests with.
+
+Add these config options used by the Selenium tests:
+
+```php
+ // Unit tests settings
+ $config['tests_username'] = 'roundcube.test@example.org';
+ $config['tests_password'] = '<test-account-password>';
+ $config['tests_url'] = 'http://localhost/roundcube/index-test.php';
+```
+
+The `tests_url` should point to Roundcube's index-test.php file accessible by
+the Selenium web browser.
+
+WARNING
+-------
+Please note that the configured IMAP account as well as the Roundcube database
+configred in `db_dsnw` will be wiped and filled with test data in every test
+run. Under no circumstances you should use credentials of a production database
+or email account!
+
+
+Run the tests
+-------------
+
+First you need to start a Selenium server. We recommend to use the
+[Selenium Standalone Server][selenium-server] but the tests will also run on a
+Selenium Grid. The tests are based in [PHPUnit_Selenium][phpunit] which can be
+installed through [PEAR][pear-phpunit].
+
+To start the test suite call `phpunit` from the Selenium directory:
+
+```
+ cd <roundcube-dir>/tests/Selenium
+ phpunit
+```
+
+[phpunit]: http://phpunit.de/manual/4.0/en/selenium.html
+[pear-phpunit]: http://pear.phpunit.de/
+[selenium-server]: http://docs.seleniumhq.org/download/
diff --git a/tests/Selenium/bootstrap.php b/tests/Selenium/bootstrap.php
index e8b186a1e..ed9c2eb32 100644
--- a/tests/Selenium/bootstrap.php
+++ b/tests/Selenium/bootstrap.php
@@ -1,185 +1,234 @@
<?php
/*
+-----------------------------------------------------------------------+
| tests/Selenium/bootstrap.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2009-2013, The Roundcube Dev Team |
+ | Copyright (C) 2009-2014, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Environment initialization script for unit tests |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
if (php_sapi_name() != 'cli')
die("Not in shell mode (php-cli)");
if (!defined('INSTALL_PATH')) define('INSTALL_PATH', realpath(dirname(__FILE__) . '/../../') . '/' );
define('TESTS_DIR', dirname(__FILE__) . '/');
if (@is_dir(TESTS_DIR . 'config')) {
define('RCUBE_CONFIG_DIR', TESTS_DIR . 'config');
}
require_once(INSTALL_PATH . 'program/include/iniset.php');
// Extend include path so some plugin test won't fail
$include_path = ini_get('include_path') . PATH_SEPARATOR . TESTS_DIR . '..';
if (set_include_path($include_path) === false) {
die("Fatal error: ini_set/set_include_path does not work.");
}
-$rcmail = rcube::get_instance('test');
+$rcmail = rcmail::get_instance('test');
define('TESTS_URL', $rcmail->config->get('tests_url'));
define('TESTS_BROWSER', $rcmail->config->get('tests_browser', 'firefox'));
define('TESTS_USER', $rcmail->config->get('tests_username'));
define('TESTS_PASS', $rcmail->config->get('tests_password'));
define('TESTS_SLEEP', $rcmail->config->get('tests_sleep', 5));
PHPUnit_Extensions_Selenium2TestCase::shareSession(true);
-// @TODO: remove user record from DB before running tests
+
+/**
+ * satisfy PHPUnit
+ */
+class bootstrap
+{
+ /**
+ * Wipe and re-initialize (mysql) database
+ */
+ public static function init_db()
+ {
+ $rcmail = rcmail::get_instance();
+
+ // drop all existing tables first
+ $db = $rcmail->get_dbh();
+ $db->query("SET FOREIGN_KEY_CHECKS=0");
+ $sql_res = $db->query("SHOW TABLES");
+ while ($sql_arr = $db->fetch_array($sql_res)) {
+ $table = reset($sql_arr);
+ $db->query("DROP TABLE $table");
+ }
+
+ // init database with schema
+ $dsn = parse_url($rcmail->config->get('db_dsnw'));
+ $db_name = trim($dsn['path'], '/');
+
+ if ($dsn['scheme'] == 'mysql' || $dsn['scheme'] == 'mysqli') {
+ system(sprintf('cat %s %s | mysql -h %s -u %s --password=%s %s',
+ realpath(INSTALL_PATH . '/SQL/mysql.initial.sql'),
+ realpath(TESTS_DIR . '/Selenium/data/mysql.sql'),
+ escapeshellarg($dsn['host']),
+ escapeshellarg($dsn['user']),
+ escapeshellarg($dsn['pass']),
+ escapeshellarg($db_name)
+ ));
+ }
+ }
+
+ /**
+ * Wipe the configured IMAP account and fill with test data
+ */
+ public static function init_imap()
+ {
+ if (!TESTS_USER)
+ return false;
+
+ // TBD.
+ }
+}
+
// @TODO: make sure mailbox has some content (always the same) or is empty
// @TODO: plugins: enable all?
/**
* Base class for all tests in this directory
*/
class Selenium_Test extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
-// $this->rc = rcube::get_instance();
$this->setBrowser(TESTS_BROWSER);
// Set root to our index.html, for better performance
// See https://github.com/sebastianbergmann/phpunit-selenium/issues/217
- $this->setBrowserUrl(TESTS_URL . '/tests/Selenium');
+ $baseurl = preg_replace('!/index(-.+)?\.php^!', '', TESTS_URL);
+ $this->setBrowserUrl($baseurl . '/tests/Selenium');
}
protected function login()
{
$this->go('mail');
$user_input = $this->byCssSelector('form input[name="_user"]');
$pass_input = $this->byCssSelector('form input[name="_pass"]');
$submit = $this->byCssSelector('form input[type="submit"]');
$user_input->value(TESTS_USER);
$pass_input->value(TESTS_PASS);
// submit login form
$submit->click();
// wait after successful login
sleep(TESTS_SLEEP);
}
protected function go($task = 'mail', $action = null)
{
- $this->url(TESTS_URL . '/?_task=' . $task);
+ $this->url(TESTS_URL . '?_task=' . $task);
// wait for interface load (initial ajax requests, etc.)
sleep(TESTS_SLEEP);
if ($action) {
$this->click_button($action);
sleep(TESTS_SLEEP);
}
}
protected function get_env()
{
return $this->execute(array(
'script' => 'return rcmail.env;',
'args' => array(),
));
}
protected function get_buttons($action)
{
$buttons = $this->execute(array(
'script' => "return rcmail.buttons['$action'];",
'args' => array(),
));
if (is_array($buttons)) {
foreach ($buttons as $idx => $button) {
$buttons[$idx] = $button['id'];
}
}
return (array) $buttons;
}
protected function get_objects()
{
return $this->execute(array(
'script' => "var i,r = []; for (i in rcmail.gui_objects) r.push(i); return r;",
'args' => array(),
));
}
protected function click_button($action)
{
$buttons = $this->get_buttons($action);
$id = array_shift($buttons);
// this doesn't work for me
$this->byId($id)->click();
}
protected function ajaxResponse($action, $script = '', $button = false)
{
if (!$script && !$button) {
$script = "rcmail.command('$action')";
}
$script =
"if (!window.test_ajax_response) {
window.test_ajax_response_object = {};
function test_ajax_response(response)
{
if (response.response && response.response.action) {
window.test_ajax_response_object[response.response.action] = response.response;
}
}
rcmail.addEventListener('responsebefore', test_ajax_response);
}
window.test_ajax_response_object['$action'] = null;
$script;
";
// run request
$this->execute(array(
'script' => $script,
'args' => array(),
));
if ($button) {
$this->click_button($action);
}
// wait
sleep(TESTS_SLEEP);
// get response
$response = $this->execute(array(
'script' => "return window.test_ajax_response_object['$action'];",
'args' => array(),
));
return $response;
}
}
diff --git a/tests/Selenium/data/mysql.sql b/tests/Selenium/data/mysql.sql
new file mode 100644
index 000000000..fe6741a02
--- /dev/null
+++ b/tests/Selenium/data/mysql.sql
@@ -0,0 +1 @@
+-- empty
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 1:43 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18821990
Default Alt Text
(12 KB)
Attached To
Mode
R113 roundcubemail
Attached
Detach File
Event Timeline