Skip to content

Commit

Permalink
MDL-68782 core_contentbank: Improving event unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed May 20, 2020
1 parent 7a460fd commit 8675e8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
13 changes: 0 additions & 13 deletions contentbank/tests/fixtures/testable_contenttype.php
Expand Up @@ -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.
*
Expand Down
10 changes: 6 additions & 4 deletions lib/tests/event/contentbank_content_viewed_test.php
Expand Up @@ -47,17 +47,18 @@ public static function setUpBeforeClass() {
}

/**
* 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');
Expand All @@ -66,14 +67,15 @@ public function test_content_updated() {

// 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);

// 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);
}
}

0 comments on commit 8675e8a

Please sign in to comment.