public function test_gradebookaccess_gradesnotavailableforstuds()
 {
     global $DB, $PAGE;
     $this->resetAfterTest(true);
     // Get the id for the necessary roles.
     $studentrole = $DB->get_field('role', 'id', array('shortname' => 'student'));
     $editteacherrole = $DB->get_field('role', 'id', array('shortname' => 'editingteacher'));
     // Create a course with grades disabled to students.
     $course2 = $this->getDataGenerator()->create_course(array('showgrades' => 0));
     $PAGE->set_course($course2);
     // This becomes necessary because gradebook_accessible depends on $COURSE.
     // Create two users.
     $student = $this->getDataGenerator()->create_user();
     $teacher = $this->getDataGenerator()->create_user();
     // Enrol users to created course.
     $this->getDataGenerator()->enrol_user($student->id, $course2->id, $studentrole);
     $this->getDataGenerator()->enrol_user($teacher->id, $course2->id, $editteacherrole);
     $this->setUser($teacher);
     // Set the teacher as active user.
     // Check functionality of gradebook_accessible.
     $coursecontext = context_course::instance($course2->id);
     $isavailable = shared::gradebook_accessible($coursecontext);
     $this->assertTrue($isavailable);
     $this->setUser($student);
     // Set the student as active user.
     $isavailable = shared::gradebook_accessible($coursecontext);
     $this->assertFalse($isavailable);
     // As long as showgrades is not active, mustn't be available for studs.
 }