Add more in-browser tests

pull/7135/head
Aleksander Machniak 5 years ago
parent 7abd4f2c15
commit 59e1efb595

@ -14,6 +14,7 @@ $config['smtp_port'] = 25;
// Settings required by the tests // Settings required by the tests
$config['create_default_folders'] = true;
$config['skin'] = 'elastic'; $config['skin'] = 'elastic';
$config['support_url'] = 'http://support.url'; $config['support_url'] = 'http://support.url';

@ -4,6 +4,16 @@ namespace Tests\Browser\Addressbook;
class Addressbook extends \Tests\Browser\DuskTestCase class Addressbook extends \Tests\Browser\DuskTestCase
{ {
protected function setUp()
{
parent::setUp();
\bootstrap::init_db();
}
/**
* Contacts UI Basics
*/
public function testAddressbook() public function testAddressbook()
{ {
$this->browse(function ($browser) { $this->browse(function ($browser) {
@ -19,6 +29,43 @@ class Addressbook extends \Tests\Browser\DuskTestCase
$this->assertContains('folderlist', $objects); $this->assertContains('folderlist', $objects);
$this->assertContains('contactslist', $objects); $this->assertContains('contactslist', $objects);
$this->assertContains('countdisplay', $objects); $this->assertContains('countdisplay', $objects);
$browser->assertSeeIn('#layout-sidebar .header', 'Groups');
// Groups/Addressbooks list
$browser->assertVisible('#directorylist');
$browser->assertSeeIn('#directorylist li:first-child', 'Personal Addresses');
$browser->assertMissing('#directorylist .treetoggle.expanded');
// Contacts list
$browser->assertVisible('#contacts-table');
// Contacts list menu
$browser->assertVisible('#toolbar-list-menu a.select:not(.disabled)');
// Toolbar menu
$browser->with('#toolbar-menu', function($browser) {
$browser->assertVisible('a.create:not(.disabled)');
$browser->assertVisible('a.print.disabled');
$browser->assertVisible('a.delete.disabled');
$browser->assertVisible('a.search:not(.disabled)');
$browser->assertVisible('a.import:not(.disabled)');
$browser->assertVisible('a.export:not(.disabled)');
$browser->assertVisible('a.more.disabled');
});
// Contact frame
$browser->assertVisible('#contact-frame');
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled):not(.selected)');
$browser->assertVisible('a.mail:not(.disabled):not(.selected)');
$browser->assertVisible('a.contacts.selected');
$browser->assertVisible('a.settings:not(.disabled):not(.selected)');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
}); });
} }
} }

