3 # Copyright (C) 2009 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 # returns number of errors
27 function test_db_reposition() {
28 $table = 'reposition';
31 db_insert($table, 'ord', '2');
33 db_insert($table, 'ord', '3');
35 db_insert($table, 'ord', '4');
37 $before = array($a, $b, $c);
38 $before_ords = array('2', '3', '4');
42 # / destination (0: first, 1: after first, 2: after 2nd, 3: after third)
43 #| / result (starting with 012 on each row)
57 # add tests for needing renumbering
59 '10 102', # no more room at the start
60 '02 102', # no more room in the middle (moving up)
61 '21 021', # no more room in the middle (moving down)
62 '03 120'); # no more room at the end
63 foreach($thirtytwo as $test) {
64 for($i = 0; $i < 32; ++$i) {
69 foreach($args as $arg_str) {
70 list($src, $dest, $space, $c1, $c2, $c3) = str_split($arg_str);
71 $ord = db_reposition($table, $before[$src], $dest);
72 db_update($table, 'ord', $ord, 'where id=%i', $before[$src]);
73 $after = db_get_column($table, 'id', 'order by ord');
74 $ords = db_get_column($table, 'ord', 'order by ord');
75 if($before[$c1] != $after[0] || $before[$c2] != $after[1] || $before[$c3] != $after[2]) {
76 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])");
86 # returns number of errors
87 function db_unit_tests_main() {
90 $errors += test_db_reposition();