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
namespace repository_googledocs\local\browser;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
global $CFG;
22
require_once($CFG->dirroot . '/repository/googledocs/tests/googledocs_content_testcase.php');
23
require_once($CFG->dirroot . '/repository/googledocs/lib.php');
24
 
25
/**
26
 * Class containing unit tests for the shared drives browser class.
27
 *
28
 * @package    repository_googledocs
29
 * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
1441 ariadna 32
final class googledocs_shared_drives_content_test extends \googledocs_content_testcase {
1 efrain 33
    /**
34
     * Test get_content_nodes().
35
     *
36
     * @dataProvider get_content_nodes_provider
37
     * @param array $shareddrives The array containing the existing shared drives
38
     * @param bool $sortcontent Whether the contents should be sorted in alphabetical order
39
     * @param array $expected The expected array which contains the generated repository content nodes
40
     */
11 efrain 41
    public function test_get_content_nodes(array $shareddrives, bool $sortcontent, array $expected): void {
1 efrain 42
        // Mock the service object.
43
        $servicemock = $this->createMock(\repository_googledocs\rest::class);
44
 
45
        // Assert that the call() method is being called only once with the given arguments to fetch the existing
46
        // shared drives. Define the returned data object by this call.
47
        $servicemock->expects($this->once())
48
            ->method('call')
49
            ->with('shared_drives_list', [])
50
            ->willReturn((object)[
51
                'kind' => 'drive#driveList',
52
                'nextPageToken' => 'd838181f30b0f5',
53
                'drives' => $shareddrives,
54
            ]);
55
 
56
        $path = \repository_googledocs::REPOSITORY_ROOT_ID . '|Google+Drive/' .
57
            \repository_googledocs::SHARED_DRIVES_ROOT_ID . '|Shared+Drives';
58
        $shareddrivesbrowser = new googledocs_shared_drives_content($servicemock, $path, $sortcontent);
59
        $contentnodes = $shareddrivesbrowser->get_content_nodes('', [$this, 'filter']);
60
 
61
        // Assert that the returned array of repository content nodes is equal to the expected one.
62
        $this->assertEquals($expected, $contentnodes);
63
    }
64
 
65
    /**
66
     * Data provider for test_get_content_nodes().
67
     *
68
     * @return array
69
     */
1441 ariadna 70
    public static function get_content_nodes_provider(): array {
1 efrain 71
        $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
72
        $shareddrivesid = \repository_googledocs::SHARED_DRIVES_ROOT_ID;
73
        $shareddrivesstring = get_string('shareddrives', 'repository_googledocs');
74
 
75
        return [
76
            'Shared drives exist; ordering applied.' =>
77
                [
78
                    [
1441 ariadna 79
                        self::create_google_drive_shared_drive_object('d85b21c0f86cb5', 'Shared Drive 1'),
80
                        self::create_google_drive_shared_drive_object('d85b21c0f86cb0', 'Shared Drive 3'),
81
                        self::create_google_drive_shared_drive_object('bed5a0f08d412a', 'Shared Drive 2'),
1 efrain 82
                    ],
83
                    true,
84
                    [
1441 ariadna 85
                        self::create_folder_content_node_array('d85b21c0f86cb5', 'Shared Drive 1',
1 efrain 86
                            "{$rootid}|Google+Drive/{$shareddrivesid}|" . urlencode($shareddrivesstring)),
1441 ariadna 87
                        self::create_folder_content_node_array('bed5a0f08d412a', 'Shared Drive 2',
1 efrain 88
                            "{$rootid}|Google+Drive/{$shareddrivesid}|" . urlencode($shareddrivesstring)),
1441 ariadna 89
                        self::create_folder_content_node_array('d85b21c0f86cb0', 'Shared Drive 3',
1 efrain 90
                            "{$rootid}|Google+Drive/{$shareddrivesid}|" . urlencode($shareddrivesstring)),
91
                    ],
92
                ],
93
            'Shared drives exist; ordering not applied.' =>
94
                [
95
                    [
1441 ariadna 96
                        self::create_google_drive_shared_drive_object('0c4ad262c65333', 'Shared Drive 3'),
97
                        self::create_google_drive_shared_drive_object('d85b21c0f86cb0', 'Shared Drive 1'),
98
                        self::create_google_drive_shared_drive_object('bed5a0f08d412a', 'Shared Drive 2'),
1 efrain 99
                    ],
100
                    false,
101
                    [
1441 ariadna 102
                        self::create_folder_content_node_array('0c4ad262c65333', 'Shared Drive 3',
1 efrain 103
                            "{$rootid}|Google+Drive/{$shareddrivesid}|" . urlencode($shareddrivesstring)),
1441 ariadna 104
                        self::create_folder_content_node_array('d85b21c0f86cb0', 'Shared Drive 1',
1 efrain 105
                            "{$rootid}|Google+Drive/{$shareddrivesid}|" . urlencode($shareddrivesstring)),
1441 ariadna 106
                        self::create_folder_content_node_array('bed5a0f08d412a', 'Shared Drive 2',
1 efrain 107
                            "{$rootid}|Google+Drive/{$shareddrivesid}|" . urlencode($shareddrivesstring)),
108
                    ],
109
                ],
110
            'Shared drives do not exist.' =>
111
                [
112
                    [],
113
                    false,
114
                    [],
115
                ],
116
        ];
117
    }
118
}