mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
48 lines
1.8 KiB
PHP
48 lines
1.8 KiB
PHP
<?php
|
|
// Event::EndDateTimeSecs() of an event that is still being recorded. Its
|
|
// EndDateTime is NULL, which was handed straight to strtotime(); PHP 8.1 and
|
|
// later report that as a deprecation, once per call, in the web log. The
|
|
// result is still false, as StartDateTimeSecs() gives for an empty value.
|
|
//
|
|
// Run: php tests/php/test_event_end_datetime_secs.php [root]
|
|
|
|
namespace {
|
|
$root = isset($argv[1]) ? $argv[1] : __DIR__.'/../..';
|
|
$src = file_get_contents($root.'/web/includes/Event.php');
|
|
$start = strpos($src, 'public function EndDateTimeSecs() {');
|
|
$end = strpos($src, 'public function Duration() {', $start);
|
|
$method = rtrim(substr($src, $start, $end - $start));
|
|
eval('class EndSecsHarness { public $EndDateTime = null; '.$method.' }');
|
|
|
|
$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"; }
|
|
}
|
|
|
|
$deprecations = 0;
|
|
set_error_handler(function($no, $msg) use (&$deprecations) {
|
|
if ($no === E_DEPRECATED) $deprecations++;
|
|
return true;
|
|
});
|
|
|
|
$e = new EndSecsHarness();
|
|
$e->EndDateTime = null;
|
|
check('NULL EndDateTime gives false', $e->EndDateTimeSecs(), false);
|
|
check('NULL EndDateTime raises no deprecation', $deprecations, 0);
|
|
|
|
$e->EndDateTime = '';
|
|
check('empty EndDateTime gives false', $e->EndDateTimeSecs(), false);
|
|
|
|
$e->EndDateTime = '2026-11-28 10:15:30';
|
|
check('a date time gives its timestamp', $e->EndDateTimeSecs(), strtotime('2026-11-28 10:15:30'));
|
|
|
|
unset($e->EndDateTime);
|
|
check('a missing EndDateTime gives false', $e->EndDateTimeSecs(), false);
|
|
check('still no deprecation', $deprecations, 0);
|
|
|
|
echo $failures ? "$failures failure(s)\n" : "all passed\n";
|
|
exit($failures ? 1 : 0);
|
|
}
|