Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 27... Línea 27...
27
 *
27
 *
28
 * @package    repository_googledocs
28
 * @package    repository_googledocs
29
 * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
29
 * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
31
 */
32
class googledocs_drive_content_test extends \googledocs_content_testcase {
32
final class googledocs_drive_content_test extends \googledocs_content_testcase {
Línea 33... Línea 33...
33
 
33
 
34
    /**
34
    /**
35
     * Test get_content_nodes().
35
     * Test get_content_nodes().
36
     *
36
     *
Línea 61... Línea 61...
61
        }
61
        }
Línea 62... Línea 62...
62
 
62
 
63
        // Assert that the call() method is being called twice with the given arguments consecutively. In the first
63
        // Assert that the call() method is being called twice with the given arguments consecutively. In the first
64
        // instance it is being called to fetch the shared drives (shared_drives_list), while in the second instance
64
        // instance it is being called to fetch the shared drives (shared_drives_list), while in the second instance
-
 
65
        // to fetch the relevant drive contents (list). Also, define the returned data objects by these calls.
65
        // to fetch the relevant drive contents (list). Also, define the returned data objects by these calls.
66
        $callinvocations = $this->exactly(2);
66
        $servicemock->expects($this->exactly(2))
67
        $servicemock->expects($callinvocations)
67
            ->method('call')
68
            ->method('call')
68
            ->withConsecutive(
69
            ->willReturnCallback(function(string $method, array $params) use (
69
                [
70
                $callinvocations,
70
                    'shared_drives_list',
71
                $shareddrives,
71
                    [],
72
                $listparams,
72
                ],
73
                $drivecontents,
73
                [
74
            ) {
74
                    'list',
75
                switch (self::getInvocationCount($callinvocations)) {
75
                    $listparams,
76
                    case 1:
76
                ]
-
 
77
            )
77
                        $this->assertEquals('shared_drives_list', $method);
-
 
78
                        $this->assertEquals([], $params);
78
            ->willReturnOnConsecutiveCalls(
79
 
79
                (object)[
80
                        return (object) [
80
                    'kind' => 'drive#driveList',
81
                            'kind' => 'drive#driveList',
81
                    'nextPageToken' => 'd838181f30b0f5',
82
                            'nextPageToken' => 'd838181f30b0f5',
82
                    'drives' => $shareddrives,
83
                            'drives' => $shareddrives,
83
                ],
84
                        ];
-
 
85
                    case 2:
-
 
86
                        $this->assertEquals('list', $method);
-
 
87
                        $this->assertEquals($listparams, $params);
84
                (object)[
88
                        return (object)[
-
 
89
                            'files' => $drivecontents,
-
 
90
                        ];
-
 
91
                    default:
85
                    'files' => $drivecontents,
92
                        $this->fail('Unexpected call to the call() method.');
86
                ]
93
                }
Línea 87... Línea 94...
87
            );
94
            });
88
 
95
 
89
        // Set the disallowed file types (extensions).
96
        // Set the disallowed file types (extensions).
90
        $this->disallowedextensions = $filterextensions;
97
        $this->disallowedextensions = $filterextensions;
Línea 98... Línea 105...
98
    /**
105
    /**
99
     * Data provider for test_get_content_nodes().
106
     * Data provider for test_get_content_nodes().
100
     *
107
     *
101
     * @return array
108
     * @return array
102
     */
109
     */
103
    public function get_content_nodes_provider(): array {
110
    public static function get_content_nodes_provider(): array {
104
 
-
 
105
        $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
111
        $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
106
        $mydriveid = \repository_googledocs::MY_DRIVE_ROOT_ID;
112
        $mydriveid = \repository_googledocs::MY_DRIVE_ROOT_ID;
Línea 107... Línea 113...
107
 
113
 
108
        return [
114
        return [
Línea 111... Línea 117...
111
                    $mydriveid,
117
                    $mydriveid,
112
                    "{$rootid}|Google+Drive/{$mydriveid}|My+Drive",
118
                    "{$rootid}|Google+Drive/{$mydriveid}|My+Drive",
113
                    true,
119
                    true,
114
                    [],
120
                    [],
115
                    [
121
                    [
116
                        $this->create_google_drive_shared_drive_object('d85b21c0f86cb5', 'Shared Drive 1'),
122
                        self::create_google_drive_shared_drive_object('d85b21c0f86cb5', 'Shared Drive 1'),
117
                    ],
123
                    ],
118
                    [
124
                    [
119
                        $this->create_google_drive_folder_object('1c4ad262c65333', 'Folder 2'),
125
                        self::create_google_drive_folder_object('1c4ad262c65333', 'Folder 2'),
120
                        $this->create_google_drive_file_object('d85b21c0f86cb0', 'File 3.pdf',
126
                        self::create_google_drive_file_object('d85b21c0f86cb0', 'File 3.pdf',
121
                            'application/pdf', 'pdf', '1000'),
127
                            'application/pdf', 'pdf', '1000'),
122
                        $this->create_google_drive_folder_object('0c4ad262c65333', 'Folder 1'),
128
                        self::create_google_drive_folder_object('0c4ad262c65333', 'Folder 1'),
123
                        $this->create_google_drive_file_object('bed5a0f08d412a', 'File 1.pdf',
129
                        self::create_google_drive_file_object('bed5a0f08d412a', 'File 1.pdf',
124
                            'application/pdf', 'pdf'),
130
                            'application/pdf', 'pdf'),
125
                    ],
131
                    ],
126
                    [
132
                    [
127
                        $this->create_folder_content_node_array('0c4ad262c65333', 'Folder 1',
133
                        self::create_folder_content_node_array('0c4ad262c65333', 'Folder 1',
128
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
134
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
129
                        $this->create_folder_content_node_array('1c4ad262c65333', 'Folder 2',
135
                        self::create_folder_content_node_array('1c4ad262c65333', 'Folder 2',
130
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
136
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
131
                        $this->create_file_content_node_array('bed5a0f08d412a', 'File 1.pdf', 'File 1.pdf',
137
                        self::create_file_content_node_array('bed5a0f08d412a', 'File 1.pdf', 'File 1.pdf',
132
                            null, '', 'https://googleusercontent.com/type/application/pdf', '',
138
                            null, '', 'https://googleusercontent.com/type/application/pdf', '',
133
                            'download'),
139
                            'download'),
134
                        $this->create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', 'File 3.pdf',
140
                        self::create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', 'File 3.pdf',
135
                            '1000', '', 'https://googleusercontent.com/type/application/pdf', '',
141
                            '1000', '', 'https://googleusercontent.com/type/application/pdf', '',
136
                            'download'),
142
                            'download'),
137
                    ],
143
                    ],
138
                ],
144
                ],
139
            'Only folders exist in the drive; shared drives do not exist; ordering not applied.' =>
145
            'Only folders exist in the drive; shared drives do not exist; ordering not applied.' =>
Línea 142... Línea 148...
142
                    "{$rootid}|Google+Drive/{$mydriveid}|My+Drive",
148
                    "{$rootid}|Google+Drive/{$mydriveid}|My+Drive",
143
                    false,
149
                    false,
144
                    [],
150
                    [],
145
                    [],
151
                    [],
146
                    [
152
                    [
147
                        $this->create_google_drive_folder_object('0c4ad262c65333', 'Folder 3'),
153
                        self::create_google_drive_folder_object('0c4ad262c65333', 'Folder 3'),
148
                        $this->create_google_drive_folder_object('d85b21c0f86cb0', 'Folder 1'),
154
                        self::create_google_drive_folder_object('d85b21c0f86cb0', 'Folder 1'),
149
                        $this->create_google_drive_folder_object('bed5a0f08d412a', 'Folder 2'),
155
                        self::create_google_drive_folder_object('bed5a0f08d412a', 'Folder 2'),
150
                    ],
156
                    ],
151
                    [
157
                    [
152
                        $this->create_folder_content_node_array('0c4ad262c65333', 'Folder 3',
158
                        self::create_folder_content_node_array('0c4ad262c65333', 'Folder 3',
153
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
159
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
154
                        $this->create_folder_content_node_array('d85b21c0f86cb0', 'Folder 1',
160
                        self::create_folder_content_node_array('d85b21c0f86cb0', 'Folder 1',
155
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
161
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
156
                        $this->create_folder_content_node_array('bed5a0f08d412a', 'Folder 2',
162
                        self::create_folder_content_node_array('bed5a0f08d412a', 'Folder 2',
157
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
163
                            "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"),
158
                    ],
164
                    ],
159
                ],
165
                ],
160
            'Only files exist in the drive; shared drives do not exist; ordering not applied; filter .txt.' =>
166
            'Only files exist in the drive; shared drives do not exist; ordering not applied; filter .txt.' =>
161
                [
167
                [
Línea 163... Línea 169...
163
                    "{$rootid}|Google+Drive/{$mydriveid}|My+Drive",
169
                    "{$rootid}|Google+Drive/{$mydriveid}|My+Drive",
164
                    false,
170
                    false,
165
                    ['txt'],
171
                    ['txt'],
166
                    [],
172
                    [],
167
                    [
173
                    [
168
                        $this->create_google_drive_file_object('d85b21c0f86cb0', 'File 3.pdf',
174
                        self::create_google_drive_file_object('d85b21c0f86cb0', 'File 3.pdf',
169
                            'application/pdf', 'pdf', '1000'),
175
                            'application/pdf', 'pdf', '1000'),
170
                        $this->create_google_drive_file_object('a85b21c0f86cb0', 'File 1.txt',
176
                        self::create_google_drive_file_object('a85b21c0f86cb0', 'File 1.txt',
171
                            'text/plain', 'txt', '3000'),
177
                            'text/plain', 'txt', '3000'),
172
                        $this->create_google_drive_file_object('f85b21c0f86cb0', 'File 2.doc',
178
                        self::create_google_drive_file_object('f85b21c0f86cb0', 'File 2.doc',
173
                            'application/msword', 'doc', '2000'),
179
                            'application/msword', 'doc', '2000'),
174
                    ],
180
                    ],
175
                    [
181
                    [
176
                        $this->create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', 'File 3.pdf',
182
                        self::create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', 'File 3.pdf',
177
                            '1000', '', 'https://googleusercontent.com/type/application/pdf', '',
183
                            '1000', '', 'https://googleusercontent.com/type/application/pdf', '',
178
                            'download'),
184
                            'download'),
179
                        $this->create_file_content_node_array('f85b21c0f86cb0', 'File 2.doc', 'File 2.doc',
185
                        self::create_file_content_node_array('f85b21c0f86cb0', 'File 2.doc', 'File 2.doc',
180
                            '2000', '', 'https://googleusercontent.com/type/application/msword', '',
186
                            '2000', '', 'https://googleusercontent.com/type/application/msword', '',
181
                            'download'),
187
                            'download'),
182
                    ],
188
                    ],
183
                ],
189
                ],
184
            'Contents do not exist in the drive; shared drives do not exist.' =>
190
            'Contents do not exist in the drive; shared drives do not exist.' =>
Línea 215... Línea 221...
215
    /**
221
    /**
216
     * Data provider for test_get_navigation().
222
     * Data provider for test_get_navigation().
217
     *
223
     *
218
     * @return array
224
     * @return array
219
     */
225
     */
220
    public function get_navigation_provider(): array {
226
    public static function get_navigation_provider(): array {
Línea 221... Línea 227...
221
 
227
 
222
        $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
228
        $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
Línea 223... Línea 229...
223
        $mydriveid = \repository_googledocs::MY_DRIVE_ROOT_ID;
229
        $mydriveid = \repository_googledocs::MY_DRIVE_ROOT_ID;