@ -4,31 +4,100 @@ namespace Tests\Browser\Addressbook;
class Import extends \Tests\Browser\DuskTestCase class Import extends \Tests\Browser\DuskTestCase
{ {
public function testImport() /**
* Test basic elements of contacts import UI
*/
public function testImportUI()
{ {
$this->browse(function ($browser) { $this->browse(function ($browser) {
$this->go('addressbook', 'import'); $this->go('addressbook');
// check task and action $browser->click('#toolbar-menu a.import');
$this->assertEnvEquals('task', 'addressbook');
$this->assertEnvEquals('action', 'import');
$objects = $this->getObjects(); $browser->assertSeeIn('.ui-dialog-title', 'Import contacts');
$browser->assertVisible('.ui-dialog button.mainaction.import');
$browser->assertVisible('.ui-dialog button.cancel');
// these objects should be there always $browser->withinFrame('.ui-dialog iframe', function ($browser) {
$this->assertContains('importform', $objects); // check task and action
$this->assertEnvEquals('task', 'addressbook');
$this->assertEnvEquals('action', 'import');
$objects = $this->getObjects();
// these objects should be there always
$this->assertContains('importform', $objects);
$browser->assertSee('You can upload');
$browser->assertVisible('#rcmImportForm');
$browser->assertVisible('#rcmImportForm select');
$browser->assertVisible('#rcmImportForm .custom-switch');
// FIXME: selecting the file input directly does not work
$browser->assertVisible('#rcmImportForm .custom-file');
$browser->assertSelected('#rcmImportForm select', 0);
});
// Close the dialog
$browser->click('.ui-dialog button.cancel');
$browser->assertMissing('.ui-dialog');
}); });
} }
public function testImport2() /**
* Import contacts from a vCard file
*
* @depends testImportUI
*/
public function testImportProcess()
{ {
$this->browse(function ($browser) { $this->browse(function ($browser) {
$this->go('addressbook', 'import'); // Open the dialog again
$browser->click('#toolbar-menu a.import');
$browser->assertSeeIn('.ui-dialog-title', 'Import contacts');
// Submit the form with no file attached
$browser->click('.ui-dialog button.mainaction');
$browser->waitForText('Attention');
$browser->assertSee('Please select a file');
$browser->driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ESCAPE);
$this->assertCount(1, $browser->elements('.ui-dialog'));
$browser->withinFrame('.ui-dialog iframe', function ($browser) {
$browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf');
});
$browser->click('.ui-dialog button.mainaction');
$objects = $this->getObjects(); $browser->withinFrame('.ui-dialog iframe', function ($browser) {
$browser->waitForText('Successfully imported 2 contacts:');
});
// Close the dialog
$browser->click('.ui-dialog button.cancel');
// Expected existing contacts + imported
$browser->waitFor('#contacts-table tr');
$this->assertCount(4, $browser->elements('#contacts-table tbody tr'));
$browser->assertSeeIn('#rcmcountdisplay', '1 4 of 4');
});
}
/**
* Test imported contact
*
* @depends testImportProcess
*/
public function testImportResult()
{
$this->browse(function ($browser) {
// Open the dialog again
$browser->click('#contacts-table tr:last-child');
// these objects should be there always $browser->withinFrame('#contact-frame', function ($browser) {
$this->assertContains('importform', $objects); $browser->waitFor('a.email'); // wait for iframe to load
$browser->assertSeeIn('.names', 'Sylvester Stalone');
$browser->assertSeeIn('a.email', 's.stalone@rambo.tv');
});
}); });
} }
} }

@ -116,6 +116,21 @@ abstract class DuskTestCase extends TestCase
$this->assertEquals($expected, $this->getEnv($key)); $this->assertEquals($expected, $this->getEnv($key));
} }
/**
* Assert specified checkbox state
*/
protected function assertCheckboxState($selector, $state)
{
$this->browse(function (Browser $browser) use ($selector, $state) {
if ($state) {
$browser->assertChecked($selector);
}
else {
$browser->assertNotChecked($selector);
}
});
}
/** /**
* Get content of rcmail.env entry * Get content of rcmail.env entry
*/ */
@ -192,15 +207,52 @@ abstract class DuskTestCase extends TestCase
}); });
} }
/**
* Change state of the Elastic's pretty checkbox
*/
protected function setCheckboxState($selector, $state)
{
// Because you can't operate on the original checkbox directly
$this->browse(function (Browser $browser) use ($selector, $state) {
$browser->ensurejQueryIsAvailable();
if ($state) {
$run = "if (!element.prev().is(':checked')) element.click()";
}
else {
$run = "if (element.prev().is(':checked')) element.click()";
}
$browser->script(
"var element = jQuery('$selector')[0] || jQuery('input[name=$selector]')[0];"
."element = jQuery(element).next('.custom-control-label'); $run;"
);
});
}
/**
* Wait for UI (notice/confirmation/loading/error/warning) message
* and assert it's text
*/
protected function waitForMessage($type, $text)
{
$selector = '#messagestack > div.' . $type;
$this->browse(function ($browser) use ($selector, $text) {
$browser->waitFor($selector)->assertSeeIn($selector, $text);
});
}
/** /**
* Starts PHP server. * Starts PHP server.
*/ */
protected static function startWebServer() protected static function startWebServer()
{ {
$path = realpath(__DIR__ . '/../../public_html'); $path = realpath(__DIR__ . '/../../public_html');
$cmd = ['php', '-S', 'localhost:8000']; $cmd = ['php', '-S', 'localhost:8000'];
$env = [];
static::$phpProcess = new Process($cmd, null, []); static::$phpProcess = new Process($cmd, null, $env);
static::$phpProcess->setWorkingDirectory($path); static::$phpProcess->setWorkingDirectory($path);
static::$phpProcess->start(); static::$phpProcess->start();

@ -1,15 +0,0 @@
<?php
namespace Tests\Browser\Mail;
class CheckRecent extends \Tests\Browser\DuskTestCase
{
public function testCheckRecent()
{
$this->browse(function ($browser) {
$this->go('mail');
// TODO
});
}
}

@ -7,7 +7,9 @@ class Compose extends \Tests\Browser\DuskTestCase
public function testCompose() public function testCompose()
{ {
$this->browse(function ($browser) { $this->browse(function ($browser) {
$this->go('mail', 'compose'); $this->go('mail');
$browser->click('#taskmenu a.compose');
// check task and action // check task and action
$this->assertEnvEquals('task', 'mail'); $this->assertEnvEquals('task', 'mail');
@ -23,6 +25,36 @@ class Compose extends \Tests\Browser\DuskTestCase
$this->assertContains('attachmentlist', $objects); $this->assertContains('attachmentlist', $objects);
$this->assertContains('filedrop', $objects); $this->assertContains('filedrop', $objects);
$this->assertContains('uploadform', $objects); $this->assertContains('uploadform', $objects);
// Toolbar menu
$browser->with('#toolbar-menu', function($browser) {
$browser->assertVisible('a.save.draft:not(.disabled)');
$browser->assertVisible('a.attach:not(.disabled)');
$browser->assertVisible('a.signature.disabled');
$browser->assertVisible('a.responses:not(.disabled)');
$browser->assertVisible('a.spellcheck:not(.disabled)');
});
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled).selected');
$browser->assertVisible('a.mail:not(.disabled):not(.selected)');
$browser->assertVisible('a.contacts:not(.disabled):not(.selected)');
$browser->assertVisible('a.settings:not(.disabled):not(.selected)');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
// Header inputs
$browser->assertSeeIn('#layout-sidebar .header', 'Options and attachments');
$browser->assertVisible('#compose-attachments');
$browser->assertVisible('#_from');
$browser->assertVisible('#compose-subject');
$browser->assertInputValue('#compose-subject', '');
// Mail body input
$browser->assertVisible('#composebodycontainer.html-editor');
$browser->assertVisible('#composebodycontainer > textarea');
}); });
} }
} }

