Files
zoneminder/tests/php/test_storage_unicode_name.php
T
Isaac ConnorandClaude Opus 5.5 af00ba10c8 test: PHP test stubs know the helpers and include path merged code now uses (#8468)
* 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>
2026-11-27 18:43:21 -05:00

56 lines
2.0 KiB
PHP

<?php
// A storage Name or Path with non-ASCII letters must not be stripped by the
// input filter, while punctuation outside the allowed set still is.
//
// Run as: php tests/php/test_storage_unicode_name.php
namespace ZM;
$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";
}
}
$stubdir = sys_get_temp_dir().'/zm_storage_unicode_stubs_'.getmypid();
@mkdir($stubdir, 0700, true);
foreach (array('database.php', 'Event.php') as $stub) {
file_put_contents($stubdir.'/'.$stub, "<?php\n");
}
set_include_path($stubdir.PATH_SEPARATOR.__DIR__.'/../../web/includes'.PATH_SEPARATOR.get_include_path());
define('ZM_DIR_EVENTS', '/var/cache/zoneminder/events');
function Warning($s) {}
function Error($s) {}
function Debug($s) {}
// Copied from web/includes/functions.php; Object.php changes() calls it.
function scalar_values_differ($old, $new) {
if (is_array($old) or is_array($new)) {
return $old != $new;
}
if (is_bool($old)) $old = (int)$old;
if (is_bool($new)) $new = (int)$new;
return (string)($old === null ? '' : $old) !== (string)($new === null ? '' : $new);
}
require_once 'Storage.php';
$storage = new Storage();
$changes = $storage->changes(array('Name' => "\u{0425}\u{0440}\u{0430}\u{043D}\u{0438}\u{043B}\u{0438}\u{0449}\u{0435}", 'Path' => '/mnt/josé/cam/'));
check('cyrillic name kept', $changes['Name'], "\u{0425}\u{0440}\u{0430}\u{043D}\u{0438}\u{043B}\u{0438}\u{0449}\u{0435}");
check('accented path kept, trailing slash removed', $changes['Path'], '/mnt/josé/cam');
$changes = $storage->changes(array('Name' => 'Cam #1', 'Path' => '/mnt/a+b'));
check('ascii punctuation still stripped from name', $changes['Name'], 'Cam 1');
check('ascii punctuation still stripped from path', $changes['Path'], '/mnt/ab');
array_map('unlink', glob($stubdir.'/*'));
rmdir($stubdir);
exit($failures ? 1 : 0);