You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-07 17:42:53 +03:00
try and get working under travis ...
This commit is contained in:
@@ -1886,7 +1886,11 @@ function db_insert($table, array $values, $timestamp = array('created', 'modifie
|
|||||||
$domain_dirty = $values['domain'];
|
$domain_dirty = $values['domain'];
|
||||||
$domain = trim($domain_dirty, "`'"); // naive assumption it is ' escaping.
|
$domain = trim($domain_dirty, "`'"); // naive assumption it is ' escaping.
|
||||||
$password_expiration_value = (int) get_password_expiration_value($domain);
|
$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 {
|
} else {
|
||||||
if ($_table == 'mailbox') {
|
if ($_table == 'mailbox') {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
<phpunit>
|
<phpunit
|
||||||
<php>
|
bootstrap="tests/bootstrap.php"
|
||||||
<const name="PHPUNIT_TEST" value="yes"/>
|
>
|
||||||
</php>
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="default">
|
<testsuite name="default">
|
||||||
<directory>./tests</directory>
|
<directory>./tests</directory>
|
||||||
@@ -9,7 +8,7 @@
|
|||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
<php>
|
<php>
|
||||||
<const name="PHP_UNIT_TEST" value="true" />
|
<const name="PHPUNIT_TEST" value="true" />
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<logging>
|
<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) {
|
function printdebug($text) {
|
||||||
if (safeget('debug') != "") {
|
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) {
|
if ($current_version >= $target_version) {
|
||||||
# already up to date
|
# 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<p>Updating database:</p><p>- old version: $current_version; target version: $target_version</p>\n";
|
echo_out("<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("<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) {
|
if (db_sqlite() && $current_version < 1824) {
|
||||||
// Fast forward to the first revision supporting SQLite
|
// Fast forward to the first revision supporting SQLite
|
||||||
@@ -195,34 +203,34 @@ function _do_upgrade($current_version) {
|
|||||||
$function_sqlite = $function . "_sqlite";
|
$function_sqlite = $function . "_sqlite";
|
||||||
|
|
||||||
if (function_exists($function)) {
|
if (function_exists($function)) {
|
||||||
echo "<p>updating to version $i (all databases)...";
|
echo_out("<p>updating to version $i (all databases)...");
|
||||||
$function();
|
$function();
|
||||||
echo " done";
|
echo_out(" done");
|
||||||
}
|
}
|
||||||
if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli' || $CONF['database_type'] == 'pgsql') {
|
if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli' || $CONF['database_type'] == 'pgsql') {
|
||||||
if (function_exists($function_mysql_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();
|
$function_mysql_pgsql();
|
||||||
echo " done";
|
echo_out(" done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli') {
|
if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli') {
|
||||||
if (function_exists($function_mysql)) {
|
if (function_exists($function_mysql)) {
|
||||||
echo "<p>updating to version $i (MySQL)...";
|
echo_out("<p>updating to version $i (MySQL)...");
|
||||||
$function_mysql();
|
$function_mysql();
|
||||||
echo " done";
|
echo_out(" done");
|
||||||
}
|
}
|
||||||
} elseif (db_sqlite()) {
|
} elseif (db_sqlite()) {
|
||||||
if (function_exists($function_sqlite)) {
|
if (function_exists($function_sqlite)) {
|
||||||
echo "<p>updating to version $i (SQLite)...";
|
echo_out("<p>updating to version $i (SQLite)...");
|
||||||
$function_sqlite();
|
$function_sqlite();
|
||||||
echo " done";
|
echo_out(" done");
|
||||||
}
|
}
|
||||||
} elseif ($CONF['database_type'] == 'pgsql') {
|
} elseif ($CONF['database_type'] == 'pgsql') {
|
||||||
if (function_exists($function_pgsql)) {
|
if (function_exists($function_pgsql)) {
|
||||||
echo "<p>updating to version $i (PgSQL)...";
|
echo_out("<p>updating to version $i (PgSQL)...");
|
||||||
$function_pgsql();
|
$function_pgsql();
|
||||||
echo " done";
|
echo_out(" done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Update config table so we don't run the same query twice in the future.
|
// 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()',
|
'{DATECURRENT}' => 'timestamp with time zone default now()',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
echo "Sorry, unsupported database type " . $CONF['database_type'];
|
echo_out("Sorry, unsupported database type " . $CONF['database_type']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +334,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") {
|
|||||||
}
|
}
|
||||||
$result = db_query($query, $ignore_errors);
|
$result = db_query($query, $ignore_errors);
|
||||||
if ($debug) {
|
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()) {
|
} elseif ($CONF['database_type'] == 'pgsql' || db_sqlite()) {
|
||||||
return "DROP INDEX $index"; # Index names are unique with a DB for PostgreSQL
|
return "DROP INDEX $index"; # Index names are unique with a DB for PostgreSQL
|
||||||
} else {
|
} else {
|
||||||
echo "Sorry, unsupported database type " . $CONF['database_type'];
|
echo_out("Sorry, unsupported database type " . $CONF['database_type']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,7 +363,7 @@ function _add_index($table, $indexname, $fieldlist) {
|
|||||||
$pgindexname = $table . "_" . $indexname . '_idx';
|
$pgindexname = $table . "_" . $indexname . '_idx';
|
||||||
return "CREATE INDEX $pgindexname ON $table($fieldlist);"; # Index names are unique with a DB for PostgreSQL
|
return "CREATE INDEX $pgindexname ON $table($fieldlist);"; # Index names are unique with a DB for PostgreSQL
|
||||||
} else {
|
} else {
|
||||||
echo "Sorry, unsupported database type " . $CONF['database_type'];
|
echo_out("Sorry, unsupported database type " . $CONF['database_type']);
|
||||||
exit;
|
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');
|
Reference in New Issue
Block a user