@ -29,7 +29,49 @@ class MailList extends \Tests\Browser\DuskTestCase
$this->assertEquals('Lines', $browser->text('#messagelist tbody tr:first-child span.subject')); $this->assertEquals('Lines', $browser->text('#messagelist tbody tr:first-child span.subject'));
//$browser->assertVisible('#messagelist tbody tr:first-child span.msgicon.unread'); // Note: This element icon has width=0, use assertPresent() not assertVisible()
$browser->assertPresent('#messagelist tbody tr:first-child span.msgicon.unread');
// List toolbar menu
$browser->assertVisible('#toolbar-list-menu a.select:not(.disabled)');
$browser->assertVisible('#toolbar-list-menu a.options:not(.disabled)');
$browser->assertVisible('a.toolbar-button.refresh:not(.disabled)');
$imap = \bootstrap::get_storage();
if ($imap->get_threading()) {
$browser->assertVisible('#toolbar-list-menu a.threads:not(.disabled)');
}
else {
$browser->assertMissing('#toolbar-list-menu a.threads');
}
});
}
/**
* @depends testList
*/
public function testListSelection()
{
$this->browse(function ($browser) {
$browser->click('#toolbar-list-menu a.select');
$browser->assertFocused('#toolbar-list-menu a.select');
// Popup menu content
$browser->with('#listselect-menu', function($browser) {
$browser->assertVisible('a.selection:not(.disabled)');
$browser->assertVisible('a.select.all:not(.disabled)');
$browser->assertVisible('a.select.page:not(.disabled)');
$browser->assertVisible('a.select.unread:not(.disabled)');
$browser->assertVisible('a.select.flagged:not(.disabled)');
$browser->assertVisible('a.select.invert:not(.disabled)');
$browser->assertVisible('a.select.none:not(.disabled)');
});
// Close the menu by clicking the page body
$browser->click();
$browser->waitUntilMissing('#listselect-menu');
// TODO: Test selection actions
}); });
} }
} }

