mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
43 lines
1.7 KiB
PHP
43 lines
1.7 KiB
PHP
<?php
|
|
// A zone added through the API without a Name, and a zone preset added with no Name or a blank one,
|
|
// were saved with an empty name, because the Zone Name rule was not required on create and
|
|
// ZonePreset had no rules at all. A preset's Name could also be blanked by an edit. Name is now
|
|
// required on create for both and a blank Name is refused, as the zone editor does when it saves
|
|
// a preset. An edit that leaves Name out is still accepted.
|
|
//
|
|
// Source check of the model rules:
|
|
// php tests/php/test_api_zone_name_required.php
|
|
|
|
class App { public static function uses($class, $package) {} }
|
|
class AppModel {}
|
|
|
|
$root = __DIR__.'/../..';
|
|
foreach (array('Zone', 'ZonePreset') as $c) require_once $root.'/web/api/app/Model/'.$c.'.php';
|
|
|
|
$passes = 0;
|
|
$failures = 0;
|
|
function check($ok, $what) {
|
|
global $passes, $failures;
|
|
if ($ok) { $passes++; echo "ok - $what\n"; } else { $failures++; echo "not ok - $what\n"; }
|
|
}
|
|
|
|
foreach (array('Zone', 'ZonePreset') as $class) {
|
|
$model = new $class();
|
|
$rules = isset($model->validate['Name']) ? $model->validate['Name'] : array();
|
|
$blank = array();
|
|
$required = array();
|
|
foreach ($rules as $rule) {
|
|
if (isset($rule['rule']) and (($rule['rule'] === 'notBlank') or (is_array($rule['rule']) and $rule['rule'][0] === 'notBlank'))) {
|
|
$blank[] = $rule;
|
|
if (isset($rule['required'])) $required[] = $rule['required'];
|
|
}
|
|
}
|
|
check(count($blank) > 0, "$class refuses a blank Name");
|
|
check(in_array('create', $required, true), "$class requires Name on create");
|
|
check(!in_array(true, $required, true), "$class does not require Name on edit");
|
|
}
|
|
|
|
echo "\n$passes passed, $failures failed\n";
|
|
exit($failures ? 1 : 0);
|
|
?>
|