3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
9 # This file contains tests for functions in wfpl/format.php
11 # See wfpl/test.php for details on how to run or create tests
14 require_once(__DIR__.'/../'.'db.php');
16 function test_db_reposition($table = 'reposition') {
18 db_insert($table, 'ord', '2');
20 db_insert($table, 'ord', '3');
22 db_insert($table, 'ord', '4');
24 $before = array($a, $b, $c);
25 $before_ords = array('2', '3', '4');
29 # / destination (0: first, 1: after first, 2: after 2nd, 3: after third)
30 #| / result (starting with 012 on each row)
44 # add tests for needing renumbering
46 '10 102', # no more room at the start
47 '02 102', # no more room in the middle (moving up)
48 '21 021', # no more room in the middle (moving down)
49 '03 120'); # no more room at the end
50 foreach($thirtytwo as $test) {
51 for($i = 0; $i < 32; ++$i) {
56 foreach($args as $arg_str) {
57 list($src, $dest, $space, $c1, $c2, $c3) = str_split($arg_str);
58 $ord = db_reposition($table, $before[$src], $dest, 'ord', 'test record');
59 db_update($table, 'ord', $ord, 'where id=%i', $before[$src]);
60 $after = db_get_column($table, 'id', 'order by ord');
61 $ords = db_get_column($table, 'ord', 'order by ord');
62 $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])";
63 if($before[$c1] == $after[0] && $before[$c2] == $after[1] && $before[$c3] == $after[2]) {
64 unit_test_passed($message);
66 unit_test_failed($message);
73 function db_unit_tests_main() {