JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
911a8af47ffe03a53ef243cf48f0194cf2404c7b
[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(__DIR__.'/'.'code/wfpl/encode.php');
25
26 function _test_encode_pulled($field, $value, $correct) {
27         unit_test_func('enc_pulled', $value, $field, $correct);
28 }
29
30 function test_encode_pulled() {
31         pulldown('array', array('one', 'two', "symbols&amp;'\""));
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&amp;\'"', 'symbols&amp;\'"');
36
37         pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&amp;\'"', '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&amp;\'"', 'Slobmys');
43
44         pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&amp;\'"', '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;amp;\'"', 'symbols&amp;amp;\'"'); # not found in unchanged
49 }
50
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");
59 }
60
61 function encode_unit_tests_main() {
62         test_encode_pulled();
63         test_encode_misc();
64 }