MDL-81717 h5p: Improve robustness content type fetching
[moodle.git] / search / tests / event / events_test.php
blob91dfc35dc2b13760c84f44890eb95866e7ce8d81
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Unit tests for search events.
20 * @package core_search
21 * @category phpunit
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;
28 /**
29 * Unit tests for search events.
31 * @package core_search
32 * @category phpunit
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 {
38 /**
39 * test_search_results_viewed
41 * @return void
43 public function test_search_results_viewed() {
45 $this->resetAfterTest();
47 $user = $this->getDataGenerator()->create_user();
48 $this->setUser($user);
50 $sink = $this->redirectEvents();
52 // Basic event.
53 \core_search\manager::trigger_search_results_viewed([
54 'q' => 'I am a query',
55 'page' => 0,
56 ]);
58 $events = $sink->get_events();
59 $event = reset($events);
60 $sink->clear();
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',
69 'page' => 2,
70 'title' => 'I am the title',
71 'areaids' => array(3,4,5),
72 'courseids' => array(2,3),
73 'timestart' => 1445644800,
74 'timeend' => 1477267200
75 ]);
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());