JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
clean up include paths and docs
[wfpl.git] / unit_tests / db.php
index 4906f1b..5077c8f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-#  Copyright (C) 2009 Jason Woofenden
+#  Copyright (C) 2010 Jason Woofenden
 #
 #  This program is free software: you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-# This file contains tests for functions in code/wfpl/format.php
+# This file contains tests for functions in wfpl/format.php
 #
-# See code/wfpl/test.php for details on how to run or create tests
+# See wfpl/test.php for details on how to run or create tests
 
 
-require_once('code/wfpl/db.php');
+require_once(__DIR__.'/../'.'db.php');
 
-# returns number of errors
-function test_db_reposition() {
-       $table = 'reposition';
-       $errors = 0;
+function test_db_reposition($table = 'reposition') {
        db_delete($table);
        db_insert($table, 'ord', '2');
        $a = db_auto_id();
@@ -72,21 +69,18 @@ function test_db_reposition() {
                db_update($table, 'ord', $ord, 'where id=%i', $before[$src]);
                $after = db_get_column($table, 'id', 'order by ord');
                $ords = db_get_column($table, 'ord', 'order by ord');
-               if($before[$c1] != $after[0] || $before[$c2] != $after[1] || $before[$c3] != $after[2]) {
-                       message("db_reposition($before[$src], $dest) did: ($before[0]:$before_ords[0], $before[1]:$before_ords[1], $before[2]:$before_ords[2]) -> ($after[0]:$ords[0]), $after[1]:$ords[1], $after[2]:$ords[2])");
-                       $errors += 1;
+               $message = "db_reposition($before[$src], $dest) did: ($before[0]:$before_ords[0], $before[1]:$before_ords[1], $before[2]:$before_ords[2]) -> ($after[0]:$ords[0]), $after[1]:$ords[1], $after[2]:$ords[2])";
+               if($before[$c1] == $after[0] && $before[$c2] == $after[1] && $before[$c3] == $after[2]) {
+                       unit_test_passed($message);
+               } else {
+                       unit_test_failed($message);
                }
                $before = $after;
                $before_ords = $ords;
        }
-
-       return $errors;
 }
 
-# returns number of errors
 function db_unit_tests_main() {
        db_connect('test');
-       $errors = 0;
-       $errors += test_db_reposition();
-       return $errors;
+       test_db_reposition();
 }