3 # Copyright (C) 2010 Jason Woofenden
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # This file contains tests for functions in code/wfpl/format.php
21 # See code/wfpl/test.php for details on how to run or create tests
24 require_once('code/wfpl/db.php');
26 function test_db_reposition($table = 'reposition') {
28 db_insert($table, 'ord', '2');
30 db_insert($table, 'ord', '3');
32 db_insert($table, 'ord', '4');
34 $before = array($a, $b, $c);
35 $before_ords = array('2', '3', '4');
39 # / destination (0: first, 1: after first, 2: after 2nd, 3: after third)
40 #| / result (starting with 012 on each row)
54 # add tests for needing renumbering
56 '10 102', # no more room at the start
57 '02 102', # no more room in the middle (moving up)
58 '21 021', # no more room in the middle (moving down)
59 '03 120'); # no more room at the end
60 foreach($thirtytwo as $test) {
61 for($i = 0; $i < 32; ++$i) {
66 foreach($args as $arg_str) {
67 list($src, $dest, $space, $c1, $c2, $c3) = str_split($arg_str);
68 $ord = db_reposition($table, $before[$src], $dest, 'ord', 'test record');
69 db_update($table, 'ord', $ord, 'where id=%i', $before[$src]);
70 $after = db_get_column($table, 'id', 'order by ord');
71 $ords = db_get_column($table, 'ord', 'order by ord');
72 $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])";
73 if($before[$c1] == $after[0] && $before[$c2] == $after[1] && $before[$c3] == $after[2]) {
74 unit_test_passed($message);
76 unit_test_failed($message);
83 function db_unit_tests_main() {