Skip to content

Commit

Permalink
Merge branch 'MDL-40997-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Aug 5, 2013
2 parents fd6d13b + d6277b0 commit 698be6b
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
4 changes: 4 additions & 0 deletions auth/tests/auth_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function test_user_loggedin_event() {
$this->assertEquals('2', $event->objectid);
$this->assertEquals(context_system::instance()->id, $event->contextid);
$this->assertEquals($user, $event->get_record_snapshot('user', 2));

$this->assertEventLegacyData(null, $event);
$expectedlog = array(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $user->id, 0, $user->id);
$this->assertEventLegacyLogData($expectedlog, $event);
}

public function test_user_loggedin_event_exceptions() {
Expand Down
48 changes: 48 additions & 0 deletions lib/phpunit/classes/advanced_testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,54 @@ public function assertDebuggingNotCalled($message = '') {
$this->assertEquals(0, $count, $message);
}

/**
* Assert that an event legacy data is equal to the expected value.
*
* @param mixed $expected expected data.
* @param \core\event\base $event the event object.
* @param string $message
* @return void
*/
public function assertEventLegacyData($expected, \core\event\base $event, $message = '') {
$legacydata = phpunit_event_mock::testable_get_legacy_eventdata($event);
if ($message === '') {
$message = 'Event legacy data does not match expected value.';
}
$this->assertEquals($expected, $legacydata, $message);
}

/**
* Assert that an event legacy log data is equal to the expected value.
*
* @param mixed $expected expected data.
* @param \core\event\base $event the event object.
* @param string $message
* @return void
*/
public function assertEventLegacyLogData($expected, \core\event\base $event, $message = '') {
$legacydata = phpunit_event_mock::testable_get_legacy_logdata($event);
if ($message === '') {
$message = 'Event legacy log data does not match expected value.';
}
$this->assertEquals($expected, $legacydata, $message);
}

/**
* Assert that an event legacy name is equal to the expected value.
*
* @param mixed $expected expected name.
* @param \core\event\base $event the event object.
* @param string $message
* @return void
*/
public function assertEventLegacyName($expected, \core\event\base $event, $message = '') {
$legacydata = phpunit_event_mock::testable_get_legacy_eventname($event);
if ($message === '') {
$message = 'Event legacy name does not match expected value.';
}
$this->assertEquals($expected, $legacydata, $message);
}

/**
* Starts message redirection.
*
Expand Down
62 changes: 62 additions & 0 deletions lib/phpunit/classes/event_mock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Event mock.
*
* @package core
* @category phpunit
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../../classes/event/base.php');

/**
* Event mock class.
*
* @package core
* @category phpunit
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class phpunit_event_mock extends \core\event\base {

/**
* Returns the log data of the event.
* @return array
*/
public static function testable_get_legacy_eventname($event) {
return $event->get_legacy_eventname();
}

/**
* Returns the log data of the event.
* @return array
*/
public static function testable_get_legacy_eventdata($event) {
return $event->get_legacy_eventdata();
}

/**
* Returns the log data of the event.
* @return array
*/
public static function testable_get_legacy_logdata($event) {
return $event->get_legacy_logdata();
}

}
1 change: 1 addition & 0 deletions lib/phpunit/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require_once('PHPUnit/Extensions/Database/Autoload.php');

require_once(__DIR__.'/classes/util.php');
require_once(__DIR__.'/classes/event_mock.php');
require_once(__DIR__.'/classes/event_sink.php');
require_once(__DIR__.'/classes/message_sink.php');
require_once(__DIR__.'/classes/basic_testcase.php');
Expand Down
1 change: 1 addition & 0 deletions lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public function test_role_assign() {
$this->assertEquals($raid, $event->other['id']);
$this->assertSame('', $event->other['component']);
$this->assertEquals(0, $event->other['itemid']);
$this->assertEventLegacyName('role_assigned', $event);
}

/**
Expand Down

0 comments on commit 698be6b

Please sign in to comment.