JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / unit_tests / encode.php
1 <?php
2
3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
7
8
9 # This file contains tests for functions in wfpl/encode.php
10 #
11 # See wfpl/test.php for details on how to run or create tests
12
13
14 require_once(__DIR__.'/../'.'encode.php');
15
16 function _test_encode_pulled($field, $value, $correct) {
17         unit_test_func('enc_pulled', $value, $field, $correct);
18 }
19
20 function test_encode_pulled() {
21         pulldown('array', array('one', 'two', "symbols&amp;'\""));
22         _test_encode_pulled('array', 'one', 'one');
23         _test_encode_pulled('array', 'One', 'One'); # not found is unchanged
24         _test_encode_pulled('array', 'two', 'two');
25         _test_encode_pulled('array', 'symbols&amp;\'"', 'symbols&amp;\'"');
26
27         pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&amp;\'"', 'Slobmys')));
28         _test_encode_pulled('mixed', 'one', 'Eno');
29         _test_encode_pulled('mixed', 'One', 'One'); # not found is unchanged
30         _test_encode_pulled('mixed', 'two', 'two');
31         _test_encode_pulled('mixed', 'symbols&\'"', 'symbols&\'"'); # not found is unchanged
32         _test_encode_pulled('mixed', 'symbols&amp;\'"', 'Slobmys');
33
34         pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&amp;\'"', 'Slobmys')));
35         _test_encode_pulled('array_2d', 'one', 'Eno');
36         _test_encode_pulled('array_2d', 'One', 'One'); # not found in unchanged
37         _test_encode_pulled('array_2d', 'two', 'Owt');
38         _test_encode_pulled('array_2d', 'symbols&amp;amp;\'"', 'symbols&amp;amp;\'"'); # not found in unchanged
39 }
40
41 function test_encode_misc() {
42         unit_test_func('enc_tab', '', '');
43         unit_test_func('enc_tab', "\n", "\t\n\t");
44         unit_test_func('enc_tab', "a", "\ta");
45         unit_test_func('enc_tab', "a\n", "\ta\n\t");
46         unit_test_func('enc_tab', "\t", "\t\t");
47         unit_test_func('enc_tab', "\n\na", "\t\n\t\n\ta");
48         unit_test_func('enc_tab', "\t\n\t\n\ta", "\t\t\n\t\t\n\t\ta");
49 }
50
51 function encode_unit_tests_main() {
52         test_encode_pulled();
53         test_encode_misc();
54 }