source: moodle/trunk/fuentes/badges/tests/events_test.php

Last change on this file was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 2.0 KB
Line 
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.
13//
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.
18 *
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
22 */
23defined('MOODLE_INTERNAL') || die();
24global $CFG;
25require_once($CFG->dirroot . '/badges/tests/badgeslib_test.php');
26
27/**
28 * Badge events tests class.
29 *
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
33 */
34class core_badges_events_testcase extends core_badges_badgeslib_testcase {
35
36    /**
37     * Test badge awarded event.
38     */
39    public function test_badge_awarded() {
40
41        $systemcontext = context_system::instance();
42
43        $sink = $this->redirectEvents();
44
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());
55
56        $sink->close();
57    }
58}
Note: See TracBrowser for help on using the repository browser.