Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 85... Línea 85...
85
    }
85
    }
Línea 86... Línea 86...
86
 
86
 
87
    /**
87
    /**
88
     * Checks the is_visible method in case the repository is set to hidden in the database.
88
     * Checks the is_visible method in case the repository is set to hidden in the database.
89
     */
89
     */
90
    public function test_is_visible_parent_false() {
90
    public function test_is_visible_parent_false(): void {
91
        global $DB;
91
        global $DB;
Línea 92... Línea 92...
92
        $id = $this->repo->options['typeid'];
92
        $id = $this->repo->options['typeid'];
93
 
93
 
Línea 99... Línea 99...
99
    }
99
    }
Línea 100... Línea 100...
100
 
100
 
101
    /**
101
    /**
102
     * Test whether the repo is disabled.
102
     * Test whether the repo is disabled.
103
     */
103
     */
104
    public function test_repo_creation() {
104
    public function test_repo_creation(): void {
Línea 105... Línea 105...
105
        $issuerid = $this->repo->get_option('issuerid');
105
        $issuerid = $this->repo->get_option('issuerid');
106
 
106
 
Línea 135... Línea 135...
135
        return $id;
135
        return $id;
136
    }
136
    }
137
    /**
137
    /**
138
     * Test if repository is disabled when webdav_endpoint is deleted.
138
     * Test if repository is disabled when webdav_endpoint is deleted.
139
     */
139
     */