@ -4,7 +4,7 @@ namespace Tests\Browser\Mail;
class Mail extends \Tests\Browser\DuskTestCase class Mail extends \Tests\Browser\DuskTestCase
{ {
public function testMail() public function testMailUI()
{ {
$this->browse(function ($browser) { $this->browse(function ($browser) {
$this->go('mail'); $this->go('mail');
@ -21,6 +21,35 @@ class Mail extends \Tests\Browser\DuskTestCase
$this->assertContains('quotadisplay', $objects); $this->assertContains('quotadisplay', $objects);
$this->assertContains('search_filter', $objects); $this->assertContains('search_filter', $objects);
$this->assertContains('countdisplay', $objects); $this->assertContains('countdisplay', $objects);
$browser->assertSeeIn('#layout-sidebar .header', TESTS_USER);
// Folders list
$browser->assertVisible('#mailboxlist li.mailbox.inbox.selected');
// Mail preview frame
$browser->assertVisible('#messagecontframe');
// Toolbar menu
$browser->with('#toolbar-menu', function($browser) {
$browser->assertMissing('a.compose'); // this is always hidden button
$browser->assertVisible('a.reply.disabled');
$browser->assertVisible('a.reply-all.disabled');
$browser->assertVisible('a.forward.disabled');
$browser->assertVisible('a.delete.disabled');
$browser->assertVisible('a.markmessage.disabled');
$browser->assertVisible('a.more:not(.disabled)');
});
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled):not(.selected)');
$browser->assertVisible('a.mail.selected');
$browser->assertVisible('a.contacts:not(.disabled):not(.selected)');
$browser->assertVisible('a.settings:not(.disabled):not(.selected)');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
}); });
} }
} }

@ -16,14 +16,15 @@ class Preferences extends \Tests\Browser\DuskTestCase
$browser->assertVisible('#settings-menu li.preferences.selected'); $browser->assertVisible('#settings-menu li.preferences.selected');
// Preferences actions // Preferences actions
$browser->assertVisible('#sections-table'); $browser->with('#sections-table', function($browser) {
$browser->assertSeeIn('#sections-table tr.general', 'User Interface'); $browser->assertSeeIn('tr.general', 'User Interface');
$browser->assertSeeIn('#sections-table tr.mailbox', 'Mailbox View'); $browser->assertSeeIn('tr.mailbox', 'Mailbox View');
$browser->assertSeeIn('#sections-table tr.mailview', 'Displaying Messages'); $browser->assertSeeIn('tr.mailview', 'Displaying Messages');
$browser->assertSeeIn('#sections-table tr.compose', 'Composing Messages'); $browser->assertSeeIn('tr.compose', 'Composing Messages');
$browser->assertSeeIn('#sections-table tr.addressbook', 'Contacts'); $browser->assertSeeIn('tr.addressbook', 'Contacts');
$browser->assertSeeIn('#sections-table tr.folders', 'Special Folders'); $browser->assertSeeIn('tr.folders', 'Special Folders');
$browser->assertSeeIn('#sections-table tr.server', 'Server Settings'); $browser->assertSeeIn('tr.server', 'Server Settings');
});
}); });
} }
} }

