From 3412e50b54e3daac8745234e21ab6e72be0ed165 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 04 Jun 2014 11:20:33 -0400
Subject: [PATCH] Fix attachment menu structure and aria-attributes

---
 tests/Selenium/bootstrap.php |   67 ++++++++++++++++++++++++++++++---
 1 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/tests/Selenium/bootstrap.php b/tests/Selenium/bootstrap.php
index 0f7eed0..ed9c2eb 100644
--- a/tests/Selenium/bootstrap.php
+++ b/tests/Selenium/bootstrap.php
@@ -5,7 +5,7 @@
  | 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.                |
@@ -27,7 +27,7 @@
 define('TESTS_DIR', dirname(__FILE__) . '/');
 
 if (@is_dir(TESTS_DIR . 'config')) {
-    define('RCMAIL_CONFIG_DIR', TESTS_DIR . 'config');
+    define('RCUBE_CONFIG_DIR', TESTS_DIR . 'config');
 }
 
 require_once(INSTALL_PATH . 'program/include/iniset.php');
@@ -38,7 +38,7 @@
     die("Fatal error: ini_set/set_include_path does not work.");
 }
 
-$rcmail = rcube::get_instance();
+$rcmail = rcmail::get_instance('test');
 
 define('TESTS_URL',     $rcmail->config->get('tests_url'));
 define('TESTS_BROWSER', $rcmail->config->get('tests_browser', 'firefox'));
@@ -48,8 +48,58 @@
 
 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
@@ -58,9 +108,12 @@
 {
     protected function setUp()
     {
-//        $this->rc = rcube::get_instance();
         $this->setBrowser(TESTS_BROWSER);
-        $this->setBrowserUrl(TESTS_URL);
+
+        // Set root to our index.html, for better performance
+        // See https://github.com/sebastianbergmann/phpunit-selenium/issues/217
+        $baseurl = preg_replace('!/index(-.+)?\.php^!', '', TESTS_URL);
+        $this->setBrowserUrl($baseurl . '/tests/Selenium');
     }
 
     protected function login()
@@ -83,7 +136,7 @@
 
     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);

--
Gitblit v1.9.1