mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
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>
91 lines
3.5 KiB
PHP
91 lines
3.5 KiB
PHP
<?php
|
|
// ajax/status.php entity=event (polled by the event view when zms moves to
|
|
// another event) formatted EndDateTime without checking it. An event still
|
|
// recording has EndDateTime NULL, so strtotime(null) raised a PHP 8.1
|
|
// deprecation and the formatter was handed false. The event view itself prints
|
|
// an empty End Time for such an event; the ajax answer must match.
|
|
//
|
|
// The formatter stub stands in for IntlDateFormatter, which rejects false.
|
|
// status.php declares functions, so each entity runs in a child php process.
|
|
//
|
|
// Run as: php tests/php/test_status_open_event_end.php
|
|
|
|
namespace ZM {
|
|
function Debug($m) {}
|
|
function Error($m) {}
|
|
|
|
// The event reply now also carries DownloadUrl, built from a ZM\Event. This
|
|
// test is about EndDateTime, so the stub only has to answer the two calls.
|
|
class Event {
|
|
public function __construct($idOrRow = null) {}
|
|
public function Id() { return 7; }
|
|
public function canView() { return true; }
|
|
public function DefaultVideo() { return ''; }
|
|
public function getStreamSrc($args = array(), $querySep = '&') { return ''; }
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
if (!isset($argv[1])) {
|
|
$failures = 0;
|
|
foreach (array('event', 'events') as $entity) {
|
|
passthru(escapeshellarg(PHP_BINARY).' '.escapeshellarg(__FILE__).' '.$entity, $rc);
|
|
if ($rc) $failures++;
|
|
}
|
|
exit($failures ? 1 : 0);
|
|
}
|
|
|
|
class StopRequest extends Exception {}
|
|
|
|
define('ZM_OPT_USE_AUTH', false);
|
|
define('ZM_AUTH_RELAY', 'none');
|
|
define('MYSQL_FMT_DATETIME_SHORT', '%y/%m/%d %H:%i:%S');
|
|
|
|
class FormatterStub {
|
|
public function format($ts) {
|
|
return is_int($ts) ? gmdate('Y-m-d H:i:s', $ts) : false;
|
|
}
|
|
}
|
|
$dateTimeFormatter = new FormatterStub();
|
|
|
|
$failures = 0;
|
|
$deprecations = array();
|
|
set_error_handler(function($no, $str) use (&$deprecations) {
|
|
$deprecations[] = $str;
|
|
return true;
|
|
});
|
|
|
|
function canView($area) { return true; }
|
|
function validJsStr($v) { return (is_null($v) or is_array($v)) ? '' : strip_tags(addslashes($v)); }
|
|
function validInt($v) { return preg_replace('/[^\-\d]/', '', $v); }
|
|
function validCardinal($v) { return is_scalar($v) ? preg_replace('/\D/', '', $v) : ''; }
|
|
function dbFetchOne($sql, $col = null, $params = array()) {
|
|
return array('Id' => 7, 'MonitorId' => 1, 'StartDateTime' => '2026-11-16 10:00:00', 'EndDateTime' => null);
|
|
}
|
|
function dbFetchAll($sql, $col = null, $params = array()) { return array(dbFetchOne($sql)); }
|
|
function ajaxResponse($data = array()) { $GLOBALS['response'] = $data; throw new StopRequest('ok'); }
|
|
function ajaxError($m) { throw new StopRequest($m); }
|
|
|
|
$entity = $argv[1];
|
|
$_REQUEST = array('entity' => $entity, 'id' => '7');
|
|
try {
|
|
// status.php requires includes/log_redact.php relative to web/, as under the web server.
|
|
set_include_path(__DIR__.'/../../web'.PATH_SEPARATOR.get_include_path());
|
|
include __DIR__.'/../../web/ajax/status.php';
|
|
} catch (StopRequest $e) {
|
|
}
|
|
$row = ($entity == 'event') ? $GLOBALS['response']['event'] : $GLOBALS['response']['events'][0];
|
|
$got = $row['EndDateTimeFormatted'];
|
|
if ($got === '' and !$deprecations) {
|
|
echo "ok - $entity: open event has an empty formatted end time\n";
|
|
} else {
|
|
$failures++;
|
|
echo "FAIL - $entity: got ".var_export($got, true).' '.implode('; ', $deprecations)."\n";
|
|
}
|
|
if ($row['StartDateTimeFormatted'] !== '2026-11-16 10:00:00') {
|
|
$failures++;
|
|
echo "FAIL - $entity: start time ".var_export($row['StartDateTimeFormatted'], true)."\n";
|
|
}
|
|
exit($failures ? 1 : 0);
|
|
}
|