MDL-40997 phpunit: Assertions for events legacy data

This commit is contained in:
Frederic Massart
2013-08-02 18:30:02 +08:00
parent a31e811563
commit d6277b0ca0
5 changed files with 116 additions and 0 deletions
+48
View File
@@ -306,6 +306,54 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
$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.
*
+62
View File
@@ -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();
}
}