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 function _test_encode_pulled($field, $value, $correct) {
27 unit_test_func('enc_pulled', $value, $field, $correct);
30 function test_encode_pulled() {
31 pulldown('array', array('one', 'two', "symbols&'\""));
32 _test_encode_pulled('array', 'one', 'one');
33 _test_encode_pulled('array', 'One', 'One'); # not found is unchanged
34 _test_encode_pulled('array', 'two', 'two');
35 _test_encode_pulled('array', 'symbols&\'"', 'symbols&\'"');
37 pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&\'"', 'Slobmys')));
38 _test_encode_pulled('mixed', 'one', 'Eno');
39 _test_encode_pulled('mixed', 'One', 'One'); # not found is unchanged
40 _test_encode_pulled('mixed', 'two', 'two');
41 _test_encode_pulled('mixed', 'symbols&\'"', 'symbols&\'"'); # not found is unchanged
42 _test_encode_pulled('mixed', 'symbols&\'"', 'Slobmys');
44 pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&\'"', 'Slobmys')));
45 _test_encode_pulled('array_2d', 'one', 'Eno');
46 _test_encode_pulled('array_2d', 'One', 'One'); # not found in unchanged
47 _test_encode_pulled('array_2d', 'two', 'Owt');
48 _test_encode_pulled('array_2d', 'symbols&amp;\'"', 'symbols&amp;\'"'); # not found in unchanged
51 function test_encode_misc() {
52 unit_test_func('enc_tab', '', '');
53 unit_test_func('enc_tab', "\n", "\t\n\t");
54 unit_test_func('enc_tab', "a", "\ta");
55 unit_test_func('enc_tab', "a\n", "\ta\n\t");
56 unit_test_func('enc_tab', "\t", "\t\t");
57 unit_test_func('enc_tab', "\n\na", "\t\n\t\n\ta");
58 unit_test_func('enc_tab', "\t\n\t\n\ta", "\t\t\n\t\t\n\t\ta");
61 function encode_unit_tests_main() {