'LEC-1', 'a' => '', 's' => $now - 3600, 'e' => $now + 3600, 'd' => $examDesc ]); Database::exec('INSERT INTO exams_x_location (examid, locationid) VALUES (100, :lid)', ['lid' => $locationId]); Database::exec('INSERT INTO sat_user (userid, firstname, lastname, email) VALUES (1, "T", "U", "t@u")'); Database::exec('INSERT INTO sat_lecture (lectureid, ownerid, displayname, starttime, endtime, isexam, isenabled) VALUES (:id, 1, :n, :ls, :le, 1, 1)', [ 'id' => 'LEC-1', 'n' => 'Lecture 1', 'ls' => $now - 7200, 'le' => $now + 7200 ]); Database::exec('INSERT INTO sat_lecture_x_location (lectureid, locationid) VALUES (:id, :lid)', ['id' => 'LEC-1', 'lid' => $locationId]); } public function testShowRendersListsAndVisWithPermissions(): void { // Permissions: view on all, edit only for location 2 User::$permissions = ['exams.view' => true, 'exams.edit' => true]; User::$allowedLocations = [2]; $this->seedBasicExamAndLecture(2, 'My Exam'); $_GET = ['action' => 'show']; $_REQUEST = $_GET; $page = new Page_Exams('exams'); $page->preprocess(); $page->render(); $names = array_column(Render::$templates, 'name'); $this->assertContains('page-main-heading', $names); $this->assertContains('page-exams', $names); $this->assertContains('page-exams-vis', $names); // Find page-exams-vis payload and verify JSON fields decode $vis = null; foreach (Render::$templates as $t) { if ($t['name'] === 'page-exams-vis') { $vis = $t; break; } } $this->assertNotNull($vis); $data = $vis['data']; $items = json_decode($data['exams_json'], true); $groups = json_decode($data['rooms_json'], true); $this->assertIsArray($items); $this->assertIsArray($groups); $this->assertNotEmpty($items); $this->assertNotEmpty($groups); $groupIds = array_column($groups, 'id'); $this->assertContains(2, $groupIds); } public function testShowFiltersByViewLocationsAndDisablesEditWhenCannotEditAll(): void { // User can view location 2 but cannot edit location 3 User::$permissions = ['exams.view' => true, 'exams.edit' => false]; User::$allowedLocations = [2]; $this->seedBasicExamAndLecture(3, 'Other Exam'); $_GET = ['action' => 'show']; $_REQUEST = $_GET; $page = new Page_Exams('exams'); $page->preprocess(); $page->render(); // page-exams rows payload should mark edit disabled when user lacks edit perms for locations $tpl = null; foreach (Render::$templates as $t) { if ($t['name'] === 'page-exams') { $tpl = $t; break; } } $this->assertNotNull($tpl); $rows = $tpl['data']['exams'] ?? []; if (!empty($rows)) { $this->assertArrayHasKey('edit', $rows[0]); $this->assertSame('disabled', $rows[0]['edit']['disabled'] ?? ''); } } }