mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
* test: PHP test stubs know the helpers and include path merged code now uses Twenty tests in tests/php failed on master after PRs that each passed on their own landed together: code under test started calling a helper, or loading a file, that these tests' stand-ins didn't provide. - validCardinal(): actions/group.php, actions/controlcap.php and ajax/reports.php deleteRequest() reduce request ids with it (#7800). The five group save tests, the controlcap test and the reports delete test now carry a copy of it. - ZM\scalar_values_differ(): Object.php changes() compares with it (#7774). The group, storage, user and zmtrack tests that load Object.php now carry a copy. - authHashTtl(): generateAuthHash() takes its freshness limit from it (#8367). test_auth_hash_slot_age lifts it out of auth.php alongside generateAuthHash(). - includes/log_redact.php: ajax/status.php requires it relative to web/ (#7930). The five status tests put web/ on the include path before including status.php, as the web server's working directory does. - test_reports_ajax_forged_id: deleteRequest() now reports a delete() that returns false (#7820), and the stub Report::delete() returned nothing, so it returns true. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: filter text test lifts filterSelectionScalars() with getFilterSelection() getFilterSelection() in _monitor_filters.php now passes request and cookie values through filterSelectionScalars() (#8455), so the test has to evaluate that function too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
// The reports delete branch used to call $report->delete() and ignore its result, so a
|
|
// failed DELETE was reported as success. deleteRequest() now reports the failure like
|
|
// snapshots.php does. The function is extracted from the ajax script (which cannot be
|
|
// included because of its top-level request handling) and run against a stub Report.
|
|
//
|
|
// Run as: php tests/php/test_ajax_reports_delete_result.php [root] (root defaults to the repo)
|
|
|
|
namespace ZM {
|
|
class Report {
|
|
private $id;
|
|
public function __construct($id) {
|
|
$this->id = ((int)$id === 0) ? 0 : $id;
|
|
}
|
|
public function Id() { return $this->id; }
|
|
public function canEdit() { return $GLOBALS['reportCanEdit']; }
|
|
public function delete() { return $GLOBALS['reportDeleteResult']; }
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
$failures = 0;
|
|
|
|
function check($name, $got, $want) {
|
|
global $failures;
|
|
if ($got === $want) {
|
|
echo "ok - $name\n";
|
|
} else {
|
|
$failures++;
|
|
echo "FAIL - $name (got ".var_export($got, true).", want ".var_export($want, true).")\n";
|
|
}
|
|
}
|
|
|
|
// Copied from web/includes/functions.php.
|
|
function validCardinal($input) {
|
|
if (!is_scalar($input)) return '';
|
|
return preg_replace('/\D/', '', $input);
|
|
}
|
|
|
|
$root = isset($argv[1]) ? $argv[1] : __DIR__.'/../..';
|
|
$path = $root.'/web/ajax/reports.php';
|
|
$src = file_get_contents($path);
|
|
if (!preg_match('/^function deleteRequest\(.*?\n\}/ms', $src, $m)) {
|
|
echo "Could not find deleteRequest() in $path\n";
|
|
exit(1);
|
|
}
|
|
eval($m[0]);
|
|
|
|
$GLOBALS['reportCanEdit'] = true;
|
|
$GLOBALS['reportDeleteResult'] = true;
|
|
check('a delete that works reports nothing', deleteRequest(4), array());
|
|
|
|
$GLOBALS['reportDeleteResult'] = false;
|
|
$messages = deleteRequest(4);
|
|
check('a failed delete is reported', count($messages) > 0, true);
|
|
check('a failed delete mentions the report id', strpos(implode(' ', $messages), '4') !== false, true);
|
|
|
|
$GLOBALS['reportDeleteResult'] = true;
|
|
check('a missing report is reported', deleteRequest(0), array('Report not found.'));
|
|
|
|
$GLOBALS['reportCanEdit'] = false;
|
|
$messages = deleteRequest(7);
|
|
check('a denied delete reports one message', count($messages), 1);
|
|
check('a denied delete mentions permission', strpos($messages[0], 'You do not have permission') === 0, true);
|
|
|
|
echo $failures ? "\n$failures failed\n" : "\nall passed\n";
|
|
exit($failures ? 1 : 0);
|
|
}
|