summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-05-21 15:11:36 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-05-21 18:43:13 +0200
commit764ec006839636a5dc7bd6bf65760037570a16c0 (patch)
treee99f89a35a967db607008c07807bca71acd06127
parent77198abd94437eb418f11957695986470b1afc9a (diff)
tests: Rework database handling
We no longer interfere with the normal installation's database settings. Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/config/example/database.php7
-rw-r--r--application/controllers/tools.php4
-rwxr-xr-xrun-tests.sh57
3 files changed, 32 insertions, 36 deletions
diff --git a/application/config/example/database.php b/application/config/example/database.php
index 51b666b38..7a0e63d56 100644
--- a/application/config/example/database.php
+++ b/application/config/example/database.php
@@ -64,6 +64,13 @@ $db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
+if (getenv("ENVIRONMENT") === "testsuite") {
+ // Change these to your likeing, just make sure they
+ // don't overlap with the normal settings.
+ $db['default']['database'] = "filebin_testsuite";
+ $db['default']['dbprefix'] = "testsuite-prefix-";
+}
+
/* End of file database.php */
/* Location: ./application/config/database.php */ \ No newline at end of file
diff --git a/application/controllers/tools.php b/application/controllers/tools.php
index d38ab7c39..a444e6024 100644
--- a/application/controllers/tools.php
+++ b/application/controllers/tools.php
@@ -43,14 +43,14 @@ class Tools extends MY_Controller {
}
}
- function drop_all_tables_using_prefix()
+ function drop_all_tables()
{
$tables = $this->db->list_tables();
$prefix = $this->db->dbprefix;
$tables_to_drop = array();
foreach ($tables as $table) {
- if (strpos($table, $prefix) === 0) {
+ if ($prefix === "" || strpos($table, $prefix) === 0) {
$tables_to_drop[] = $this->db->protect_identifiers($table);
}
}
diff --git a/run-tests.sh b/run-tests.sh
index 5d1c2597c..78e36d3c9 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -2,56 +2,45 @@
#
# This runs the testsuite
#
-# If you have a local webserver you can call this script with it's URL.
+
+export ENVIRONMENT="testsuite"
startdir="$(dirname "$0")"
url=""
-use_php_dev_server=0
-
-if (($#>0)); then
- url="$1"
-fi
-
+port=23115
+ip='127.0.0.1'
+url="http://$ip:$port/index.php"
+
+die() {
+ echo "$@" >&2
+ echo "Aborting..." >&2
+ exit 1
+}
-if [[ -z "$url" ]]; then
- port=23115
- url="http://127.0.0.1:$port/index.php"
- use_php_dev_server=1
-fi
cd "$startdir"
-test -d system || exit 1
-test -d application || exit 1
-test -f run-tests.sh || exit 1
+# some sanity checks
+test -d system || die 'Required dir not found.'
+test -d application || die 'Required dir not found.'
+test -f run-tests.sh || die 'Required file not found.'
+grep -qF 'getenv("ENVIRONMENT")' application/config/database.php || die "database config doesn't honor ENVIRONMENT."
# prepare
trap cleanup EXIT INT
cleanup() {
- php index.php tools drop_all_tables_using_prefix
- if ((use_php_dev_server)); then
- kill $server_pid
- fi
- rm -f $startdir/application/config/database-testsuite.php
+ pkill -P $$
+ php index.php tools drop_all_tables
}
-cat <<EOF >application/config/database-testsuite.php || exit 1
-<?php
-\$db['default']['dbprefix'] = "testsuite-prefix-";
-EOF
-
-if ((use_php_dev_server)); then
- php -S 127.0.0.1:$port &
- server_pid=$!
-
- while ! curl -s "$url" >/dev/null; do
- sleep 0.2;
- done
-fi
+php -S "$ip:$port" &
+while ! curl -s "$url" >/dev/null; do
+ sleep 0.1;
+done
# run tests
-php index.php tools drop_all_tables_using_prefix
+php index.php tools drop_all_tables
php index.php tools update_database
prove --ext .php --state=hot,slow,all,save --timer -ve "php index.php tools test $url" -r application/test/tests/