1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 09:55:33 +02:00

MDL-68782 core_contentbank: Improving event unit tests

This commit is contained in:
Amaia Anabitarte 2020-05-20 12:42:11 +02:00
parent 7a460fd5d5
commit 8675e8ae6a
2 changed files with 6 additions and 17 deletions
contentbank/tests/fixtures
lib/tests/event

@ -37,19 +37,6 @@ class contenttype extends \core_contentbank\contenttype {
/** Feature for testing */
const CAN_TEST = 'test';
/**
* Returns the URL where the content will be visualized.
*
* @param content $content The content to delete.
* @return string URL where to visualize the given content.
*/
public function get_view_url(\core_contentbank\content $content): string {
$fileurl = $this->get_file_url($content->get_id());
$url = $fileurl."?forcedownload=1";
return $url;
}
/**
* Returns the HTML code to render the icon for content bank contents.
*

@ -47,17 +47,18 @@ class contentbank_content_viewed_testcase extends \advanced_testcase {
}
/**
* Test the content updated event.
* Test the content viewed event.
*
* @covers ::create_from_record
*/
public function test_content_updated() {
public function test_content_viewed() {
$this->resetAfterTest();
$this->setAdminUser();
// Save the system context.
$systemcontext = \context_system::instance();
$contenttype = new \contenttype_testable\contenttype();
// Create a content bank content.
$generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
@ -66,8 +67,8 @@ class contentbank_content_viewed_testcase extends \advanced_testcase {
// Trigger and capture the content viewed event.
$sink = $this->redirectEvents();
$eventtotrigger = \core\event\contentbank_content_viewed::create_from_record($content->get_content());
$eventtotrigger->trigger();
$result = $contenttype->get_view_content($content);
$this->assertEmpty($result);
$events = $sink->get_events();
$event = reset($events);
@ -75,5 +76,6 @@ class contentbank_content_viewed_testcase extends \advanced_testcase {
// Check that the event data is valid.
$this->assertInstanceOf('\core\event\contentbank_content_viewed', $event);
$this->assertEquals($systemcontext, $event->get_context());
$this->assertEquals($content->get_id(), $event->objectid);
}
}