38 function assert_true($value, $msg=
'', $silent=
false, $fatal=
true)
40 if ($value !==
true) {
42 $msg =
'['.gettype($value).
'] "'.$value.
'" was not TRUE';
44 trigger_exception($msg, $silent, $fatal);
63 function assert_false($value, $msg=
'', $silent=
false, $fatal=
true)
65 if ($value !==
false) {
67 $msg =
'['.gettype($value).
'] "'.$value.
'" was not FALSE';
69 trigger_exception($msg, $silent, $fatal);
88 function assert_null($value, $msg=
'', $silent=
false, $fatal=
true)
90 if (!is_null($value)) {
92 $msg =
'['.gettype($value).
'] "'.$value.
'" was not NULL';
94 trigger_exception($msg, $silent, $fatal);
113 function assert_not_null($value, $msg=
'', $silent=
false, $fatal=
true)
115 if (is_null($value)) {
117 $msg = translate(
'passed_value_was_null');
119 trigger_exception($msg, $silent, $fatal);
138 function assert_empty($value, $msg=
'', $silent=
false, $fatal=
true)
140 if (!empty($value)) {
142 $msg = translate(
'assert_not_empty', gettype($value), $value);
144 trigger_exception($msg, $silent, $fatal);
163 function assert_not_empty($value, $msg=
'', $silent=
false, $fatal=
true)
167 $msg = translate(
'assert_empty', gettype($value), $value);
169 trigger_exception($msg, $silent, $fatal);
193 function assert_equals($test, $expected, $msg=
'', $silent=
false, $fatal=
true)
195 if ($test != $expected) {
196 if (!empty($msg)) $msg .=
' -';
197 $msg .= translate(
'assert_equals', gettype($expected), $expected, gettype($test), $test);
198 trigger_exception($msg, $silent, $fatal);
218 function assert_not_equals($value1, $value2, $msg=
'', $silent=
false, $fatal=
true)
220 if ($value1 == $value2) {
221 if (empty($msg)) $msg = translate(
'assert_not_equal');
222 trigger_exception($msg, $silent, $fatal);
248 function assert_array_contains($test, $expected, $msg=
'', $silent=
false, $fatal=
true)
250 $diff = array_diff($expected, $test);
252 if (!empty($msg)) $msg .=
' -';
253 $msg .= translate(
'assert_contains', print_r($expected,
true), print_r($test,
true));
254 trigger_exception($msg, $silent, $fatal);
279 function assert_array_equals($test, $expected, $msg=
'', $silent=
false, $fatal=
true)
281 if ($test != $expected) {
282 if (!empty($msg)) $msg .=
' -';
283 $msg .= translate(
'assert_contains', print_r($expected,
true), print_r($test,
true));
284 trigger_exception($msg, $silent, $fatal);
307 function assert_isset($test, $msg=
'', $silent=
false, $fatal=
true)
310 if (empty($msg)) $msg = translate(
'assert_isset');
311 trigger_exception($msg, $silent, $fatal);
336 function assert_isset_array_index($test, $index, $msg=
'', $silent=
false, $fatal=
true)
338 assert_type($test,
'array');
340 if (!isset($test[$index])) {
342 $msg = translate(
'assert_isset_array', $index);
344 trigger_exception($msg, $silent, $fatal);
364 function assert_is_a($obj, $class, $msg=
'', $silent=
false, $fatal=
true)
366 if (!($obj instanceof $class)) {
368 $msg = translate(
'assert_object', strtoupper($class));
370 trigger_exception($msg, $silent, $fatal);
390 function assert_type($obj, $type, $msg=
'', $silent=
false, $fatal=
true)
392 if (strtolower(gettype($obj)) != strtolower($type)) {
394 $msg = translate(
'assert_type', gettype($obj), $obj, strtoupper($type));
396 trigger_exception($msg, $silent, $fatal);
420 function assert_valid_db_result($result, $msg=
'', $silent=
false, $fatal=
true)
422 throw new Exception(
'assert_valid_db_result() is obselete, use try...catch instead');
438 function assert_valid_assetid($assetids, $msg=
'', $silent=
false, $fatal=
true)
442 if (!is_array($assetids)) {
443 $assetid_array = Array($assetids);
445 $assetid_array = $assetids;
450 foreach ($assetid_array as $one_id) {
453 if (empty($one_id))
break;
456 if (!is_int($one_id) && !is_string($one_id)) {
460 $current_id = $one_id;
466 $is_int_id = (((string)(
int)$one_id) == $one_id);
468 if ($is_int_id && !($one_id > 0)) {
470 }
else if (!$is_int_id && !preg_match(
'|^[0-9]+:.*$|', $one_id)) {
478 $msg = translate(
'assert_assetid', gettype($current_id), htmlspecialchars($current_id));
480 trigger_exception($msg, $silent, $fatal);
498 function trigger_exception($msg, $silent=
false, $fatal=
false)
500 $error_type = ($fatal) ? E_USER_ERROR : E_USER_WARNING;
502 if (SQ_CONF_DEBUG & 1) {
503 $backtrace = debug_backtrace();
504 $line = $backtrace[1][
'line'];
505 $file = $backtrace[1][
'file'];
507 throw new Exception(
'Assertion failed: '.$msg);
509 trigger_localised_error(
'SYS0270', $error_type, $msg, $line, $file);
512 trigger_localised_error(
'SYS0320', $error_type, $msg);