die; } /** this creates a working environment where we can conduct our tests */ require_once $CFG->progdir . '/init.php'; $tests = array('wastest_dump_cfg' => 'Dump the $CFG object (including database password)', 'wastest_dump_db' => 'Dump the contents of the $DB object (also including passwords)', 'wastest_drop_table' => 'Unconditionally drop the table \'foo\'', 'wastest_create_table' => 'Create table \'foo\' (only a few fields)', 'wastest_fill_table' => 'Add some records to \'foo\'', 'wastest_dump_table' => 'Display all records from \'foo\'', 'wastest_show_tables' => 'Result of MySQL SHOW TABLES', 'wastest_tabledef_dump' => 'Raw dump of a big table definition which excercises create_table() in $Database', 'wastest_tabledef_sql' => 'SQL-version of this big table definition', 'wastest_table_create' => 'Actually create the big table via $DB->create_table()', 'wastest_drop_big_table' => 'Drop the big table again', 'wastest_describe_table' => 'Result of MySQL DESCRIBE tablename (using the big table)', 'wastest_dump_table_description' => 'A neat HTML-table describing tabledefs in a generic way'); echo <<<EOT <html> <head> <title>WAS Test</title> </head> <body> EOT; /* strategy: if they specified a test to do, do it. Then print the test menu (again) */ if (isset($_GET['test'])) { $current_test = $_GET['test']; perform_test($current_test); } else { $current_test = ''; } show_testmenu($current_test); echo <<<EOT </body> </html> EOT; die; /* *================================================================== */ function perform_test($test_to_do) { global $tests;
<?php $all_filters = array('No filters' => array(), 'Require Scalar' => array('flags' => FILTER_REQUIRE_SCALAR), 'Require Array' => array('flags' => FILTER_REQUIRE_ARRAY)); function perform_test($name, $test_filters, $add_empty) { $params = array('null' => NULL, 'empty_array' => array(), 'filled_array' => array(1, 2, 3), 'int' => 1, 'double' => 1.0, 'string' => 'string'); if ($add_empty) { $name .= ', Add empty'; } echo "{$name}\n"; $filters = array_fill_keys(array_keys($params), $test_filters); $filters['missing'] = $test_filters; var_dump(filter_var_array($params, $filters, $add_empty)); } foreach ($all_filters as $test_name => $filter) { perform_test($test_name, $filter, true); perform_test($test_name, $filter, false); }