X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=unit_tests%2Fdb.php;h=a7499702c922a20b41f4a3d4770a5bc1df4e5a88;hb=900e09b8300463e3dd42e89c21de181520513e95;hp=a2aeb1b1f06c1655b78bb16ff67fe4ddc276fc16;hpb=0e820ee53af5142bd6774ee415ccdb9627bcdbb6;p=wfpl.git diff --git a/unit_tests/db.php b/unit_tests/db.php index a2aeb1b..a749970 100644 --- a/unit_tests/db.php +++ b/unit_tests/db.php @@ -1,32 +1,19 @@ . +# This program is in the public domain within the United States. Additionally, +# we waive copyright and related rights in the work worldwide through the CC0 +# 1.0 Universal public domain dedication, which can be found at +# http://creativecommons.org/publicdomain/zero/1.0/ -# 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(); @@ -68,25 +55,22 @@ function test_db_reposition() { foreach($args as $arg_str) { list($src, $dest, $space, $c1, $c2, $c3) = str_split($arg_str); - $ord = db_reposition($table, $before[$src], $dest); + $ord = db_reposition($table, $before[$src], $dest, 'ord', 'test record'); 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(); }