@ -0,0 +1,144 @@
<?php
namespace Tests\Browser\Settings\Preferences;
class General extends \Tests\Browser\DuskTestCase
{
protected function tearDown()
{
parent::tearDown();
// Reset user preferences back to defaults
$db = $this->app->get_dbh();
$db->query("UPDATE users SET preferences = '' WHERE username = ?", TESTS_USER);
}
public function testGeneral()
{
$this->browse(function ($browser) {
$this->go('settings');
$browser->click('#sections-table tr.general');
$browser->assertVisible('#sections-table tr.general.focused');
$browser->withinFrame('#preferences-frame', function ($browser) {
// check task and action
$this->assertEnvEquals('task', 'settings');
$this->assertEnvEquals('action', 'edit-prefs');
$browser->assertVisible('.formbuttons button.submit');
// Main Options fieldset
$browser->with('form.propform fieldset.main', function ($browser) {
$browser->assertSeeIn('legend', 'Main Options');
$browser->assertSeeIn('label[for=rcmfd_lang]', 'Language');
$browser->assertVisible('select[name=_language]');
$browser->assertSelected('select[name=_language]', 'en_US');
$browser->assertSeeIn('label[for=rcmfd_timezone]', 'Time zone');
$browser->assertVisible('select[name=_timezone]');
// we don't know what timezone has been autodetected
// $browser->assertSelected('select[name=_timezone]', 'auto');
$browser->assertSeeIn('label[for=rcmfd_time_format]', 'Time format');
$browser->assertVisible('select[name=_time_format]');
$browser->assertSelected('select[name=_time_format]', $this->app->config->get('time_format'));
$browser->assertSeeIn('label[for=rcmfd_date_format]', 'Date format');
$browser->assertVisible('select[name=_date_format]');
$browser->assertSelected('select[name=_date_format]', $this->app->config->get('date_format'));
$browser->assertSeeIn('label[for=rcmfd_prettydate]', 'Pretty dates');
$this->assertCheckboxState('_pretty_date', $this->app->config->get('prettydate'));
$browser->assertSeeIn('label[for=rcmfd_displaynext]', 'Display next');
$this->assertCheckboxState('_display_next', $this->app->config->get('display_next'));
$browser->assertSeeIn('label[for=rcmfd_refresh_interval]', 'Refresh');
$browser->assertVisible('select[name=_refresh_interval]');
$browser->assertSelected('select[name=_refresh_interval]', $this->app->config->get('refresh_interval')/60);
});
// Interface Skin fieldset
$browser->with('form.propform fieldset.skin', function ($browser) {
$browser->assertSeeIn('legend', 'Interface skin');
// TODO
});
// Browser Options fieldset
$browser->with('form.propform fieldset.browser', function ($browser) {
$browser->assertSeeIn('legend', 'Browser Options');
$browser->assertSeeIn('label[for=rcmfd_standard_windows]', 'Handle popups');
$this->assertCheckboxState('_standard_windows', $this->app->config->get('standard_windows'));
});
});
});
}
/**
* Test (all) User Interface preferences change
*
* @depends testGeneral
*/
public function testPreferencesChange()
{
// Values we're changing to
// TODO: Skin or language change causes page reload, we should test this separately
$this->settings = [
'timezone' => 'Pacific/Midway',
'time_format' => 'h:i A',
'date_format' => 'd-m-Y',
'refresh_interval' => 60,
'pretty_date' => !boolval($this->app->config->get('prettydate')),
'display_next' => !boolval($this->app->config->get('display_next')),
'standard_windows' => !boolval($this->app->config->get('standard_windows')),
];
$this->browse(function ($browser) {
// Update preferences
$browser->withinFrame('#preferences-frame', function ($browser) {
$browser->select('_timezone', $this->settings['timezone']);
$browser->select('_time_format', $this->settings['time_format']);
$browser->select('_date_format', $this->settings['date_format']);
$browser->select('_refresh_interval', $this->settings['refresh_interval']);
$this->setCheckboxState('_pretty_date', $this->settings['pretty_date']);
$this->setCheckboxState('_display_next', $this->settings['display_next']);
$this->setCheckboxState('_standard_windows', $this->settings['standard_windows']);
// Submit form
$browser->click('.formbuttons button.submit');
});
$this->waitForMessage('confirmation', 'Successfully saved');
// Verify if every option has been updated
$browser->withinFrame('#preferences-frame', function ($browser) {
$browser->assertSelected('_timezone', $this->settings['timezone']);
$browser->assertSelected('_time_format', $this->settings['time_format']);
$browser->assertSelected('_date_format', $this->settings['date_format']);
$browser->assertSelected('_refresh_interval', $this->settings['refresh_interval']);
$this->assertCheckboxState('_pretty_date', $this->settings['pretty_date']);
$this->assertCheckboxState('_display_next', $this->settings['display_next']);
$this->assertCheckboxState('_standard_windows', $this->settings['standard_windows']);
// Assert the options have been saved in database properly
$prefs = \bootstrap::get_prefs();
$options = array_diff(array_keys($this->settings), ['refresh_interval', 'pretty_date']);
foreach ($options as $option) {
$this->assertEquals($this->settings[$option], $prefs[$option]);
}
$this->assertEquals($this->settings['pretty_date'], $prefs['prettydate']);
$this->assertEquals($this->settings['refresh_interval'], $prefs['refresh_interval']/60);
});
});
}
}

