/** * Set a fake page layout. Used when we test URL generation. * @param int $id assumed attempt id. * @param string $layout layout to set. Like quiz attempt.layout. E.g. '1,2,0,3,4,0,'. * @param array $infos slot numbers which contain 'descriptions', or other non-questions. * @return quiz_attempt attempt object for use in unit tests. */ public static function setup_fake_attempt_layout($id, $layout, $infos = array()) { $attempt = new stdClass(); $attempt->id = $id; $attempt->layout = $layout; $course = new stdClass(); $quiz = new stdClass(); $cm = new stdClass(); $cm->id = 0; $attemptobj = new self($attempt, $quiz, $cm, $course, false); $attemptobj->slots = array(); foreach (explode(',', $layout) as $slot) { if ($slot == 0) { continue; } $attemptobj->slots[$slot] = new stdClass(); $attemptobj->slots[$slot]->slot = $slot; $attemptobj->slots[$slot]->requireprevious = 0; $attemptobj->slots[$slot]->questionid = 0; } $attemptobj->sections = array(); $attemptobj->sections[0] = new stdClass(); $attemptobj->sections[0]->heading = ''; $attemptobj->sections[0]->firstslot = 1; $attemptobj->sections[0]->shufflequestions = 0; $attemptobj->infos = $infos; $attemptobj->link_sections_and_slots(); $attemptobj->determine_layout(); $attemptobj->number_questions(); return $attemptobj; }