Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 23... Línea 23...
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
24
 */
Línea 25... Línea 25...
25
 
25
 
Línea -... Línea 26...
-
 
26
namespace core\event;
-
 
27
 
26
namespace core\event;
28
use context_system;
27
 
29
 
28
/**
30
/**
29
 * Test for draft file added event.
31
 * Test for draft file added event.
30
 *
32
 *
31
 * @package   core
33
 * @package   core
32
 * @category  test
34
 * @category  test
33
 * @copyright 2023 The Open University.
35
 * @copyright 2023 The Open University.
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 * @covers    \core\event\draft_file_added
37
 * @covers    \core\event\draft_file_added
36
 */
38
 */
37
class draft_file_added_test extends \advanced_testcase {
39
final class draft_file_added_test extends \advanced_testcase {
38
    /**
40
    /**
39
     * Test draft file added event.
41
     * Test draft file added event.
40
     */
42
     */
Línea 59... Línea 61...
59
        $originalfile = $fs->create_file_from_string($filerecord, 'Test content');
61
        $originalfile = $fs->create_file_from_string($filerecord, 'Test content');
60
        $nbsp = "\xc2\xa0";
62
        $nbsp = "\xc2\xa0";
Línea 61... Línea 63...
61
 
63
 
62
        // Event data for logging.
64
        // Event data for logging.
63
        $eventdata = [
65
        $eventdata = [
64
                'objectid' => $originalfile->get_id(),
66
            'objectid' => $originalfile->get_id(),
65
                'context' => $usercontext,
67
            'context' => $usercontext,
66
                'other' => [
68
            'other' => [
67
                        'itemid' => $originalfile->get_itemid(),
69
                'itemid' => $originalfile->get_itemid(),
68
                        'filename' => $originalfile->get_filename(),
70
                'filename' => $originalfile->get_filename(),
69
                        'filesize' => $originalfile->get_filesize(),
71
                'filesize' => $originalfile->get_filesize(),
70
                        'filepath' => $originalfile->get_filepath(),
72
                'filepath' => $originalfile->get_filepath(),
-
 
73
                'contenthash' => $originalfile->get_contenthash(),
71
                        'contenthash' => $originalfile->get_contenthash(),
74
                'avscantime' => '1.234',
72
                ]
75
            ],
73
        ];
76
        ];
74
        $event = \core\event\draft_file_added::create($eventdata);
77
        $event = draft_file_added::create($eventdata);
Línea 75... Línea 78...
75
        $event->trigger();
78
        $event->trigger();
76
 
79
 
77
        $events = $sink->get_events();
80
        $events = $sink->get_events();
Línea 78... Línea 81...
78
        $this->assertCount(1, $events);
81
        $this->assertCount(1, $events);
79
        $event = reset($events);
82
        $event = reset($events);
80
 
83
 
81
        $this->assertEquals($usercontext, $event->get_context());
84
        $this->assertEquals($usercontext, $event->get_context());
-
 
85
        $expected = "The user with id '{$user->id}' has uploaded file '/test.txt' to the draft file area with item id 0. ".
-
 
86
            "Size: 12{$nbsp}bytes. Content hash: {$originalfile->get_contenthash()}.";
-
 
87
        $this->assertSame($expected, $event->get_description());
-
 
88
        $this->assertSame(1.234, $event->other['avscantime']);
-
 
89
    }
-
 
90
 
-
 
91
    public function test_avscantime_optional(): void {
-
 
92
        $eventdata = [
-
 
93
            'objectid' => 123,
-
 
94
            'context' => context_system::instance(),
-
 
95
            'other' => [
-
 
96
                'itemid' => 789,
-
 
97
                'filename' => 'test.txt',
-
 
98
                'filesize' => 42,
-
 
99
                'filepath' => '/',
-
 
100
                'contenthash' => 'a2653cc92420a875358f09942e4b4665351fa49b',
-
 
101
            ],
-
 
102
        ];
-
 
103
        $event = draft_file_added::create($eventdata);
-
 
104
        $event->trigger();
-
 
105
 
-
 
106
        // Mainly, we are asserting that creating the event does not throw an exception.
-
 
107
        $this->assertInstanceOf(draft_file_added::class, $event);
-
 
108
    }
-
 
109
 
-
 
110
    public function test_avscantime_must_be_float(): void {
-
 
111
        $this->expectException(\coding_exception::class);
-
 
112
 
-
 
113
        $eventdata = [
-
 
114
            'objectid' => 123,
-
 
115
            'context' => context_system::instance(),
-
 
116
            'other' => [
-
 
117
                'itemid' => 789,
-
 
118
                'filename' => 'test.txt',
-
 
119
                'filesize' => 42,
-
 
120
                'filepath' => '/',
-
 
121
                'contenthash' => 'a2653cc92420a875358f09942e4b4665351fa49b',
-
 
122
                'avscantime' => 'frog',
82
        $expected = "The user with id '{$user->id}' has uploaded file '/test.txt' to the draft file area with item id 0. ".
123
            ],
83
            "Size: 12{$nbsp}bytes. Content hash: {$originalfile->get_contenthash()}.";
124
        ];