Merge branch 'MDL-51402' of git://github.com/timhunt/moodle
[moodle.git] / badges / tests / events_test.php
blob833cf0974886abf0f3abf41a0e8a70a5bbae84ff
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/>.
16 /**
17 * Badge events tests.
19 * @package core_badges
20 * @copyright 2015 onwards Simey Lameze <simey@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 defined('MOODLE_INTERNAL') || die();
24 global $CFG;
25 require_once($CFG->dirroot . '/badges/tests/badgeslib_test.php');
27 /**
28 * Badge events tests class.
30 * @package core_badges
31 * @copyright 2015 onwards Simey Lameze <simey@moodle.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_badges_events_testcase extends core_badges_badgeslib_testcase {
36 /**
37 * Test badge awarded event.
39 public function test_badge_awarded() {
41 $systemcontext = context_system::instance();
43 $sink = $this->redirectEvents();
45 $badge = new badge($this->badgeid);
46 $badge->issue($this->user->id, true);
47 $badge->is_issued($this->user->id);
48 $events = $sink->get_events();
49 $this->assertCount(1, $events);
50 $event = reset($events);
51 $this->assertInstanceOf('\core\event\badge_awarded', $event);
52 $this->assertEquals($this->badgeid, $event->objectid);
53 $this->assertEquals($this->user->id, $event->relateduserid);
54 $this->assertEquals($systemcontext, $event->get_context());
56 $sink->close();