MDL-68782 core_contentbank: Improving event unit tests
authorAmaia Anabitarte <amaia@moodle.com>
Wed, 20 May 2020 10:42:11 +0000 (12:42 +0200)
committerAmaia Anabitarte <amaia@moodle.com>
Wed, 20 May 2020 20:37:30 +0000 (22:37 +0200)
contentbank/tests/fixtures/testable_contenttype.php
lib/tests/event/contentbank_content_viewed_test.php

index f279481..a70bccb 100644 (file)
@@ -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.
      *
index acc7e53..3cf66de 100644 (file)
@@ -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);
     }
 }