140
    public function test_issuer_webdav() {
140
    public function test_issuer_webdav(): void {
141
        $idwebdav = $this->get_endpoint_id('webdav_endpoint');
141
        $idwebdav = $this->get_endpoint_id('webdav_endpoint');
142
        if (!empty($idwebdav)) {
142
        if (!empty($idwebdav)) {
143
            foreach ($idwebdav as $id) {
143
            foreach ($idwebdav as $id) {
144
                \core\oauth2\api::delete_endpoint($id);
144
                \core\oauth2\api::delete_endpoint($id);
145
            }
145
            }
Línea 147... Línea 147...
147
        $this->assertFalse(\repository_nextcloud\issuer_management::is_valid_issuer($this->issuer));
147
        $this->assertFalse(\repository_nextcloud\issuer_management::is_valid_issuer($this->issuer));
148
    }
148
    }
149
    /**
149
    /**
150
     * Test if repository is disabled when ocs_endpoint is deleted.
150
     * Test if repository is disabled when ocs_endpoint is deleted.
151
     */
151
     */
152
    public function test_issuer_ocs() {
152
    public function test_issuer_ocs(): void {
153
        $idocs = $this->get_endpoint_id('ocs_endpoint');
153
        $idocs = $this->get_endpoint_id('ocs_endpoint');
154
        if (!empty($idocs)) {
154
        if (!empty($idocs)) {
155
            foreach ($idocs as $id) {
155
            foreach ($idocs as $id) {
156
                \core\oauth2\api::delete_endpoint($id);
156
                \core\oauth2\api::delete_endpoint($id);
157
            }
157
            }
Línea 160... Línea 160...
160
    }
160
    }
Línea 161... Línea 161...
161
 
161
 
162
    /**
162
    /**
163
     * Test if repository is disabled when userinfo_endpoint is deleted.
163
     * Test if repository is disabled when userinfo_endpoint is deleted.
164
     */
164
     */
165
    public function test_issuer_userinfo() {
165
    public function test_issuer_userinfo(): void {
166
        $idtoken = $this->get_endpoint_id('userinfo_endpoint');
166
        $idtoken = $this->get_endpoint_id('userinfo_endpoint');
167
        if (!empty($idtoken)) {
167
        if (!empty($idtoken)) {
168
            foreach ($idtoken as $id) {
168
            foreach ($idtoken as $id) {
169
                \core\oauth2\api::delete_endpoint($id);
169
                \core\oauth2\api::delete_endpoint($id);
Línea 173... Línea 173...
173
    }
173
    }
Línea 174... Línea 174...
174
 
174
 
175
    /**
175
    /**
176
     * Test if repository is disabled when token_endpoint is deleted.
176
     * Test if repository is disabled when token_endpoint is deleted.
177
     */
177
     */
178
    public function test_issuer_token() {
178
    public function test_issuer_token(): void {
179
        $idtoken = $this->get_endpoint_id('token_endpoint');
179
        $idtoken = $this->get_endpoint_id('token_endpoint');
180
        if (!empty($idtoken)) {
180
        if (!empty($idtoken)) {
181
            foreach ($idtoken as $id) {
181
            foreach ($idtoken as $id) {
182
                \core\oauth2\api::delete_endpoint($id);
182
                \core\oauth2\api::delete_endpoint($id);
Línea 186... Línea 186...
186
    }
186
    }
Línea 187... Línea 187...
187
 
187
 
188
    /**
188
    /**
189
     * Test if repository is disabled when auth_endpoint is deleted.
189
     * Test if repository is disabled when auth_endpoint is deleted.
190
     */
190
     */
191
    public function test_issuer_authorization() {
191
    public function test_issuer_authorization(): void {
192
        $idauth = $this->get_endpoint_id('authorization_endpoint');
192
        $idauth = $this->get_endpoint_id('authorization_endpoint');
193
        if (!empty($idauth)) {
193
        if (!empty($idauth)) {
194
            foreach ($idauth as $id) {
194
            foreach ($idauth as $id) {
195
                \core\oauth2\api::delete_endpoint($id);
195
                \core\oauth2\api::delete_endpoint($id);
Línea 198... Línea 198...
198
        $this->assertFalse(\repository_nextcloud\issuer_management::is_valid_issuer($this->issuer));
198
        $this->assertFalse(\repository_nextcloud\issuer_management::is_valid_issuer($this->issuer));
199
    }
199
    }
200
    /**
200
    /**
201
     * Test if repository throws an error when endpoint does not exist.
201
     * Test if repository throws an error when endpoint does not exist.
202
     */
202
     */
203
    public function test_parse_endpoint_url_error() {
203
    public function test_parse_endpoint_url_error(): void {
204
        $this->expectException(\repository_nextcloud\configuration_exception::class);
204
        $this->expectException(\repository_nextcloud\configuration_exception::class);
205
        \repository_nextcloud\issuer_management::parse_endpoint_url('notexisting', $this->issuer);
205
        \repository_nextcloud\issuer_management::parse_endpoint_url('notexisting', $this->issuer);
206
    }
206
    }
207
    /**
207
    /**
208
     * Test get_listing method with an example directory. Tests error cases.
208
     * Test get_listing method with an example directory. Tests error cases.
209
     */
209
     */
210
    public function test_get_listing_error() {
210
    public function test_get_listing_error(): void {
211
        $ret = $this->get_initialised_return_array();
211
        $ret = $this->get_initialised_return_array();
212
        $this->setUser();
212
        $this->setUser();
213
        // WebDAV socket is not opened.
213
        // WebDAV socket is not opened.
214
        $mock = $this->createMock(\webdav_client::class);
214
        $mock = $this->createMock(\webdav_client::class);
215
        $mock->expects($this->once())->method('open')->will($this->returnValue(false));
215
        $mock->expects($this->once())->method('open')->will($this->returnValue(false));
Línea 226... Línea 226...
226
        $this->assertEquals($ret, $this->repo->get_listing('/'));
226
        $this->assertEquals($ret, $this->repo->get_listing('/'));
227
    }
227
    }
228
    /**
228
    /**
229
     * Test get_listing method with an example directory. Tests the root directory.
229
     * Test get_listing method with an example directory. Tests the root directory.
230
     */
230
     */
231
    public function test_get_listing_root() {
231
    public function test_get_listing_root(): void {
232
        $this->setUser();
232
        $this->setUser();
233
        $ret = $this->get_initialised_return_array();
233
        $ret = $this->get_initialised_return_array();
Línea 234... Línea 234...
234
 
234
 
235
        // This is the expected response from the ls method.
235
        // This is the expected response from the ls method.
Línea 290... Línea 290...
290
    }
290
    }
291
    /**
291
    /**
292
     * Test get_listing method with an example directory. Tests a different directory than the root
292
     * Test get_listing method with an example directory. Tests a different directory than the root
293
     * directory.
293
     * directory.
294
     */
294
     */
295
    public function test_get_listing_directory() {
295
    public function test_get_listing_directory(): void {
296
        $ret = $this->get_initialised_return_array();
296
        $ret = $this->get_initialised_return_array();
297
        $this->setUser();
297
        $this->setUser();
Línea 298... Línea 298...
298
 
298
 
299
        // An additional directory path has to be added to the 'path' field within the returned array.
299
        // An additional directory path has to be added to the 'path' field within the returned array.
Línea 359... Línea 359...
359
        $this->assertEquals($ret, $ls);
359
        $this->assertEquals($ret, $ls);
360
    }
360
    }
361
    /**
361
    /**
362
     * Test the get_link method.
362
     * Test the get_link method.
363
     */
363
     */
364
    public function test_get_link_success() {
364
    public function test_get_link_success(): void {
365
        $mock = $this->getMockBuilder(\repository_nextcloud\ocs_client::class)->disableOriginalConstructor()->disableOriginalClone(
365
        $mock = $this->getMockBuilder(\repository_nextcloud\ocs_client::class)->disableOriginalConstructor()->disableOriginalClone(
366
            )->getMock();
366
            )->getMock();
367
        $file = '/datei';
367
        $file = '/datei';
368
        $expectedresponse = <<<XML
368
        $expectedresponse = <<<XML
369
<?xml version="1.0"?>
369
<?xml version="1.0"?>
Línea 419... Línea 419...
419
    }
419
    }
Línea 420... Línea 420...
420
 
420
 
421
    /**
421
    /**
422
     * get_link can get OCS failure responses. Test that this is handled appropriately.
422
     * get_link can get OCS failure responses. Test that this is handled appropriately.
423
     */
423
     */
424
    public function test_get_link_failure() {
424
    public function test_get_link_failure(): void {
425
        $mock = $this->getMockBuilder(\repository_nextcloud\ocs_client::class)->disableOriginalConstructor()->disableOriginalClone(
425
        $mock = $this->getMockBuilder(\repository_nextcloud\ocs_client::class)->disableOriginalConstructor()->disableOriginalClone(
426
            )->getMock();
426
            )->getMock();
427
        $file = '/datei';
427
        $file = '/datei';
428
        $expectedresponse = <<<XML
428
        $expectedresponse = <<<XML
Línea 459... Línea 459...
459
    }
459
    }
Línea 460... Línea 460...
460
 
460
 
461
    /**
461
    /**
462
     * get_link can get OCS responses that are not actually XML. Test that this is handled appropriately.
462
     * get_link can get OCS responses that are not actually XML. Test that this is handled appropriately.
463
     */
463
     */
464
    public function test_get_link_problem() {
464
    public function test_get_link_problem(): void {
465
        $mock = $this->getMockBuilder(\repository_nextcloud\ocs_client::class)->disableOriginalConstructor()->disableOriginalClone(
465
        $mock = $this->getMockBuilder(\repository_nextcloud\ocs_client::class)->disableOriginalConstructor()->disableOriginalClone(
466
            )->getMock();
466
            )->getMock();
467
        $file = '/datei';
467
        $file = '/datei';
468
        $expectedresponse = <<<JSON
468
        $expectedresponse = <<<JSON
Línea 489... Línea 489...
489
    }
489
    }
Línea 490... Línea 490...
490
 
490
 
491
    /**
491
    /**
492
     * Test get_file reference, merely returns the input if no optional_param is set.
492
     * Test get_file reference, merely returns the input if no optional_param is set.
493
     */
493
     */
494
    public function test_get_file_reference_withoutoptionalparam() {
494
    public function test_get_file_reference_withoutoptionalparam(): void {
495
        $this->assertEquals('/somefile', $this->repo->get_file_reference('/somefile'));
495
        $this->assertEquals('/somefile', $this->repo->get_file_reference('/somefile'));
Línea 496... Línea 496...
496
    }
496
    }
497
 
497
 
498
    /**
498
    /**
499
     * Test logout.
499
     * Test logout.
500
     */
500
     */
Línea 501... Línea 501...
501
    public function test_logout() {
501
    public function test_logout(): void {
502
        $mock = $this->createMock(\core\oauth2\client::class);
502
        $mock = $this->createMock(\core\oauth2\client::class);
503
 
503
 
Línea 516... Línea 516...
516
 
516
 
517
    }
517
    }
518
    /**
518
    /**
519
     * Test for the get_file method from the repository_nextcloud class.
519
     * Test for the get_file method from the repository_nextcloud class.
520
     */
520
     */
521
    public function test_get_file() {
521
    public function test_get_file(): void {
522
        // WebDAV socket is not open.
522
        // WebDAV socket is not open.
523
        $mock = $this->createMock(\webdav_client::class);
523
        $mock = $this->createMock(\webdav_client::class);
524
        $mock->expects($this->once())->method('open')->will($this->returnValue(false));
524
        $mock->expects($this->once())->method('open')->will($this->returnValue(false));
Línea 538... Línea 538...
538
    }
538
    }
Línea 539... Línea 539...
539
 
539
 
540
    /**
540
    /**
541
     * Test callback.
541
     * Test callback.
542
     */
542
     */
543
    public function test_callback() {
543
    public function test_callback(): void {
544
        $mock = $this->createMock(\core\oauth2\client::class);
544
        $mock = $this->createMock(\core\oauth2\client::class);
545
        // Should call check_login exactly once.
545
        // Should call check_login exactly once.
546
        $mock->expects($this->once())->method('log_out');
546
        $mock->expects($this->once())->method('log_out');
Línea 551... Línea 551...
551
        $this->repo->callback();
551
        $this->repo->callback();
552
    }
552
    }
553
    /**
553
    /**
554
     * Test check_login.
554
     * Test check_login.
555
     */
555
     */
556
    public function test_check_login() {
556
    public function test_check_login(): void {
557
        $mock = $this->createMock(\core\oauth2\client::class);
557
        $mock = $this->createMock(\core\oauth2\client::class);
558
        $mock->expects($this->once())->method('is_logged_in')->will($this->returnValue(true));
558
        $mock->expects($this->once())->method('is_logged_in')->will($this->returnValue(true));
559
        $this->set_private_property($mock, 'client');
559
        $this->set_private_property($mock, 'client');
Línea 560... Línea 560...
560
 
560
 
561
        $this->assertTrue($this->repo->check_login());
561
        $this->assertTrue($this->repo->check_login());
562
    }
562
    }
563
    /**
563
    /**
564
     * Test print_login.
564
     * Test print_login.
565
     */
565
     */
566
    public function test_print_login() {
566
    public function test_print_login(): void {
567
        $mock = $this->createMock(\core\oauth2\client::class);
567
        $mock = $this->createMock(\core\oauth2\client::class);
568
        $mock->expects($this->exactly(2))->method('get_login_url')->will($this->returnValue(new \moodle_url('url')));
568
        $mock->expects($this->exactly(2))->method('get_login_url')->will($this->returnValue(new \moodle_url('url')));
Línea 569... Línea 569...
569
        $this->set_private_property($mock, 'client');
569
        $this->set_private_property($mock, 'client');
Línea 590... Línea 590...
590
    }
590
    }
Línea 591... Línea 591...
591
 
591
 
592
    /**
592
    /**
593
     * Test the initiate_webdavclient function.
593
     * Test the initiate_webdavclient function.
594
     */
594
     */
595
    public function test_initiate_webdavclient() {
595
    public function test_initiate_webdavclient(): void {
Línea 596... Línea 596...
596
        global $CFG;
596
        global $CFG;
597
 
597
 
598
        $idwebdav = $this->get_endpoint_id('webdav_endpoint');
598
        $idwebdav = $this->get_endpoint_id('webdav_endpoint');
Línea 627... Línea 627...
627
    /**
627
    /**
628
     * Test supported_returntypes.
628
     * Test supported_returntypes.
629
     * FILE_INTERNAL | FILE_REFERENCE when no system account is connected.
629
     * FILE_INTERNAL | FILE_REFERENCE when no system account is connected.
630
     * FILE_INTERNAL | FILE_CONTROLLED_LINK | FILE_REFERENCE when a system account is connected.
630
     * FILE_INTERNAL | FILE_CONTROLLED_LINK | FILE_REFERENCE when a system account is connected.
631
     */
631
     */
632
    public function test_supported_returntypes() {
632
    public function test_supported_returntypes(): void {
633
        global $DB;
633
        global $DB;
634
        $this->assertEquals(FILE_INTERNAL | FILE_REFERENCE, $this->repo->supported_returntypes());
634
        $this->assertEquals(FILE_INTERNAL | FILE_REFERENCE, $this->repo->supported_returntypes());
635
        $dataobject = new \stdClass();
635
        $dataobject = new \stdClass();
636
        $dataobject->timecreated = time();
636
        $dataobject->timecreated = time();
637
        $dataobject->timemodified = time();
637
        $dataobject->timemodified = time();
Línea 652... Línea 652...
652
     * The reference_file_selected() method is called every time a FILE_CONTROLLED_LINK is chosen for upload.
652
     * The reference_file_selected() method is called every time a FILE_CONTROLLED_LINK is chosen for upload.
653
     * Since the function is very long the private function are tested separately, and merely the abortion of the
653
     * Since the function is very long the private function are tested separately, and merely the abortion of the
654
     * function are tested.
654
     * function are tested.
655
     *
655
     *
656
     */
656
     */
657
    public function test_reference_file_selected_error() {
657
    public function test_reference_file_selected_error(): void {
658
        $this->repo->disabled = true;
658
        $this->repo->disabled = true;
659
        $this->expectException(\repository_exception::class);
659
        $this->expectException(\repository_exception::class);
660
        $this->repo->reference_file_selected('', \context_system::instance(), '', '', '');
660
        $this->repo->reference_file_selected('', \context_system::instance(), '', '', '');
Línea 661... Línea 661...
661
 
661
 
Línea 712... Línea 712...
712
    }
712
    }
Línea 713... Línea 713...
713
 
713
 
714
    /**
714
    /**
715
     * Test the send_file function for access controlled links.
715
     * Test the send_file function for access controlled links.
716
     */
716
     */
717
    public function test_send_file_errors() {
717
    public function test_send_file_errors(): void {
718
        $fs = get_file_storage();
718
        $fs = get_file_storage();
719
        $storedfile = $fs->create_file_from_reference([
719
        $storedfile = $fs->create_file_from_reference([
720
            'contextid' => \context_system::instance()->id,
720
            'contextid' => \context_system::instance()->id,
721
            'component' => 'core',
721
            'component' => 'core',