+<?php
+
+# Copyright (C) 2010 Jason Woofenden
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This file contains tests for functions in code/wfpl/format.php
+#
+# See code/wfpl/test.php for details on how to run or create tests
+
+
+require_once('code/wfpl/encode.php');
+
+# returns number of errors
+function _test_encode_pulled($field, $value, $correct) {
+ unit_test_func('enc_pulled', $value, $field, $correct);
+}
+
+function test_encode_pulled() {
+ pulldown('array', array('one', 'two', "symbols&'\""));
+ _test_encode_pulled('array', 'one', 'one');
+ _test_encode_pulled('array', 'One', 'One'); # not found is unchanged
+ _test_encode_pulled('array', 'two', 'two');
+ _test_encode_pulled('array', 'symbols&\'"', 'symbols&\'"');
+
+ pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&\'"', 'Slobmys')));
+ _test_encode_pulled('mixed', 'one', 'Eno');
+ _test_encode_pulled('mixed', 'One', 'One'); # not found is unchanged
+ _test_encode_pulled('mixed', 'two', 'two');
+ _test_encode_pulled('mixed', 'symbols&\'"', 'symbols&\'"'); # not found is unchanged
+ _test_encode_pulled('mixed', 'symbols&\'"', 'Slobmys');
+
+ pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&\'"', 'Slobmys')));
+ _test_encode_pulled('array_2d', 'one', 'Eno');
+ _test_encode_pulled('array_2d', 'One', 'One'); # not found in unchanged
+ _test_encode_pulled('array_2d', 'two', 'Owt');
+ _test_encode_pulled('array_2d', 'symbols&amp;\'"', 'symbols&amp;\'"'); # not found in unchanged
+}
+
+function test_encode_misc() {
+ unit_test_func('enc_tab', '', '');
+ unit_test_func('enc_tab', "\n", "\t\n\t");
+ unit_test_func('enc_tab', "a", "\ta");
+ unit_test_func('enc_tab', "a\n", "\ta\n\t");
+ unit_test_func('enc_tab', "\t", "\t\t");
+ unit_test_func('enc_tab', "\n\na", "\t\n\t\n\ta");
+ unit_test_func('enc_tab', "\t\n\t\n\ta", "\t\t\n\t\t\n\t\ta");
+}
+
+function encode_unit_tests_main() {
+ test_encode_pulled();
+ test_encode_misc();
+}