diff --git a/tests/php/test_api_associated_ids.php b/tests/php/test_api_associated_ids.php index c69712bc7c..38b05a0585 100644 --- a/tests/php/test_api_associated_ids.php +++ b/tests/php/test_api_associated_ids.php @@ -121,7 +121,8 @@ check('an unrestricted user may replace the list', linksSaved(array(1, 2), array foreach (array('Groups' => array('Group', 'MonitorIds', 'Monitor'), 'Snapshots' => array('Snapshot', 'EventIds', 'Event'), 'Tags' => array('Tag', 'EventIds', 'Event')) as $name => $a) { list($alias, $field, $assoc) = $a; $c = file_get_contents("$controllers/{$name}Controller.php"); - $copy = strpos($c, "\$this->request->data['$assoc'] = explode(',', \$this->request->data['$alias']['$field']);"); + // The ids come from requestField() (flat or nested), then are copied to the association. + $copy = preg_match("/\\\$this->request->data\\['$assoc'\\] = explode\\(',', \\\$\\w+\\);/", $c, $m, PREG_OFFSET_CAPTURE) ? $m[0][1] : false; $first = strpos($c, "requestAssociatedIds('$alias', '$assoc')"); check("$name add copies $field to $assoc before the check", $copy !== false and $first !== false and $copy < $first, true); if ($name != 'Groups') { diff --git a/tests/php/test_assignment_precedence.php b/tests/php/test_assignment_precedence.php index 00fe1e5a8c..39fa1ed46d 100644 --- a/tests/php/test_assignment_precedence.php +++ b/tests/php/test_assignment_precedence.php @@ -161,8 +161,6 @@ echo "nothing new under web/ cuts an assignment short\n"; // -- assigns only Id(), so delete is offered for any // existing filter whether or not the user may edit it. // This one is access control, so it is not mine to guess at. -// console.php:110 $show_storage_areas -- assigns only the count test, so -// the canEdit('System') half never applies. // monitor.php:1483 $stream_available = canView('Stream') and ... or ... // -- assigns only canView('Stream'). The intent is also // ambiguous between A && (B || C) and (A && B) || C, which @@ -175,7 +173,6 @@ $known = array( 'web/skins/classic/views/_options_dnsmasq.php $cfg = ... or', 'web/skins/classic/views/filter.php $canSave = ... or', 'web/skins/classic/views/filter.php $canDelete = ... and', - 'web/skins/classic/views/console.php $show_storage_areas = ... and', 'web/skins/classic/views/monitor.php $stream_available = ... and', ); diff --git a/tests/php/test_control_ptz_command.php b/tests/php/test_control_ptz_command.php index 6ae9686930..4b17f34daf 100644 --- a/tests/php/test_control_ptz_command.php +++ b/tests/php/test_control_ptz_command.php @@ -78,19 +78,24 @@ class MockMonitor { public function Orientation() { return $this->orientation; } public function Width() { return $this->width; } public function Height() { return $this->height; } + // The size of the image the user clicks on: width and height swap when rotated 90 or 270. + private function rotated() { return in_array($this->orientation, array('ROTATE_90', 'ROTATE_270')); } + public function ViewWidth() { return $this->rotated() ? $this->height : $this->width; } + public function ViewHeight() { return $this->rotated() ? $this->width : $this->height; } public function AutoStopTimeout() { return 0; } } // ---------------------------------------------------------------------------- // Test 1: movePseudoMap coordinate factor rotation (ROTATE_90 and ROTATE_270) // ---------------------------------------------------------------------------- -// Monitor 640x480, halfWidth=320, halfHeight=240. -// Click at x=240, y=120: -// unrotated xFactor = (240 - 320)/320 = -0.25, yFactor = (120 - 240)/240 = -0.5 +// Monitor 640x480 rotated 90 or 270 is displayed 480x640, so the click is read against +// halfWidth=240, halfHeight=320 (ViewWidth/ViewHeight). +// Click at x=120, y=160: +// unrotated xFactor = (120 - 240)/240 = -0.5, yFactor = (160 - 320)/320 = -0.5 // ROTATE_90: -// Correct: yFactor = -(-0.25) = 0.25, xFactor = -0.5 -> dirn = 'DownLeft' +// Correct: yFactor = -(-0.5) = 0.5, xFactor = -0.5 -> dirn = 'DownLeft' // Pan step (using |xFactor|=0.5): MinPanStep(1) + (MaxPanStep(10)-1)*0.5 = 1 + 4.5 = 6 (<= 10) -// With bug: $tempYFactor = $y = 120, $xFactor = 120! Pan step becomes 1 + 9*120 = 1081! +// With bug: $tempYFactor = $y = 160, $xFactor = 160! Pan step becomes 1 + 9*160 = 1441! $ctrl = new MockControl(array( 'HasPanSpeed' => 1, 'MinPanSpeed' => 1, 'MaxPanSpeed' => 10, 'HasTurboPan' => 0, 'HasTiltSpeed' => 1, 'MinTiltSpeed' => 1, 'MaxTiltSpeed' => 10, 'HasTurboTilt' => 0, @@ -98,7 +103,7 @@ $ctrl = new MockControl(array( 'MinTiltStep' => 1, 'MaxTiltStep' => 10, )); $mon90 = new MockMonitor('ROTATE_90', $ctrl, 640, 480); -$_REQUEST = array('control' => 'movePseudoMap', 'x' => 240, 'y' => 120, 'scale' => 100); +$_REQUEST = array('control' => 'movePseudoMap', 'x' => 120, 'y' => 160, 'scale' => 100); $cmd = buildControlCommand($mon90); preg_match('/--panstep=(\d+)/', $cmd, $mPan); @@ -107,11 +112,11 @@ check('movePseudoMap ROTATE_90 panstep is within max bounds', ($panStep >= 1 && check('movePseudoMap ROTATE_90 command is moveRelDownLeft', $_REQUEST['control'], 'moveRelDownLeft'); // ROTATE_270: -// Correct: xFactor = -(-0.5) = 0.5, yFactor = -0.25 -> dirn = 'UpRight' -// Tilt step (using |yFactor|=0.25): MinTiltStep(1) + 9*0.25 = 3 (<= 10) -// With bug: $tempXFactor = $x = 240, $yFactor = 240! Tilt step becomes 1 + 9*240 = 2161! +// Correct: xFactor = -(-0.5) = 0.5, yFactor = -0.5 -> dirn = 'UpRight' +// Tilt step (using |yFactor|=0.5): MinTiltStep(1) + 9*0.5 = 5 (<= 10) +// With bug: $tempXFactor = $x = 120, $yFactor = 120! Tilt step becomes 1 + 9*120 = 1081! $mon270 = new MockMonitor('ROTATE_270', $ctrl, 640, 480); -$_REQUEST = array('control' => 'movePseudoMap', 'x' => 240, 'y' => 120, 'scale' => 100); +$_REQUEST = array('control' => 'movePseudoMap', 'x' => 120, 'y' => 160, 'scale' => 100); $cmd = buildControlCommand($mon270); preg_match('/--tiltstep=(\d+)/', $cmd, $mTilt); $tiltStep = isset($mTilt[1]) ? (int)$mTilt[1] : 0; @@ -122,7 +127,7 @@ check('movePseudoMap ROTATE_270 command is moveRelUpRight', $_REQUEST['control'] // Test 2: moveConMap coordinate factor rotation (ROTATE_90 and ROTATE_270) // ---------------------------------------------------------------------------- $mon90 = new MockMonitor('ROTATE_90', $ctrl, 640, 480); -$_REQUEST = array('control' => 'moveConMap', 'x' => 240, 'y' => 120, 'scale' => 100); +$_REQUEST = array('control' => 'moveConMap', 'x' => 120, 'y' => 160, 'scale' => 100); $cmd = buildControlCommand($mon90); preg_match('/--panspeed=(\d+)/', $cmd, $mPanSpeed); $panSpeed = isset($mPanSpeed[1]) ? (int)$mPanSpeed[1] : 0; @@ -130,7 +135,7 @@ check('moveConMap ROTATE_90 panspeed is within max bounds', ($panSpeed >= 1 && $ check('moveConMap ROTATE_90 command is moveConDownLeft', $_REQUEST['control'], 'moveConDownLeft'); $mon270 = new MockMonitor('ROTATE_270', $ctrl, 640, 480); -$_REQUEST = array('control' => 'moveConMap', 'x' => 240, 'y' => 120, 'scale' => 100); +$_REQUEST = array('control' => 'moveConMap', 'x' => 120, 'y' => 160, 'scale' => 100); $cmd = buildControlCommand($mon270); preg_match('/--tiltspeed=(\d+)/', $cmd, $mTiltSpeed); $tiltSpeed = isset($mTiltSpeed[1]) ? (int)$mTiltSpeed[1] : 0; diff --git a/tests/php/test_event_null_start.php b/tests/php/test_event_null_start.php index dfd619abbd..82e6e9af3a 100644 --- a/tests/php/test_event_null_start.php +++ b/tests/php/test_event_null_start.php @@ -64,6 +64,7 @@ class Storage { public static function find_one($params) { return new Storage($params['Id']); } public function Id() { return $this->id; } public function Path() { return '/var/cache/zoneminder/events'; } + public function DoDelete() { return 1; } public function Scheme($s = null) { if ($s) $this->scheme = $s; return $this->scheme; } } diff --git a/tests/php/test_event_writes_require_events_edit.php b/tests/php/test_event_writes_require_events_edit.php index 2b6980bfc0..47a9f559f3 100644 --- a/tests/php/test_event_writes_require_events_edit.php +++ b/tests/php/test_event_writes_require_events_edit.php @@ -35,6 +35,7 @@ namespace ZM { public function DefaultScale() { return 100; } } class Event { + public function Archived() { return 0; } // Object::__construct() takes an array as the row itself, without loading it. private $row = null; public function __construct($id) { if (is_array($id)) $this->row = $id; } @@ -51,7 +52,7 @@ namespace ZM { public function Monitor() { return new Monitor(); } public function Path() { return $GLOBALS['event_path']; } public function DefaultVideo() { return $GLOBALS['default_video'] ?? ''; } - public function delete() { $GLOBALS['queries'][] = 'Event::delete'; } + public function delete() { $GLOBALS['queries'][] = 'Event::delete'; return true; } } } diff --git a/tests/php/test_object_save_error.php b/tests/php/test_object_save_error.php index 870feda04f..ada9ddd03f 100644 --- a/tests/php/test_object_save_error.php +++ b/tests/php/test_object_save_error.php @@ -66,7 +66,7 @@ check('a good save still reports success', $thing2->save(array('Deleted' => true // Monitor::delete() must hand that result back rather than swallow it. $monitor_src = file_get_contents($root.'/web/includes/Monitor.php'); check('Monitor::delete returns the result of the save', - (bool)preg_match('/return \$this->save\(\[\'Deleted\'=>true\]\);/', $monitor_src)); + (bool)preg_match('/\$saved = \$this->save\(\[\'Deleted\'=>true\]\);.*return \$saved;/s', $monitor_src)); // And the console action has to surface it, and not audit a delete that failed. $console_src = file_get_contents($root.'/web/includes/actions/console.php'); diff --git a/tests/php/test_snapshot_create_requires_snapshots_edit.php b/tests/php/test_snapshot_create_requires_snapshots_edit.php index 40955015aa..a448bcf675 100644 --- a/tests/php/test_snapshot_create_requires_snapshots_edit.php +++ b/tests/php/test_snapshot_create_requires_snapshots_edit.php @@ -19,6 +19,7 @@ namespace ZM { public function save($a) { $GLOBALS['done'][] = 'Snapshot::save'; return true; } public function Id() { return 5; } public function Events() { return array(); } + public function EventIds() { return array(1); } } class Snapshot_Event { public function save($a) { $GLOBALS['done'][] = 'Snapshot_Event::save'; return true; }