Browse Source

Fix database initialization for the browser tests

pull/8233/head
Aleksander Machniak 4 years ago
parent
commit
50a3a6fd81
  1. 23
      tests/Browser/bootstrap.php
  2. 2
      tests/Browser/data/data.sql

23
tests/Browser/bootstrap.php

@ -70,6 +70,8 @@ class bootstrap
$db->query("DROP TABLE $table");
}
self::init_db_user($db);
// init database with schema
system(sprintf('cat %s %s | mysql -h %s -u %s --password=%s %s',
realpath(INSTALL_PATH . '/SQL/mysql.initial.sql'),
@ -85,6 +87,8 @@ class bootstrap
// delete database file
system(sprintf('rm -f %s', escapeshellarg($dsn['database'])));
self::init_db_user($db);
// load sample test data
// Note: exec_script() does not really work with these queries
$sql = file_get_contents(TESTS_DIR . 'data/data.sql');
@ -99,6 +103,25 @@ class bootstrap
}
}
/**
* Create user/identity record for the test user
*/
private static function init_db_user($db)
{
$rcmail = rcmail::get_instance();
$imap_host = $rcmail->config->get('default_host');
if ($host = parse_url($imap_host, PHP_URL_HOST)) {
$imap_host = $host;
}
$db->query("INSERT INTO `users` (`username`, `mail_host`, `language`)"
. " VALUES (?, ?, 'en_US')", TESTS_USER, $imap_host);
$db->query("INSERT INTO `identities` (`user_id`, `email`, `standard`)"
. " VALUES (1, ?, '1')", TESTS_USER);
}
/**
* Wipe the configured IMAP account and fill with test data
*/

2
tests/Browser/data/data.sql

@ -1,6 +1,4 @@
DELETE FROM responses;
-- 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;;;

Loading…
Cancel
Save