id = $id; $s->data = $data; $r = $s->beforeSave(); return array($r, $s->data); } list($r, $d) = run(false, array('Snapshot' => array('Name' => 'a')), new FakeUser()); check('new snapshot records the user', $d['Snapshot']['CreatedBy'], 5); check('new snapshot records the time', (bool)preg_match('/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/', (string)$d['Snapshot']['CreatedOn']), true); check('beforeSave lets the save go on', $r, true); list($r, $d) = run(false, array('Event' => array(1, 2)), new FakeUser()); check('a snapshot with only events still gets the user', $d['Snapshot']['CreatedBy'], 5); list($r, $d) = run(false, array('Snapshot' => array('Name' => 'a')), null); check('without authentication CreatedBy stays NULL', $d['Snapshot']['CreatedBy'] ?? null, null); check('without authentication CreatedOn is still set', isset($d['Snapshot']['CreatedOn']), true); list($r, $d) = run(3, array('Snapshot' => array('Name' => 'b')), new FakeUser()); check('an edit leaves CreatedBy alone', isset($d['Snapshot']['CreatedBy']), false); check('an edit leaves CreatedOn alone', isset($d['Snapshot']['CreatedOn']), false); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); ?>