2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Unit tests for search events.
20 * @package core_search
22 * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace core_search\event
;
29 * Unit tests for search events.
31 * @package core_search
33 * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class events_test
extends \advanced_testcase
{
39 * test_search_results_viewed
43 public function test_search_results_viewed() {
45 $this->resetAfterTest();
47 $user = $this->getDataGenerator()->create_user();
48 $this->setUser($user);
50 $sink = $this->redirectEvents();
53 \core_search\manager
::trigger_search_results_viewed([
54 'q' => 'I am a query',
58 $events = $sink->get_events();
59 $event = reset($events);
62 $this->assertEquals(\context_system
::instance(), $event->get_context());
64 $urlparams = ['q' => 'I am a query', 'page' => 0];
65 $this->assertEquals($urlparams, $event->get_url()->params());
67 \core_search\manager
::trigger_search_results_viewed([
68 'q' => 'I am a query',
70 'title' => 'I am the title',
71 'areaids' => array(3,4,5),
72 'courseids' => array(2,3),
73 'timestart' => 1445644800,
74 'timeend' => 1477267200
77 $events = $sink->get_events();
78 $event = reset($events);
79 $this->assertEquals(\context_system
::instance(), $event->get_context());
81 $urlparams = ['q' => 'I am a query', 'page' => 2, 'title' => 'I am the title', 'timestart' => 1445644800, 'timeend' => 1477267200];
82 $this->assertEquals($urlparams, $event->get_url()->params());