Пример #1
0
 /**
  * Test prepare_new_moduleinfo_data
  */
 public function test_prepare_new_moduleinfo_data()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $course = self::getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     // Test with a complex module, like assign.
     $assignmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
     $sectionnumber = 1;
     list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $assignmodule->name, $sectionnumber);
     $this->assertEquals($assignmodule, $module);
     $this->assertEquals($coursecontext, $context);
     $this->assertNull($cm);
     // Not cm yet.
     $expecteddata = new stdClass();
     $expecteddata->section = $sectionnumber;
     $expecteddata->visible = 1;
     $expecteddata->course = $course->id;
     $expecteddata->module = $module->id;
     $expecteddata->modulename = $module->name;
     $expecteddata->groupmode = $course->groupmode;
     $expecteddata->groupingid = $course->defaultgroupingid;
     $expecteddata->id = '';
     $expecteddata->instance = '';
     $expecteddata->coursemodule = '';
     $expecteddata->advancedgradingmethod_submissions = '';
     // Not grading methods enabled by default.
     // Unset untestable.
     unset($data->introeditor);
     unset($data->_advancedgradingdata);
     $this->assertEquals($expecteddata, $data);
     // Create a viewer user. Not able to edit.
     $viewer = self::getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($viewer->id, $course->id);
     $this->setUser($viewer);
     $this->expectException('required_capability_exception');
     prepare_new_moduleinfo_data($course, $assignmodule->name, $sectionnumber);
 }
Пример #2
0
    $url->param('return', $return);
}
if (!empty($add)) {
    $section = required_param('section', PARAM_INT);
    $course = required_param('course', PARAM_INT);
    $url->param('add', $add);
    $url->param('section', $section);
    $url->param('course', $course);
    $PAGE->set_url($url);
    $course = $DB->get_record('course', array('id' => $course), '*', MUST_EXIST);
    require_login($course);
    // There is no page for this in the navigation. The closest we'll have is the course section.
    // If the course section isn't displayed on the navigation this will fall back to the course which
    // will be the closest match we have.
    navigation_node::override_active_url(course_get_url($course, $section));
    list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $add, $section);
    $data->return = 0;
    $data->sr = $sectionreturn;
    $data->add = $add;
    if (!empty($type)) {
        //TODO: hopefully will be removed in 2.0
        $data->type = $type;
    }
    $sectionname = get_section_name($course, $cw);
    $fullmodulename = get_string('modulename', $module->name);
    if ($data->section && $course->format != 'site') {
        $heading = new stdClass();
        $heading->what = $fullmodulename;
        $heading->to = $sectionname;
        $pageheading = get_string('addinganewto', 'moodle', $heading);
    } else {