Proyectos de Subversion Moodle

Rev

| 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
/**
18
 * Base class for the googledoc repository unit tests.
19
 *
20
 * @package    repository_googledocs
21
 * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
abstract class repository_googledocs_testcase extends \advanced_testcase {
25
 
26
    /**
27
     * Create an array that would replicate the structure of a repository folder node array.
28
     *
29
     * @param string $id The ID of the folder
30
     * @param string $name The name of the folder
31
     * @param string $path The root path
32
     * @param string $modified The date of the last modification
33
     * @return array The repository folder node array
34
     */
35
    protected function create_folder_content_node_array(string $id, string $name, string $path,
36
            string $modified = ''): array {
37
 
38
        global $CFG, $OUTPUT;
39
 
40
        return [
41
            'id' => $id,
42
            'title' => $name,
43
            'path' => repository_googledocs\helper::build_node_path($id, $name, $path),
44
            'date' => $modified,
45
            'thumbnail' => "{$CFG->wwwroot}/theme/image.php/boost/core/1/" . file_folder_icon(),
46
            'thumbnail_height' => 64,
47
            'thumbnail_width' => 64,
48
            'children' => [],
49
        ];
50
    }
51
 
52
    /**
53
     * Create an array that would replicate the structure of a repository file node array.
54
     *
55
     * @param string $id The ID of the file
56
     * @param string $name The name of the file
57
     * @param string $title The title of the file node
58
     * @param string|null $size The size of the file
59
     * @param string $modified The date of the last modification
60
     * @param string $thumbnail The thumbnail of the file
61
     * @param string|null $link The external link to the file
62
     * @param string|null $exportformat The export format of the file
63
     * @param string|null $googledoctype The type of the Google Doc file (if applicable)
64
     * @return array The repository file node array
65
     */
66
    protected function create_file_content_node_array(string $id, string $name, string $title, ?string $size = null,
67
            string $modified = '', string $thumbnail = '' , string $link = '', string $exportformat = '',
68
            ?string $googledoctype = null): array {
69
 
70
        return [
71
            'id' => $id,
72
            'title' => $title,
73
            'source' => json_encode([
74
                'id' => $id,
75
                'name' => $name,
76
                'link' => $link,
77
                'exportformat' => $exportformat,
78
                'googledoctype' => $googledoctype
79
            ]),
80
            'date' => $modified,
81
            'size' => $size,
82
            'thumbnail' => $thumbnail,
83
            'thumbnail_height' => 64,
84
            'thumbnail_width' => 64,
85
        ];
86
    }
87
 
88
    /**
89
     * Create an object that would replicate the metadata for a shared drive returned by the Google Drive API call.
90
     *
91
     * @param string $id The ID of the shared drive
92
     * @param string $name The name of the shared drive
93
     * @return \stdClass The shared drive object
94
     */
95
    protected function create_google_drive_shared_drive_object(string $id, string $name): \stdClass {
96
        return (object)[
97
            'kind' => 'drive#drive',
98
            'id' => $id,
99
            'name' => $name,
100
        ];
101
    }
102
 
103
    /**
104
     * Create an object that would replicate the metadata for a folder returned by the Google Drive API call.
105
     *
106
     * @param string $id The ID of the folder
107
     * @param string $name The name of the folder
108
     * @param string|null $modified The date of the last modification
109
     * @return \stdClass The folder object
110
     */
111
    protected function create_google_drive_folder_object(string $id, string $name, ?string $modified = null): \stdClass {
112
        return (object)[
113
            'id' => $id,
114
            'name' => $name,
115
            'mimeType' => 'application/vnd.google-apps.folder',
116
            'webViewLink' => "https://drive.google.com/drive/folders/{$id}",
117
            'iconLink' => 'https://googleusercontent.com/16/type/application/vnd.google-apps.folder+shared',
118
            'modifiedTime' => $modified ?? '',
119
        ];
120
    }
121
 
122
    /**
123
     * Create an object that would replicate the metadata for a file returned by the Google Drive API call.
124
     *
125
     * @param string $id The ID of the file
126
     * @param string $name The name of the file
127
     * @param string $mimetype The mimetype of the file
128
     * @param string|null $extension The extension of the file
129
     * @param string|null $size The size of the file
130
     * @param string|null $modified The date of the last modification
131
     * @param string|null $webcontentlink The link for downloading the content of the file
132
     * @param string|null $webviewlink The link for opening the file in a browser
133
     * @return \stdClass The file object
134
     */
135
    protected function create_google_drive_file_object(string $id, string $name, string $mimetype,
136
            ?string $extension = null, ?string $size = null, ?string $modified = null, ?string $webcontentlink = null,
137
            ?string $webviewlink = null): \stdClass {
138
 
139
        $googledrivefile = [
140
            'id' => $id,
141
            'name' => $name,
142
            'mimeType' => $mimetype,
143
            'size' => $size ?? '',
144
            'webContentLink' => $webcontentlink ?? '',
145
            'webViewLink' => $webviewlink ?? '',
146
            'iconLink' => "https://googleusercontent.com/type/{$mimetype}",
147
            'modifiedTime' => $modified ?? '',
148
        ];
149
        // The returned metadata might not always have the 'fileExtension' property.
150
        if ($extension) {
151
            $googledrivefile['fileExtension'] = $extension;
152
        }
153
 
154
        return (object)$googledrivefile;
155
    }
156
}