array('x'), 'limit' => array('y')); list($offset, $limit) = run_validation($code); $problems = array(); if (!empty($GLOBALS['php_errors'])) { $problems[] = 'php errors: ' . implode('; ', $GLOBALS['php_errors']); } if ($offset != 0) $problems[] = "\$offset is ".var_export($offset, true); if ($limit != 0) $problems[] = "\$limit is ".var_export($limit, true); if (count($GLOBALS['errors']) != 2) { $problems[] = count($GLOBALS['errors']).' ZM\\Error messages'; } foreach ($GLOBALS['errors'] as $m) { if (strpos($m, 'Array') !== false) $problems[] = "message mentions Array: $m"; } if ($problems) { $failures++; echo "FAIL - $name: array offset and limit rejected - ".implode(', ', $problems)."\n"; } else { echo "ok - $name: array offset and limit rejected\n"; } // Case 2: scalar digits are accepted without any errors. $GLOBALS['errors'] = array(); $GLOBALS['php_errors'] = array(); $_REQUEST = array('offset' => '5', 'limit' => '20'); list($offset, $limit) = run_validation($code); $problems = array(); if ($offset != 5) $problems[] = "\$offset is ".var_export($offset, true); if ($limit != 20) $problems[] = "\$limit is ".var_export($limit, true); if (!empty($GLOBALS['errors'])) { $problems[] = count($GLOBALS['errors']).' ZM\\Error messages'; } if (!empty($GLOBALS['php_errors'])) { $problems[] = 'php errors: ' . implode('; ', $GLOBALS['php_errors']); } if ($problems) { $failures++; echo "FAIL - $name: scalar offset and limit accepted - ".implode(', ', $problems)."\n"; } else { echo "ok - $name: scalar offset and limit accepted\n"; } // Case 3: non-numeric offset and negative limit are rejected. $GLOBALS['errors'] = array(); $GLOBALS['php_errors'] = array(); $_REQUEST = array('offset' => 'abc', 'limit' => '-1'); list($offset, $limit) = run_validation($code); $problems = array(); if ($offset != 0) $problems[] = "\$offset is ".var_export($offset, true); if ($limit != 0) $problems[] = "\$limit is ".var_export($limit, true); if (count($GLOBALS['errors']) != 2) { $problems[] = count($GLOBALS['errors']).' ZM\\Error messages'; } if ($problems) { $failures++; echo "FAIL - $name: non-numeric offset and negative limit rejected - ".implode(', ', $problems)."\n"; } else { echo "ok - $name: non-numeric offset and negative limit rejected\n"; } } echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); }