Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2571377
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
15 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tests/Selenium/Login.php b/tests/Selenium/Login.php
index 65b082851..6910b43e6 100644
--- a/tests/Selenium/Login.php
+++ b/tests/Selenium/Login.php
@@ -1,27 +1,28 @@
<?php
class Selenium_Login extends Selenium_Test
{
protected function setUp()
{
bootstrap::init_db();
+ bootstrap::init_imap();
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/Mail/List.php b/tests/Selenium/Mail/List.php
index 7574c1801..9c1d4a8d8 100644
--- a/tests/Selenium/Mail/List.php
+++ b/tests/Selenium/Mail/List.php
@@ -1,25 +1,37 @@
<?php
class Selenium_Mail_List extends Selenium_Test
{
- public function testCheckRecent()
+ public function testList()
{
$this->go('mail');
$res = $this->ajaxResponse('list', "rcmail.command('list')");
$this->assertEquals('list', $res['action']);
$this->assertRegExp('/this\.set_pagetitle/', $res['exec']);
$this->assertRegExp('/this\.set_unread_count/', $res['exec']);
$this->assertRegExp('/this\.set_rowcount/', $res['exec']);
$this->assertRegExp('/this\.set_message_coltypes/', $res['exec']);
-// $this->assertRegExp('/this\.add_message_row/', $res['exec']);
$this->assertContains('current_page', $res['env']);
$this->assertContains('exists', $res['env']);
$this->assertContains('pagecount', $res['env']);
$this->assertContains('pagesize', $res['env']);
$this->assertContains('messagecount', $res['env']);
$this->assertContains('mailbox', $res['env']);
+
+ $this->assertEquals($res['env']['mailbox'], 'INBOX');
+ $this->assertEquals($res['env']['messagecount'], 1);
+
+ // check message list
+ $row = $this->byCssSelector('.messagelist tbody tr:first-child');
+ $this->assertHasClass('unread', $row);
+
+ $subject = $this->byCssSelector('.messagelist tbody tr:first-child td.subject');
+ $this->assertEquals('Lines', $subject->text());
+
+ $icon = $this->byCssSelector('.messagelist tbody tr:first-child td.status span');
+ $this->assertHasClass('unread', $icon);
}
}
diff --git a/tests/Selenium/Settings/About.php b/tests/Selenium/Settings/About.php
index 9a6c31d4b..4cd49431a 100644
--- a/tests/Selenium/Settings/About.php
+++ b/tests/Selenium/Settings/About.php
@@ -1,14 +1,15 @@
<?php
class Selenium_Settings_About extends Selenium_Test
{
public function testAbout()
{
- $this->url(TESTS_URL . '/?_task=settings&_action=about');
+ $this->url(TESTS_URL . '?_task=settings&_action=about');
+ sleep(TESTS_SLEEP);
// check task and action
$env = $this->get_env();
$this->assertEquals('settings', $env['task']);
$this->assertEquals('about', $env['action']);
}
}
diff --git a/tests/Selenium/bootstrap.php b/tests/Selenium/bootstrap.php
index 124a81ef2..fe2d11156 100644
--- a/tests/Selenium/bootstrap.php
+++ b/tests/Selenium/bootstrap.php
@@ -1,234 +1,283 @@
<?php
/*
+-----------------------------------------------------------------------+
| tests/Selenium/bootstrap.php |
| |
| This file is part of the Roundcube Webmail client |
| 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(__DIR__ . '/../../') . '/' );
-define('TESTS_DIR', __DIR__ . '/');
+define('TESTS_DIR', realpath(__DIR__ . '/../') . '/');
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 = 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);
/**
* 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'),
+ 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.
+ $rcmail = rcmail::get_instance();
+ $imap = $rcmail->get_storage();
+
+ $imap_host = $rcmail->config->get('default_host');
+ $a_host = parse_url($args['host']);
+ if ($a_host['host']) {
+ $imap_host = $a_host['host'];
+ $imap_ssl = isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'));
+ $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143);
+ }
+ else {
+ $imap_port = 143;
+ $imap_ssl = false;
+ }
+
+ if (!$imap->connect($imap_host, TESTS_USER, TESTS_PASS, $imap_port, $imap_ssl)) {
+ die("IMAP error: unable to authenticate with user " . TESTS_USER);
+ }
+
+ // create Archive mailbox
+ $folders = $imap->list_folders();
+ if (!in_array('Archive', $folders)) {
+ $imap->create_folder('Archive', true);
+ }
+ else {
+ $imap->delete_message('*', 'Archive');
+ }
+
+ // empty Inbox
+ $imap->delete_message('*', 'INBOX');
+
+ // import email messages
+ foreach (glob(TESTS_DIR . 'Selenium/data/mail/*.eml') as $f) {
+ $imap->save_message('INBOX', file_get_contents($f));
+ }
+
+ $imap->close();
}
}
// @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->setBrowser(TESTS_BROWSER);
// 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()
{
- $this->go('mail');
+ $this->go('mail', null, true);
+ }
+ protected function do_login()
+ {
$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)
+ protected function go($task = 'mail', $action = null, $login = true)
{
$this->url(TESTS_URL . '?_task=' . $task);
// wait for interface load (initial ajax requests, etc.)
sleep(TESTS_SLEEP);
+ // check if we have a valid session
+ $env = $this->get_env();
+ if ($login && $env['task'] == 'login') {
+ $this->do_login();
+ }
+
if ($action) {
$this->click_button($action);
-
sleep(TESTS_SLEEP);
}
}
protected function get_env()
{
return $this->execute(array(
- 'script' => 'return rcmail.env;',
+ 'script' => 'return window.rcmail ? 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'];",
+ 'script' => "return window.test_ajax_response_object ? test_ajax_response_object['$action'] : {};",
'args' => array(),
));
return $response;
}
+
+ protected function assertHasClass($classname, $element)
+ {
+ $this->assertContains($classname, $element->attribute('class'));
+ }
}
diff --git a/tests/Selenium/data/mail/lines.eml b/tests/Selenium/data/mail/lines.eml
new file mode 100644
index 000000000..e5977d4fc
--- /dev/null
+++ b/tests/Selenium/data/mail/lines.eml
@@ -0,0 +1,45 @@
+Return-Path: <thomas@roundcube.net>
+X-Original-To: tb@tester.local
+To: Tom Tester <tb@tester.local>
+Subject: Lines
+X-PHP-Originating-Script: 501:rcmail.php
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+ boundary="=_8853bfb47b7da1852ac882e69cc724f3"
+Date: Fri, 23 May 2014 19:44:50 +0200
+From: "Thomas B." <thomas@roundcube.net>
+Reply-To: hello@roundcube.net
+Mail-Reply-To: hello@roundcube.net
+Message-ID: <99839b8ec12482419372f1edafa9de75@woodcrest.local>
+X-Sender: thomas@roundcube.net
+User-Agent: Roundcube Webmail/1.0.1
+
+--=_8853bfb47b7da1852ac882e69cc724f3
+Content-Transfer-Encoding: 7bit
+Content-Type: text/plain; charset=UTF-8;
+ format=flowed
+
+Plain text message body.
+
+--
+Developer of Free Software
+Sent with Roundcube Webmail - roundcube.net
+--=_8853bfb47b7da1852ac882e69cc724f3
+Content-Transfer-Encoding: base64
+Content-Type: text/plain;
+ name=lines.txt
+Content-Disposition: attachment;
+ filename=lines.txt;
+ size=13
+
+Zm9vDQpiYXINCmduYQ==
+--=_8853bfb47b7da1852ac882e69cc724f3
+Content-Transfer-Encoding: base64
+Content-Type: text/plain;
+ name=lines_lf.txt
+Content-Disposition: attachment;
+ filename=lines_lf.txt;
+ size=11
+
+Zm9vCmJhcgpnbmE=
+--=_8853bfb47b7da1852ac882e69cc724f3--
diff --git a/tests/Selenium/phpunit.xml b/tests/Selenium/phpunit.xml
index b5835cf74..fe0c7016c 100644
--- a/tests/Selenium/phpunit.xml
+++ b/tests/Selenium/phpunit.xml
@@ -1,21 +1,29 @@
<phpunit backupGlobals="false"
bootstrap="bootstrap.php"
colors="true">
<testsuites>
- <testsuite name="All Tests">
+ <testsuite name="Mail">
<file>Login.php</file><!-- Login.php test must be first -->
- <file>Addressbook/Addressbook.php</file>
- <file>Addressbook/Import.php</file>
<file>Mail/Mail.php</file>
<file>Mail/CheckRecent.php</file>
<file>Mail/Compose.php</file>
<file>Mail/Getunread.php</file>
<file>Mail/List.php</file>
+ <file>Logout.php</file><!-- Logout.php test must be last -->
+ </testsuite>
+ <testsuite name="Addressbook">
+ <file>Login.php</file>
+ <file>Addressbook/Addressbook.php</file>
+ <file>Addressbook/Import.php</file>
+ <file>Logout.php</file>
+ </testsuite>
+ <testsuite name="Settings">
+ <file>Login.php</file>
<file>Settings/About.php</file>
<file>Settings/Folders.php</file>
<file>Settings/Identities.php</file>
<file>Settings/Settings.php</file>
- <file>Logout.php</file><!-- Logout.php test must be last -->
+ <file>Logout.php</file>
</testsuite>
</testsuites>
</phpunit>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Mar 18, 5:58 PM (2 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
458396
Default Alt Text
(15 KB)
Attached To
Mode
R3 roundcubemail
Attached
Detach File
Event Timeline
Log In to Comment