JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
unit_test_func requires that type matches
[wfpl.git] / unit_tests / encode.php
1 <?php
2
3 #  Copyright (C) 2010 Jason Woofenden
4 #
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.
9 #  
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.
14 #  
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/>.
17
18
19 # This file contains tests for functions in code/wfpl/format.php
20 #
21 # See code/wfpl/test.php for details on how to run or create tests
22
23
24 require_once('code/wfpl/encode.php');
25
26 # returns number of errors
27 function _test_encode_pulled($field, $value, $correct) {
28         unit_test_func('enc_pulled', $value, $field, $correct);
29 }
30
31 function test_encode_pulled() {
32         pulldown('array', array('one', 'two', "symbols&amp;'\""));
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&amp;\'"', 'symbols&amp;\'"');
37
38         pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&amp;\'"', '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&amp;\'"', 'Slobmys');
44
45         pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&amp;\'"', '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;amp;\'"', 'symbols&amp;amp;\'"'); # not found in unchanged
50 }
51
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");
60 }
61
62 function encode_unit_tests_main() {
63         test_encode_pulled();
64         test_encode_misc();
65 }