Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 90... Línea 90...
90
    }
90
    }
Línea 91... Línea 91...
91
 
91
 
92
    /**
92
    /**
93
     * Function to test the private function create_share_user_sysaccount.
93
     * Function to test the private function create_share_user_sysaccount.
94
     */
94
     */
95
    public function test_create_share_user_sysaccount_user_shares() {
95
    public function test_create_share_user_sysaccount_user_shares(): void {
96
        $params = [
96
        $params = [
97
            'path' => "/ambient.txt",
97
            'path' => "/ambient.txt",
98
            'shareType' => \repository_nextcloud\ocs_client::SHARE_TYPE_USER,
98
            'shareType' => \repository_nextcloud\ocs_client::SHARE_TYPE_USER,
99
            'publicUpload' => false,
99
            'publicUpload' => false,
Línea 148... Línea 148...
148
    }
148
    }
149
    /**
149
    /**
150
     * Test the delete_share_function. In case the request fails, the function throws an exception, however this
150
     * Test the delete_share_function. In case the request fails, the function throws an exception, however this
151
     * can not be tested in phpUnit since it is javascript.
151
     * can not be tested in phpUnit since it is javascript.
152
     */
152
     */
153
    public function test_delete_share_dataowner_sysaccount() {
153
    public function test_delete_share_dataowner_sysaccount(): void {
154
        $shareid = 5;
154
        $shareid = 5;
155
        $deleteshareparams = [
155
        $deleteshareparams = [
156
            'share_id' => $shareid
156
            'share_id' => $shareid
157
        ];
157
        ];
158
        $returnxml = <<<XML
158
        $returnxml = <<<XML
Línea 174... Línea 174...
174
 
174
 
175
    /**
175
    /**
176
     * Function which test that create folder path does return the adequate results (path and success).
176
     * Function which test that create folder path does return the adequate results (path and success).
177
     * Additionally mock checks whether the right params are passed to the corresponding functions.
177
     * Additionally mock checks whether the right params are passed to the corresponding functions.
178
     */
178
     */
Línea 179... Línea 179...
179
    public function test_create_folder_path_folders_are_not_created() {
179
    public function test_create_folder_path_folders_are_not_created(): void {
180
 
180
 
181
        $mocks = $this->set_up_mocks_for_create_folder_path(true, 'somename');
181
        $mocks = $this->set_up_mocks_for_create_folder_path(true, 'somename');
182
        $this->set_private_property($mocks['mockclient'], 'systemwebdavclient', $this->linkmanager);
182
        $this->set_private_property($mocks['mockclient'], 'systemwebdavclient', $this->linkmanager);
Línea 186... Línea 186...
186
    }
186
    }
187
    /**
187
    /**
188
     * Function which test that create folder path does return the adequate results (path and success).
188
     * Function which test that create folder path does return the adequate results (path and success).
189
     * Additionally mock checks whether the right params are passed to the corresponding functions.
189
     * Additionally mock checks whether the right params are passed to the corresponding functions.
190
     */
190
     */
191
    public function test_create_folder_path_folders_are_created() {
191
    public function test_create_folder_path_folders_are_created(): void {
Línea 192... Línea 192...
192
 
192
 
193
        // In Context is okay, number of context counts for number of iterations.
193
        // In Context is okay, number of context counts for number of iterations.
194
        $mocks = $this->set_up_mocks_for_create_folder_path(false, 'somename/withslash', true, 201);
194
        $mocks = $this->set_up_mocks_for_create_folder_path(false, 'somename/withslash', true, 201);
195
        $this->set_private_property($mocks['mockclient'], 'systemwebdavclient', $this->linkmanager);
195
        $this->set_private_property($mocks['mockclient'], 'systemwebdavclient', $this->linkmanager);
Línea 198... Línea 198...
198
        $this->assertEquals('/somenamewithslash (ctx )/mod_resource/content/0', $result);
198
        $this->assertEquals('/somenamewithslash (ctx )/mod_resource/content/0', $result);
199
    }
199
    }
200
    /**
200
    /**
201
     * Test whether the create_folder_path methode throws exception.
201
     * Test whether the create_folder_path methode throws exception.
202
     */
202
     */
203
    public function test_create_folder_path_folder_creation_fails() {
203
    public function test_create_folder_path_folder_creation_fails(): void {
Línea 204... Línea 204...
204
 
204
 
205
        $mocks = $this->set_up_mocks_for_create_folder_path(false, 'somename', true, 400);
205
        $mocks = $this->set_up_mocks_for_create_folder_path(false, 'somename', true, 400);
206
        $this->set_private_property($mocks['mockclient'], 'systemwebdavclient', $this->linkmanager);
206
        $this->set_private_property($mocks['mockclient'], 'systemwebdavclient', $this->linkmanager);
207
        $this->expectException(\repository_nextcloud\request_exception::class);
207
        $this->expectException(\repository_nextcloud\request_exception::class);
Línea 241... Línea 241...
241
 
241
 
242
    /**
242
    /**
243
     * Test whether the right methods from the webdavclient are called when the storage_folder is created.
243
     * Test whether the right methods from the webdavclient are called when the storage_folder is created.
244
     * 1. Directory already exist -> no further action needed.
244
     * 1. Directory already exist -> no further action needed.
245
     */
245
     */
246
    public function test_create_storage_folder_success() {
246
    public function test_create_storage_folder_success(): void {
247
        $mockwebdavclient = $this->createMock(\webdav_client::class);
247
        $mockwebdavclient = $this->createMock(\webdav_client::class);
248
        $url = $this->issuer->get_endpoint_url('webdav');
248
        $url = $this->issuer->get_endpoint_url('webdav');
249
        $parsedwebdavurl = parse_url($url);
249
        $parsedwebdavurl = parse_url($url);
250
        $webdavprefix = $parsedwebdavurl['path'];
250
        $webdavprefix = $parsedwebdavurl['path'];
Línea 257... Línea 257...
257
    /**
257
    /**
258
     * Test whether the right methods from the webdavclient are called when the storage_folder is created.
258
     * Test whether the right methods from the webdavclient are called when the storage_folder is created.
259
     * 2. Directory does not exist. It is created with mkcol and returns a success.
259
     * 2. Directory does not exist. It is created with mkcol and returns a success.
260
     *
260
     *
261
     */
261
     */
262
    public function test_create_storage_folder_success_mkcol() {
262
    public function test_create_storage_folder_success_mkcol(): void {
263
        $mockwebdavclient = $this->createMock(\webdav_client::class);
263
        $mockwebdavclient = $this->createMock(\webdav_client::class);
264
        $url = $this->issuer->get_endpoint_url('webdav');
264
        $url = $this->issuer->get_endpoint_url('webdav');
265
        $parsedwebdavurl = parse_url($url);
265
        $parsedwebdavurl = parse_url($url);
266
        $webdavprefix = $parsedwebdavurl['path'];
266
        $webdavprefix = $parsedwebdavurl['path'];
267
        $mockwebdavclient->expects($this->once())->method('open')->willReturn(true);
267
        $mockwebdavclient->expects($this->once())->method('open')->willReturn(true);
Línea 273... Línea 273...
273
    }
273
    }
274
    /**
274
    /**
275
     * Test whether the right methods from the webdavclient are called when the storage_folder is created.
275
     * Test whether the right methods from the webdavclient are called when the storage_folder is created.
276
     * 3. Request to create Folder fails.
276
     * 3. Request to create Folder fails.
277
     */
277
     */
278
    public function test_create_storage_folder_failure() {
278
    public function test_create_storage_folder_failure(): void {
279
        $mockwebdavclient = $this->createMock(\webdav_client::class);
279
        $mockwebdavclient = $this->createMock(\webdav_client::class);
280
        $url = $this->issuer->get_endpoint_url('webdav');
280
        $url = $this->issuer->get_endpoint_url('webdav');
281
        $parsedwebdavurl = parse_url($url);
281
        $parsedwebdavurl = parse_url($url);
282
        $webdavprefix = $parsedwebdavurl['path'];
282
        $webdavprefix = $parsedwebdavurl['path'];
283
        $mockwebdavclient->expects($this->once())->method('open')->willReturn(true);
283
        $mockwebdavclient->expects($this->once())->method('open')->willReturn(true);
Línea 288... Línea 288...
288
        $this->linkmanager->create_storage_folder('myname', $mockwebdavclient);
288
        $this->linkmanager->create_storage_folder('myname', $mockwebdavclient);
289
    }
289
    }
290
    /**
290
    /**
291
     * Test whether the webdav client gets the right params and whether function differentiates between move and copy.
291
     * Test whether the webdav client gets the right params and whether function differentiates between move and copy.
292
     */
292
     */
293
    public function test_transfer_file_to_path_copyfile() {
293
    public function test_transfer_file_to_path_copyfile(): void {
294
        // Initialize params.
294
        // Initialize params.
295
        $parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
295
        $parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
296
        $webdavprefix = $parsedwebdavurl['path'];
296
        $webdavprefix = $parsedwebdavurl['path'];
297
        $srcpath = 'sourcepath';
297
        $srcpath = 'sourcepath';
298
        $dstpath = "destinationpath/another/path";
298
        $dstpath = "destinationpath/another/path";
Línea 312... Línea 312...
312
    /**
312
    /**
313
     * Test whether the webdav client gets the right params and whether function handles overwrite.
313
     * Test whether the webdav client gets the right params and whether function handles overwrite.
314
     *
314
     *
315
     * @covers \repository_nextcloud\access_controlled_link_manager::transfer_file_to_path
315
     * @covers \repository_nextcloud\access_controlled_link_manager::transfer_file_to_path
316
     */
316
     */
317
    public function test_transfer_file_to_path_overwritefile() {
317
    public function test_transfer_file_to_path_overwritefile(): void {
318
        // Initialize params.
318
        // Initialize params.
319
        $parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
319
        $parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
320
        $webdavprefix = $parsedwebdavurl['path'];
320
        $webdavprefix = $parsedwebdavurl['path'];
321
        $srcpath = 'sourcepath';
321
        $srcpath = 'sourcepath';
322
        $dstpath = "destinationpath/another/path";
322
        $dstpath = "destinationpath/another/path";
Línea 336... Línea 336...
336
    /**
336
    /**
337
     * This function tests whether the function transfer_file_to_path() moves or copies a given file to a given path
337
     * This function tests whether the function transfer_file_to_path() moves or copies a given file to a given path
338
     * It tests whether the webdav_client gets the right parameter and whether function distinguishes between move and copy.
338
     * It tests whether the webdav_client gets the right parameter and whether function distinguishes between move and copy.
339
     *
339
     *
340
     */
340
     */
341
    public function test_transfer_file_to_path_copyfile_movefile() {
341
    public function test_transfer_file_to_path_copyfile_movefile(): void {
342
        // Initialize params.
342
        // Initialize params.
343
        $parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
343
        $parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
344
        $webdavprefix = $parsedwebdavurl['path'];
344
        $webdavprefix = $parsedwebdavurl['path'];
345
        $srcpath = 'sourcepath';
345
        $srcpath = 'sourcepath';
346
        $dstpath = "destinationpath/another/path";
346
        $dstpath = "destinationpath/another/path";
Línea 361... Línea 361...
361
     * Test the get_shares_from path() function. This function extracts from an list of shares the share of a given user
361
     * Test the get_shares_from path() function. This function extracts from an list of shares the share of a given user
362
     * (the username is a parameter in the function call) and returns the id. The test firstly test whether the right fileid
362
     * (the username is a parameter in the function call) and returns the id. The test firstly test whether the right fileid
363
     * for user1 is extracted then for user2 and last but least whether an error is thrown if the user does not have a share.
363
     * for user1 is extracted then for user2 and last but least whether an error is thrown if the user does not have a share.
364
     * @throws moodle_exception
364
     * @throws moodle_exception
365
     */
365
     */
366
    public function test_get_shares_from_path() {
366
    public function test_get_shares_from_path(): void {
367
        $params = [
367
        $params = [
368
            'path' => '/Kernsystem/Kursbereich Miscellaneous/Kurs Example Course/Datei zet/mod_resource/content/0/picture.png',
368
            'path' => '/Kernsystem/Kursbereich Miscellaneous/Kurs Example Course/Datei zet/mod_resource/content/0/picture.png',
369
            'reshares' => true
369
            'reshares' => true
370
        ];
370
        ];
371
        $reference = new \stdClass();
371
        $reference = new \stdClass();
Línea 454... Línea 454...
454
    /** Test whether the systemwebdav client is constructed correctly. Port is set to 443 in case of https, to 80 in
454
    /** Test whether the systemwebdav client is constructed correctly. Port is set to 443 in case of https, to 80 in
455
     * case of http and exception is thrown when endpoint does not exist.
455
     * case of http and exception is thrown when endpoint does not exist.
456
     * @throws \repository_nextcloud\configuration_exception
456
     * @throws \repository_nextcloud\configuration_exception
457
     * @throws coding_exception
457
     * @throws coding_exception
458
     */
458
     */
459
    public function test_create_system_dav() {
459
    public function test_create_system_dav(): void {
460
        // Initialize mock and params.
460
        // Initialize mock and params.
461
        $fakeaccesstoken = new \stdClass();
461
        $fakeaccesstoken = new \stdClass();
462
        $fakeaccesstoken->token = "fake access token";
462
        $fakeaccesstoken->token = "fake access token";
463
        // Use `atLeastOnce` instead of `exactly(2)` because it is only called a second time on dev systems that allow http://.
463
        // Use `atLeastOnce` instead of `exactly(2)` because it is only called a second time on dev systems that allow http://.
464
        $this->oauthsystemmock->expects($this->atLeastOnce())->method('get_accesstoken')->willReturn($fakeaccesstoken);
464
        $this->oauthsystemmock->expects($this->atLeastOnce())->method('get_accesstoken')->willReturn($fakeaccesstoken);
Línea 510... Línea 510...
510
     * whether the right file_target is extracted and lastly it is checked whether an error is thrown in case no suitable
510
     * whether the right file_target is extracted and lastly it is checked whether an error is thrown in case no suitable
511
     * element exists.
511
     * element exists.
512
     * @throws \repository_nextcloud\request_exception
512
     * @throws \repository_nextcloud\request_exception
513
     * @throws coding_exception
513
     * @throws coding_exception
514
     */
514
     */
515
    public function test_get_share_information_from_shareid() {
515
    public function test_get_share_information_from_shareid(): void {
516
        $params303 = [
516
        $params303 = [
517
            'share_id' => 303,
517
            'share_id' => 303,
518
        ];
518
        ];
519
        $params302 = [
519
        $params302 = [
520
            'share_id' => 302,
520
            'share_id' => 302,