Merge branch 'wip-MDL-45218-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Marina Glancy 2014-04-23 14:33:12 +08:00
commit cae96c6217
4 changed files with 229 additions and 7 deletions

View file

@ -159,12 +159,16 @@ class core_event_testcase extends advanced_testcase {
$observer->priority = 200;
$observer->internal = false;
$observer->includefile = null;
$observer->plugintype = null;
$observer->plugin = null;
$expected[0] = $observer;
$observer = new stdClass();
$observer->callable = '\core_tests\event\unittest_observer::observe_one';
$observer->priority = 0;
$observer->internal = true;
$observer->includefile = $CFG->dirroot.'/lib/tests/fixtures/event_fixtures.php';
$observer->plugintype = null;
$observer->plugin = null;
$expected[1] = $observer;
$this->assertEquals($expected, $result['\core_tests\event\unittest_executed']);
@ -175,6 +179,8 @@ class core_event_testcase extends advanced_testcase {
$observer->priority = 100;
$observer->internal = true;
$observer->includefile = null;
$observer->plugintype = null;
$observer->plugin = null;
$expected[0] = $observer;
$this->assertEquals($expected, $result['\core\event\unknown_executed']);
@ -185,12 +191,16 @@ class core_event_testcase extends advanced_testcase {
$observer->priority = 10;
$observer->internal = true;
$observer->includefile = null;
$observer->plugintype = null;
$observer->plugin = null;
$expected[0] = $observer;
$observer = new stdClass();
$observer->callable = array('\core_tests\event\unittest_observer', 'observe_all_alt');
$observer->priority = 0;
$observer->internal = true;
$observer->includefile = null;
$observer->plugintype = null;
$observer->plugin = null;
$expected[1] = $observer;
$this->assertEquals($expected, $result['\core\event\base']);
@ -213,6 +223,8 @@ class core_event_testcase extends advanced_testcase {
$observer->priority = 0;
$observer->internal = true;
$observer->includefile = $CFG->dirroot.'/lib/tests/fixtures/event_fixtures.php';
$observer->plugintype = null;
$observer->plugin = null;
$expected[0] = $observer;
$this->assertEquals($expected, $result['\core_tests\event\unittest_executed']);
@ -749,4 +761,72 @@ class core_event_testcase extends advanced_testcase {
phpunit_event_mock::testable_set_event_context($event, null);
$this->assertEventContextNotUsed($event);
}
/**
* Test that all observer information is returned correctly.
*/
public function test_get_all_observers() {
// Retrieve all observers.
$observers = \core\event\manager::get_all_observers();
// Expected information from the workshop allocation scheduled observer.
$expected = array();
$observer = new stdClass();
$observer->callable = '\workshopallocation_scheduled\observer::workshop_viewed';
$observer->priority = 0;
$observer->internal = true;
$observer->includefile = null;
$observer->plugintype = 'workshopallocation';
$observer->plugin = 'scheduled';
$expected[0] = $observer;
$this->assertEquals($expected, $observers['\mod_workshop\event\course_module_viewed']);
}
/**
* Test formatting of the get_explanation method.
* This formats the information from an events class docblock.
*/
public function test_get_explanation() {
$explanation = \core_tests\event\full_docblock::get_explanation();
$expected = "This is an explanation of the event.
- I'm making a point here.
- I have a second {@link something} point here.
- whitespace is intentional to test it's removal.
I have something else *Yeah* that.";
$this->assertEquals($explanation, $expected);
$explanation = \core_tests\event\docblock_test2::get_explanation();
$expected = "We have only the description in the docblock
and nothing else.";
$this->assertEquals($explanation, $expected);
$explanation = \core_tests\event\docblock_test3::get_explanation();
$expected = "Calendar event created event.";
$this->assertEquals($explanation, $expected);
}
/**
* Test that general information about an event is returned
* by the get_static_info() method.
*/
public function test_get_static_info() {
$staticinfo = \core_tests\event\static_info_viewing::get_static_info();
$expected = array(
'eventname' => '\\core_tests\\event\\static_info_viewing',
'component' => 'core_tests',
'target' => 'static_info',
'action' => 'viewing',
'crud' => 'r',
'edulevel' => 0,
'objecttable' => 'mod_unittest'
);
$this->assertEquals($staticinfo, $expected);
}
}

View file

@ -276,3 +276,66 @@ class context_used_in_event extends \core\event\base {
return array($this->data['courseid'], 'core_unittest', 'view', 'unittest.php?id=' . $this->context->instanceid);
}
}
/**
* This is an explanation of the event.
* - I'm making a point here.
* - I have a second {@link something} point here.
* - whitespace is intentional to test it's removal.
*
*
* I have something else *Yeah* that.
*
*
*
* @package core
* @category phpunit
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class full_docblock extends \core\event\base {
protected function init() {
}
}
/**
* We have only the description in the docblock
* and nothing else.
*/
class docblock_test2 extends \core\event\base {
protected function init() {
}
}
/**
* Calendar event created event.
*
* @property-read array $other Extra information about the event.
* -int timestart: timestamp for event time start.
* -string name: Name of the event.
* -int repeatid: Id of the parent event if present, else 0.
*
* @package core
* @since Moodle 2.7
* @copyright 2014 onwards Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class docblock_test3 extends \core\event\base {
protected function init() {
}
}
class static_info_viewing extends \core\event\base {
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'mod_unittest';
}
}