1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core_files\redactor;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Tests for file redactor manager class.
|
|
|
21 |
*
|
|
|
22 |
* @package core_files
|
|
|
23 |
* @copyright Meirza <meirza.arson@moodle.com>
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
* @covers \core_files\redactor\manager
|
|
|
26 |
*/
|
|
|
27 |
final class manager_test extends \advanced_testcase {
|
|
|
28 |
/**
|
|
|
29 |
* Helper to get a manager with a dummy file service.
|
|
|
30 |
*
|
|
|
31 |
* @return \core_files\redactor\manager
|
|
|
32 |
*/
|
|
|
33 |
private function get_manager_with_dummy_file_service(): manager {
|
|
|
34 |
$manager = $this->getMockBuilder(\core_files\redactor\manager::class)
|
|
|
35 |
->onlyMethods(['get_service_classnames'])
|
|
|
36 |
->getMock();
|
|
|
37 |
|
|
|
38 |
$manager->method('get_service_classnames')
|
|
|
39 |
->willReturn([\core_files\tests\redactor\services\dummy_file_service::class]);
|
|
|
40 |
|
|
|
41 |
return $manager;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Test file redaction by path.
|
|
|
46 |
*/
|
|
|
47 |
public function test_redact_file(): void {
|
|
|
48 |
|
|
|
49 |
$manager = $this->get_manager_with_dummy_file_service();
|
|
|
50 |
|
|
|
51 |
// Test redaction for a binary (not supported).
|
|
|
52 |
$redactedfile = $manager->redact_file("application/binary", "/path/to/binary");
|
|
|
53 |
$this->assertNull($redactedfile);
|
|
|
54 |
$redactedfile = $manager->redact_file_content("application/binary", "Binary content here");
|
|
|
55 |
$this->assertNull($redactedfile);
|
|
|
56 |
|
|
|
57 |
// Test redaction for an image.
|
|
|
58 |
$redactedfile = $manager->redact_file("image/jpeg", "/path/to/image.jpg");
|
|
|
59 |
$this->assertEquals('/redacted/path/to/image.jpg', $redactedfile);
|
|
|
60 |
$redactedfile = $manager->redact_file_content("image/jpeg", "Example picture goes here");
|
|
|
61 |
$this->assertEquals('redacted:Example picture goes here', $redactedfile);
|
|
|
62 |
}
|
|
|
63 |
}
|