MDL-40912 coursecat: replaced 'add' add_to_log call with an event
[moodle.git] / lib / tests / events_test.php
CommitLineData
03ea10e6
MN
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/**
18 * Events tests.
19 *
20 * @package core
21 * @category test
22 * @copyright 2014 Mark Nelson <markn@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28class core_events_testcase extends advanced_testcase {
29
30 /**
31 * Test set up.
32 *
33 * This is executed before running any test in this file.
34 */
35 public function setUp() {
36 $this->resetAfterTest();
37 }
38
39 /**
40 * Test the course category created event.
41 */
42 public function test_course_category_created() {
43 // Trigger and capture the event.
44 $sink = $this->redirectEvents();
45 $category = $this->getDataGenerator()->create_category();
46 $events = $sink->get_events();
47 $event = reset($events);
48
49 // Check that the event data is valid.
50 $this->assertInstanceOf('\core\event\course_category_created', $event);
51 $this->assertEquals(context_coursecat::instance($category->id), $event->get_context());
52 $expected = array(SITEID, 'category', 'add', 'editcategory.php?id=' . $category->id, $category->id);
53 $this->assertEventLegacyLogData($expected, $event);
54 }
55}