@ -15,11 +15,22 @@ class Settings extends \Tests\Browser\DuskTestCase
$browser->assertSeeIn('#layout-sidebar .header', 'Settings'); $browser->assertSeeIn('#layout-sidebar .header', 'Settings');
// Sidebar menu // Sidebar menu
$browser->assertVisible('#settings-menu'); $browser->with('#settings-menu', function($browser) {
$browser->assertSeeIn('#settings-menu li.preferences', 'Preferences'); $browser->assertSeeIn('li.preferences', 'Preferences');
$browser->assertSeeIn('#settings-menu li.folders', 'Folders'); $browser->assertSeeIn('li.folders', 'Folders');
$browser->assertSeeIn('#settings-menu li.identities', 'Identities'); $browser->assertSeeIn('li.identities', 'Identities');
$browser->assertSeeIn('#settings-menu li.responses', 'Responses'); $browser->assertSeeIn('li.responses', 'Responses');
});
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled):not(.selected)');
$browser->assertVisible('a.mail:not(.disabled):not(.selected)');
$browser->assertVisible('a.contacts:not(.disabled):not(.selected)');
$browser->assertVisible('a.settings:not(.disabled).selected');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
}); });
} }
} }

@ -48,10 +48,10 @@ class bootstrap
{ {
$rcmail = rcmail::get_instance(); $rcmail = rcmail::get_instance();
$dsn = rcube_db::parse_dsn($rcmail->config->get('db_dsnw')); $dsn = rcube_db::parse_dsn($rcmail->config->get('db_dsnw'));
$db = $rcmail->get_dbh();
if ($dsn['phptype'] == 'mysql' || $dsn['phptype'] == 'mysqli') { if ($dsn['phptype'] == 'mysql' || $dsn['phptype'] == 'mysqli') {
// drop all existing tables first // drop all existing tables first
$db = $rcmail->get_dbh();
$db->query("SET FOREIGN_KEY_CHECKS=0"); $db->query("SET FOREIGN_KEY_CHECKS=0");
$sql_res = $db->query("SHOW TABLES"); $sql_res = $db->query("SHOW TABLES");
while ($sql_arr = $db->fetch_array($sql_res)) { while ($sql_arr = $db->fetch_array($sql_res)) {
@ -62,7 +62,7 @@ class bootstrap
// init database with schema // init database with schema
system(sprintf('cat %s %s | mysql -h %s -u %s --password=%s %s', system(sprintf('cat %s %s | mysql -h %s -u %s --password=%s %s',
realpath(INSTALL_PATH . '/SQL/mysql.initial.sql'), realpath(INSTALL_PATH . '/SQL/mysql.initial.sql'),
realpath(TESTS_DIR . 'data/mysql.sql'), realpath(TESTS_DIR . 'data/data.sql'),
escapeshellarg($dsn['hostspec']), escapeshellarg($dsn['hostspec']),
escapeshellarg($dsn['username']), escapeshellarg($dsn['username']),
escapeshellarg($dsn['password']), escapeshellarg($dsn['password']),
@ -70,8 +70,21 @@ class bootstrap
)); ));
} }
else if ($dsn['phptype'] == 'sqlite') { else if ($dsn['phptype'] == 'sqlite') {
// delete database file -- will be re-initialized on first access $db->closeConnection();
// delete database file
system(sprintf('rm -f %s', escapeshellarg($dsn['database']))); system(sprintf('rm -f %s', escapeshellarg($dsn['database'])));
// load sample test data
// Note: exec_script() does not really work with these queries
$sql = file_get_contents(TESTS_DIR . 'data/data.sql');
$sql = preg_split('/;\n/', $sql, -1, PREG_SPLIT_NO_EMPTY);
foreach ($sql as $query) {
$result = $db->query($query);
if ($db->is_error($result)) {
die($db->is_error());
}
}
} }
} }
@ -89,7 +102,7 @@ class bootstrap
self::connect_imap(TESTS_USER, TESTS_PASS); self::connect_imap(TESTS_USER, TESTS_PASS);
self::purge_mailbox('INBOX'); self::purge_mailbox('INBOX');
self::ensure_mailbox('Archive', true); // self::ensure_mailbox('Archive', true);
return self::$imap_ready; return self::$imap_ready;
} }
@ -97,7 +110,7 @@ class bootstrap
/** /**
* Authenticate to IMAP with the given credentials * Authenticate to IMAP with the given credentials
*/ */
public static function connect_imap($username, $password, $host = null) public static function connect_imap($username, $password)
{ {
$rcmail = rcmail::get_instance(); $rcmail = rcmail::get_instance();
$imap = $rcmail->get_storage(); $imap = $rcmail->get_storage();
@ -107,7 +120,7 @@ class bootstrap
self::$imap_ready = false; self::$imap_ready = false;
} }
$imap_host = $host ?: $rcmail->config->get('default_host'); $imap_host = $rcmail->config->get('default_host');
$a_host = parse_url($imap_host); $a_host = parse_url($imap_host);
if ($a_host['host']) { if ($a_host['host']) {
$imap_host = $a_host['host']; $imap_host = $a_host['host'];
@ -171,4 +184,28 @@ class bootstrap
$imap->delete_message('*', $mailbox); $imap->delete_message('*', $mailbox);
} }
} }
/**
* Check IMAP capabilities
*/
public static function get_storage()
{
if (!self::init_imap()) {
die(__METHOD__ . ': IMAP connection unavailable');
}
return rcmail::get_instance()->get_storage();
}
/**
* Return user preferences directly from database
*/
public static function get_prefs()
{
$db = rcmail::get_instance()->get_dbh();
$query = $db->query("SELECT preferences FROM users WHERE username = ?", TESTS_USER);
$record = $db->fetch_assoc($query);
return unserialize($record['preferences']);
}
} }

