getMessage().")\n"; return; } check($name, $got, $want); } class FakePermission { private $mid, $p; function __construct($mid, $p) { $this->mid = $mid; $this->p = $p; } function Permission() { return $this->p; } function MonitorId() { return $this->mid; } } class FakeGroup { private $name; function __construct($name) { $this->name = $name; } function Name() { return $this->name; } } class FakeGroupPermission { private $value, $group; function __construct($value, $group) { $this->value = $value; $this->group = new FakeGroup($group); } function MonitorPermission($mid) { return $this->value; } function Group() { return $this->group; } } class FakeUser implements ArrayAccess { public $id, $monitors, $own = null, $groups = array(); function __construct($id, $monitors) { $this->id = $id; $this->monitors = $monitors; } function Id() { return $this->id; } function Monitors() { return $this->monitors; } function Monitor_Permission($mid) { return $this->own; } function Group_Permissions() { return $this->groups; } #[\ReturnTypeWillChange] function offsetGet($offset) { return $offset === 'Monitors' ? $this->monitors : null; } #[\ReturnTypeWillChange] function offsetExists($offset) { return true; } #[\ReturnTypeWillChange] function offsetSet($offset, $value) {} #[\ReturnTypeWillChange] function offsetUnset($offset) {} } function editableMonitor($mid) { return false; } eval('namespace ZM; class CanEditHarness { public $Id = 3; function Id() { return $this->Id; } '.$method.' }'); $user = new FakeUser(1, 'Edit'); // the logged-in admin looking at the monitor $m = new ZM\CanEditHarness(); $u = new FakeUser(2, 'None'); $u->groups = array(new FakeGroupPermission('Edit', 'Front')); attempt('Monitors=None with a group Edit grants edit', function() use ($m, $u) { return $m->canEdit($u); }, true); $u = new FakeUser(2, 'Edit'); $u->groups = array(new FakeGroupPermission('None', 'Front')); attempt('Monitors=Edit with a group None refuses', function() use ($m, $u) { return $m->canEdit($u); }, false); $u = new FakeUser(2, 'Edit'); $u->groups = array(new FakeGroupPermission('View', 'Front')); attempt('a group View does not deny edit', function() use ($m, $u) { return $m->canEdit($u); }, true); $u = new FakeUser(2, 'None'); $u->groups = array(new FakeGroupPermission('View', 'Front')); attempt('Monitors=None with a group View refuses', function() use ($m, $u) { return $m->canEdit($u); }, false); $u = new FakeUser(2, 'Edit'); attempt('Monitors=Edit with no group permissions grants edit', function() use ($m, $u) { return $m->canEdit($u); }, true); $u = new FakeUser(2, 'None'); attempt('Monitors=None with no group permissions refuses', function() use ($m, $u) { return $m->canEdit($u); }, false); $u = new FakeUser(2, 'Edit'); $u->own = new FakePermission(3, 'View'); attempt('own View on the monitor refuses edit', function() use ($m, $u) { return $m->canEdit($u); }, false); $u = new FakeUser(2, 'None'); $u->groups = array(new FakeGroupPermission('View', 'Front'), new FakeGroupPermission('Edit', 'Back')); attempt('any group Edit grants edit', function() use ($m, $u) { return $m->canEdit($u); }, true); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); }