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/encode.php');
26 # returns number of errors
27 function _test_encode_pulled($field, $value, $correct) {
28 unit_test_func('enc_pulled', $value, $field, $correct);
31 function test_encode_pulled() {
32 pulldown('array', array('one', 'two', "symbols&'\""));
33 _test_encode_pulled('array', 'one', 'one');
34 _test_encode_pulled('array', 'One', 'One'); # not found is unchanged
35 _test_encode_pulled('array', 'two', 'two');
36 _test_encode_pulled('array', 'symbols&\'"', 'symbols&\'"');
38 pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&\'"', 'Slobmys')));
39 _test_encode_pulled('mixed', 'one', 'Eno');
40 _test_encode_pulled('mixed', 'One', 'One'); # not found is unchanged
41 _test_encode_pulled('mixed', 'two', 'two');
42 _test_encode_pulled('mixed', 'symbols&\'"', 'symbols&\'"'); # not found is unchanged
43 _test_encode_pulled('mixed', 'symbols&\'"', 'Slobmys');
45 pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&\'"', 'Slobmys')));
46 _test_encode_pulled('array_2d', 'one', 'Eno');
47 _test_encode_pulled('array_2d', 'One', 'One'); # not found in unchanged
48 _test_encode_pulled('array_2d', 'two', 'Owt');
49 _test_encode_pulled('array_2d', 'symbols&amp;\'"', 'symbols&amp;\'"'); # not found in unchanged
52 function test_encode_misc() {
53 unit_test_func('enc_tab', '', '');
54 unit_test_func('enc_tab', "\n", "\t\n\t");
55 unit_test_func('enc_tab', "a", "\ta");
56 unit_test_func('enc_tab', "a\n", "\ta\n\t");
57 unit_test_func('enc_tab', "\t", "\t\t");
58 unit_test_func('enc_tab', "\n\na", "\t\n\t\n\ta");
59 unit_test_func('enc_tab', "\t\n\t\n\ta", "\t\t\n\t\t\n\t\ta");
62 function encode_unit_tests_main() {