From b2e814967f0f61a71597998a68520100d0347e61 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 29 Dec 2018 21:45:12 +0000 Subject: [PATCH] try and get working under travis ... --- functions.inc.php | 6 +++++- phpunit.xml | 9 ++++----- public/upgrade.php | 44 ++++++++++++++++++++++++++------------------ tests/bootstrap.php | 26 ++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 tests/bootstrap.php diff --git a/functions.inc.php b/functions.inc.php index d2daa8ce..19c26153 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1886,7 +1886,11 @@ function db_insert($table, array $values, $timestamp = array('created', 'modifie $domain_dirty = $values['domain']; $domain = trim($domain_dirty, "`'"); // naive assumption it is ' escaping. $password_expiration_value = (int) get_password_expiration_value($domain); - $values['password_expiry'] = "now() + interval " . $password_expiration_value . " day"; + if (db_sqlite()) { + $values['password_expiry'] = "datetime('now', '$password_expiration_value day')"; + } else { + $values['password_expiry'] = "now() + interval " . $password_expiration_value . " day"; + } } } else { if ($_table == 'mailbox') { diff --git a/phpunit.xml b/phpunit.xml index e95d012b..59fd7575 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,6 @@ - - - - + ./tests @@ -9,7 +8,7 @@ - + diff --git a/public/upgrade.php b/public/upgrade.php index df4f7a26..ff138dd6 100644 --- a/public/upgrade.php +++ b/public/upgrade.php @@ -111,9 +111,17 @@ function _db_add_field($table, $field, $fieldtype, $after = '') { } } +function echo_out($text) { + if (defined('PHPUNIT_TEST')) { + error_log("ErrorLog" . $text); + } else { + echo $text; + } +} + function printdebug($text) { if (safeget('debug') != "") { - print "

$text

"; + echo_out("

$text

"); } } @@ -175,12 +183,12 @@ function _do_upgrade($current_version) { if ($current_version >= $target_version) { # already up to date - echo "

Database is up to date: $current_version/$target_version

"; + echo_out("

Database is up to date: $current_version/$target_version

"); return true; } - echo "

Updating database:

- old version: $current_version; target version: $target_version

\n"; - echo "
  (If the update doesn't work, run setup.php?debug=1 to see the detailed error messages and SQL queries.)
"; + echo_out("

Updating database:

- old version: $current_version; target version: $target_version

\n"); + echo_out("
  (If the update doesn't work, run setup.php?debug=1 to see the detailed error messages and SQL queries.)
"); if (db_sqlite() && $current_version < 1824) { // Fast forward to the first revision supporting SQLite @@ -195,34 +203,34 @@ function _do_upgrade($current_version) { $function_sqlite = $function . "_sqlite"; if (function_exists($function)) { - echo "

updating to version $i (all databases)..."; + echo_out("

updating to version $i (all databases)..."); $function(); - echo "   done"; + echo_out("   done"); } if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli' || $CONF['database_type'] == 'pgsql') { if (function_exists($function_mysql_pgsql)) { - echo "

updating to version $i (MySQL and PgSQL)..."; + echo_out("

updating to version $i (MySQL and PgSQL)..."); $function_mysql_pgsql(); - echo "   done"; + echo_out("   done"); } } if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli') { if (function_exists($function_mysql)) { - echo "

updating to version $i (MySQL)..."; + echo_out("

updating to version $i (MySQL)..."); $function_mysql(); - echo "   done"; + echo_out("   done"); } } elseif (db_sqlite()) { if (function_exists($function_sqlite)) { - echo "

updating to version $i (SQLite)..."; + echo_out("

updating to version $i (SQLite)..."); $function_sqlite(); - echo "   done"; + echo_out("   done"); } } elseif ($CONF['database_type'] == 'pgsql') { if (function_exists($function_pgsql)) { - echo "

updating to version $i (PgSQL)..."; + echo_out("

updating to version $i (PgSQL)..."); $function_pgsql(); - echo "   done"; + echo_out("   done"); } } // Update config table so we don't run the same query twice in the future. @@ -310,7 +318,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") { '{DATECURRENT}' => 'timestamp with time zone default now()', ); } else { - echo "Sorry, unsupported database type " . $CONF['database_type']; + echo_out("Sorry, unsupported database type " . $CONF['database_type']); exit; } @@ -326,7 +334,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") { } $result = db_query($query, $ignore_errors); if ($debug) { - print "

" . $result['error'] . "
"; + echo_out("
" . $result['error'] . "
"); } } @@ -339,7 +347,7 @@ function _drop_index($table, $index) { } elseif ($CONF['database_type'] == 'pgsql' || db_sqlite()) { return "DROP INDEX $index"; # Index names are unique with a DB for PostgreSQL } else { - echo "Sorry, unsupported database type " . $CONF['database_type']; + echo_out("Sorry, unsupported database type " . $CONF['database_type']); exit; } } @@ -355,7 +363,7 @@ function _add_index($table, $indexname, $fieldlist) { $pgindexname = $table . "_" . $indexname . '_idx'; return "CREATE INDEX $pgindexname ON $table($fieldlist);"; # Index names are unique with a DB for PostgreSQL } else { - echo "Sorry, unsupported database type " . $CONF['database_type']; + echo_out("Sorry, unsupported database type " . $CONF['database_type']); exit; } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..551a4250 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,26 @@ +