mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-19 19:22:14 +02:00
try and get working under travis ...
This commit is contained in:
parent
590c80f0bc
commit
b2e814967f
@ -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') {
|
||||
|
@ -1,7 +1,6 @@
|
||||
<phpunit>
|
||||
<php>
|
||||
<const name="PHPUNIT_TEST" value="yes"/>
|
||||
</php>
|
||||
<phpunit
|
||||
bootstrap="tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory>./tests</directory>
|
||||
@ -9,7 +8,7 @@
|
||||
</testsuites>
|
||||
|
||||
<php>
|
||||
<const name="PHP_UNIT_TEST" value="true" />
|
||||
<const name="PHPUNIT_TEST" value="true" />
|
||||
</php>
|
||||
|
||||
<logging>
|
||||
|
@ -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 "<p style='color:#999'>$text</p>";
|
||||
echo_out("<p style='color:#999'>$text</p>");
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,12 +183,12 @@ function _do_upgrade($current_version) {
|
||||
|
||||
if ($current_version >= $target_version) {
|
||||
# already up to date
|
||||
echo "<p>Database is up to date: $current_version/$target_version </p>";
|
||||
echo_out("<p>Database is up to date: $current_version/$target_version </p>");
|
||||
return true;
|
||||
}
|
||||
|
||||
echo "<p>Updating database:</p><p>- old version: $current_version; target version: $target_version</p>\n";
|
||||
echo "<div style='color:#999'> (If the update doesn't work, run setup.php?debug=1 to see the detailed error messages and SQL queries.)</div>";
|
||||
echo_out("<p>Updating database:</p><p>- old version: $current_version; target version: $target_version</p>\n");
|
||||
echo_out("<div style='color:#999'> (If the update doesn't work, run setup.php?debug=1 to see the detailed error messages and SQL queries.)</div>");
|
||||
|
||||
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 "<p>updating to version $i (all databases)...";
|
||||
echo_out("<p>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 "<p>updating to version $i (MySQL and PgSQL)...";
|
||||
echo_out("<p>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 "<p>updating to version $i (MySQL)...";
|
||||
echo_out("<p>updating to version $i (MySQL)...");
|
||||
$function_mysql();
|
||||
echo " done";
|
||||
echo_out(" done");
|
||||
}
|
||||
} elseif (db_sqlite()) {
|
||||
if (function_exists($function_sqlite)) {
|
||||
echo "<p>updating to version $i (SQLite)...";
|
||||
echo_out("<p>updating to version $i (SQLite)...");
|
||||
$function_sqlite();
|
||||
echo " done";
|
||||
echo_out(" done");
|
||||
}
|
||||
} elseif ($CONF['database_type'] == 'pgsql') {
|
||||
if (function_exists($function_pgsql)) {
|
||||
echo "<p>updating to version $i (PgSQL)...";
|
||||
echo_out("<p>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 "<div style='color:#f00'>" . $result['error'] . "</div>";
|
||||
echo_out("<div style='color:#f00'>" . $result['error'] . "</div>");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
26
tests/bootstrap.php
Normal file
26
tests/bootstrap.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
define('POSTFIXADMIN', 1);
|
||||
define('POSTFIXADMIN_CLI', 1);
|
||||
|
||||
require_once(dirname(__FILE__) . '/../vendor/autoload.php');
|
||||
require_once(dirname(__FILE__) . '/../common.php');
|
||||
|
||||
|
||||
$CONF['default_language'] = 'en';
|
||||
$CONF['language_hook'] = '';
|
||||
|
||||
$db_file = '/tmp/postfixadmin.sqlite.test';
|
||||
$CONF['database_type'] = 'sqlite';
|
||||
$CONF['database_name'] = $db_file;
|
||||
|
||||
Config::write('database_type', 'sqlite');
|
||||
Config::write('database_name', $db_file);
|
||||
|
||||
clearstatcache();
|
||||
if (file_exists($db_file)) {
|
||||
unlink($db_file);
|
||||
}
|
||||
|
||||
|
||||
require_once(dirname(__FILE__) . '/../public/upgrade.php');
|
Loading…
Reference in New Issue
Block a user