Skip to content

Commit

Permalink
MDL-40912 coursecat: replaced 'hide' and 'show' add_to_log calls with…
Browse files Browse the repository at this point in the history
… an event
  • Loading branch information
mdjnelson committed Jan 15, 2014
1 parent d86c720 commit 001f095
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/coursecatlib.php
Expand Up @@ -1998,7 +1998,13 @@ protected function hide_raw($visibleold = 0) {
public function hide() {
if ($this->hide_raw(0)) {
cache_helper::purge_by_event('changesincoursecat');
add_to_log(SITEID, "category", "hide", "editcategory.php?id=$this->id", $this->id);

$event = \core\event\course_category_updated::create(array(
'objectid' => $this->id,
'context' => $this->get_context()
));
$event->set_legacy_logdata(array(SITEID, 'category', 'hide', 'editcategory.php?id=' . $this->id, $this->id));
$event->trigger();
}
}

Expand Down Expand Up @@ -2051,7 +2057,13 @@ protected function show_raw() {
public function show() {
if ($this->show_raw()) {
cache_helper::purge_by_event('changesincoursecat');
add_to_log(SITEID, "category", "show", "editcategory.php?id=$this->id", $this->id);

$event = \core\event\course_category_updated::create(array(
'objectid' => $this->id,
'context' => $this->get_context()
));
$event->set_legacy_logdata(array(SITEID, 'category', 'show', 'editcategory.php?id=' . $this->id, $this->id));
$event->trigger();
}
}

Expand Down
24 changes: 24 additions & 0 deletions lib/tests/events_test.php
Expand Up @@ -115,5 +115,29 @@ public function test_course_category_updated() {
$this->assertEquals(context_coursecat::instance($childcat->id), $event->get_context());
$expected = array(SITEID, 'category', 'move', 'editcategory.php?id=' . $childcat->id, $childcat->id);
$this->assertEventLegacyLogData($expected, $event);

// Trigger and capture the event for hiding a category.
$sink = $this->redirectEvents();
$category2->hide();
$events = $sink->get_events();
$event = reset($events);

// Check that the event data is valid.
$this->assertInstanceOf('\core\event\course_category_updated', $event);
$this->assertEquals(context_coursecat::instance($category2->id), $event->get_context());
$expected = array(SITEID, 'category', 'hide', 'editcategory.php?id=' . $category2->id, $category2->id);
$this->assertEventLegacyLogData($expected, $event);

// Trigger and capture the event for unhiding a category.
$sink = $this->redirectEvents();
$category2->show();
$events = $sink->get_events();
$event = reset($events);

// Check that the event data is valid.
$this->assertInstanceOf('\core\event\course_category_updated', $event);
$this->assertEquals(context_coursecat::instance($category2->id), $event->get_context());
$expected = array(SITEID, 'category', 'show', 'editcategory.php?id=' . $category2->id, $category2->id);
$this->assertEventLegacyLogData($expected, $event);
}
}

0 comments on commit 001f095

Please sign in to comment.