Beispiel #1
0
 /**
  * Test the courses searched.
  *
  * There is no external API for viewing course information so the unit test will simply
  * create and trigger the event and ensure data is returned as expected.
  */
 public function test_courses_searched_event()
 {
     // Trigger an event: courses searched.
     $search = 'mysearch';
     $eventparams = array('context' => context_system::instance(), 'other' => array('query' => $search));
     $event = \core\event\courses_searched::create($eventparams);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\courses_searched', $event);
     $this->assertEquals($search, $event->other['query']);
     $this->assertDebuggingNotCalled();
     $sink->close();
 }
Beispiel #2
0
$strsearch = new lang_string("search");
$strsearchresults = new lang_string("searchresults");
$strnovalidcourses = new lang_string('novalidcourses');
$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
$PAGE->navbar->add($strsearch, new moodle_url('/course/search.php'));
if (!empty($search)) {
    $PAGE->navbar->add(s($search));
}
if (empty($searchcriteria)) {
    // no search criteria specified, print page with just search form
    $PAGE->set_title("{$site->fullname} : {$strsearch}");
} else {
    // this is search results page
    $PAGE->set_title("{$site->fullname} : {$strsearchresults}");
    // Link to manage search results should be visible if user have system or category level capability
    if (can_edit_in_category() || !empty($usercatlist)) {
        $aurl = new moodle_url('/course/management.php', $searchcriteria);
        $searchform = $OUTPUT->single_button($aurl, get_string('managecourses'), 'get');
    } else {
        $searchform = $courserenderer->course_search_form($search, 'navbar');
    }
    $PAGE->set_button($searchform);
    // Trigger event, courses searched.
    $eventparams = array('context' => $PAGE->context, 'other' => array('query' => $search));
    $event = \core\event\courses_searched::create($eventparams);
    $event->trigger();
}
$PAGE->set_heading($site->fullname);
echo $OUTPUT->header();
echo $courserenderer->search_courses($searchcriteria);
echo $OUTPUT->footer();