@ -0,0 +1,12 @@
BEGIN:VCARD
VERSION:3.0
N:Machniak;Aleksander;;;
FN:Aleksander Machniak
EMAIL;TYPE=INTERNET;TYPE=HOME:alec@example.org
END:VCARD
BEGIN:VCARD
VERSION:3.0
N:Stalone;Sylvester;;;
FN:Sylvester Stalone
EMAIL;TYPE=INTERNET;TYPE=HOME:s.stalone@rambo.tv
END:VCARD

@ -0,0 +1,14 @@
-- Contacts
DELETE FROM contacts;
INSERT INTO contacts (user_id, changed, del, name, email, firstname, surname, vcard, words) VALUES (1, '2019-12-31 12:23:33.523071-05', 0, 'John Doe', 'johndoe@example.org', 'John', 'Doe', 'BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
EMAIL;TYPE=INTERNET;TYPE=HOME:johndoe@example.org
END:VCARD', ' john do johndo@example.org');
INSERT INTO contacts (user_id, changed, del, name, email, firstname, surname, vcard, words) VALUES (1, '2019-12-31 12:24:10.213475-05', 0, 'Jane Stalone', 'j.stalone@microsoft.com', 'Jane', 'Stalone', 'BEGIN:VCARD
VERSION:3.0
N:Stalone;Jane;;;
FN:Jane Stalone
EMAIL;TYPE=INTERNET;TYPE=HOME:j.stalone@microsoft.com
END:VCARD', ' jane stalone j.stalone@microsoft.com');

@ -13,6 +13,7 @@
<testsuite name="Settings"> <testsuite name="Settings">
<file>Settings/Settings.php</file> <file>Settings/Settings.php</file>
<file>Settings/Preferences.php</file> <file>Settings/Preferences.php</file>
<file>Settings/Preferences/General.php</file>
<file>Settings/Folders.php</file> <file>Settings/Folders.php</file>
<file>Settings/Identities.php</file> <file>Settings/Identities.php</file>
<file>Settings/Responses.php</file> <file>Settings/Responses.php</file>
@ -20,7 +21,6 @@
</testsuite> </testsuite>
<testsuite name="Mail"> <testsuite name="Mail">
<file>Mail/Mail.php</file> <file>Mail/Mail.php</file>
<file>Mail/CheckRecent.php</file>
<file>Mail/Compose.php</file> <file>Mail/Compose.php</file>
<file>Mail/Getunread.php</file> <file>Mail/Getunread.php</file>
<file>Mail/List.php</file> <file>Mail/List.php</file>

Loading…
Cancel
Save