Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
use tool_filetypes\utils;
18
 
19
/**
20
 * Unit tests for the custom file types.
21
 *
22
 * @package tool_filetypes
23
 * @copyright 2014 The Open University
24
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @coversDefaultClass \tool_filetypes\utils
26
 */
1441 ariadna 27
final class tool_filetypes_test extends advanced_testcase {
1 efrain 28
    /**
29
     * Tests is_extension_invalid() function.
30
     *
31
     * @covers ::is_extension_invalid
32
     */
11 efrain 33
    public function test_is_extension_invalid(): void {
1 efrain 34
        // The pdf file extension already exists in default moodle minetypes.
35
        $this->assertTrue(utils::is_extension_invalid('pdf'));
36
 
37
        // The frog extension does not.
38
        $this->assertFalse(utils::is_extension_invalid('frog'));
39
 
40
        // However you could use the pdf extension when editing the pdf extension.
41
        $this->assertFalse(utils::is_extension_invalid('pdf', 'pdf'));
42
 
43
        // Blank extension is invalid.
44
        $this->assertTrue(utils::is_extension_invalid(''));
45
 
46
        // Extensions with dot are invalid.
47
        $this->assertTrue(utils::is_extension_invalid('.frog'));
48
    }
49
 
50
    /**
51
     * Tests is_defaulticon_allowed() function.
52
     *
53
     * @covers ::is_defaulticon_allowed
54
     */
11 efrain 55
    public function test_is_defaulticon_allowed(): void {
1 efrain 56
        // You ARE allowed to set a default icon for a MIME type that hasn't
57
        // been used yet.
58
        $this->assertTrue(utils::is_defaulticon_allowed('application/x-frog'));
59
 
60
        // You AREN'T allowed to set default icon for text/plain as there is
61
        // already a type that has that set.
62
        $this->assertFalse(utils::is_defaulticon_allowed('text/plain'));
63
 
64
        // But you ARE still allowed to set it when actually editing txt, which
65
        // is the default.
66
        $this->assertTrue(utils::is_defaulticon_allowed('text/plain', 'txt'));
67
    }
68
 
69
    /**
70
     * Tests get_icons_from_path() function.
71
     *
72
     * @covers ::get_icons_from_path
73
     */
11 efrain 74
    public function test_get_icons_from_path(): void {
1 efrain 75
        // Get icons from the fixtures folder.
76
        $icons = utils::get_icons_from_path(__DIR__ . '/fixtures');
77
 
78
        // The icons are returned alphabetically and with keys === values.
79
        // For the icon with numbers after the name, only the base name is
80
        // returned and only one of it.
81
        $this->assertEquals(array('frog' => 'frog', 'zombie' => 'zombie'), $icons);
82
    }
83
 
84
    /**
85
     * Test get_file_icons() function to confirm no file icons are removed by mistake.
86
     *
87
     * @covers ::get_file_icons
88
     */
11 efrain 89
    public function test_get_file_icons(): void {
1 efrain 90
        $icons = utils::get_file_icons();
91
        $filetypes = core_filetypes::get_types();
92
 
93
        $requiredicons = array_column($filetypes, 'icon');
94
        $requireduniqueicons = array_unique($requiredicons);
95
 
96
        // The 'folder' icon is not a file, however the test validates no
97
        // file icons are removed by mistake from the directory pix/f.
98
        // Adding the folder icon manually completes the scope of this test.
99
        $requireduniqueicons[] = 'folder';
100
 
101
        foreach ($requireduniqueicons as $requiredicon) {
102
            $this->assertArrayHasKey($requiredicon, $icons, "Icon '$requiredicon' is missing.");
103
        }
104
    }
105
}