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 repository root 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_root_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 array $expected The expected array which contains the generated repository content nodes
39
     */
11 efrain 40
    public function test_get_content_nodes(array $shareddrives, array $expected): void {
1 efrain 41
        // Mock the service object.
42
        $servicemock = $this->createMock(\repository_googledocs\rest::class);
43
 
44
        // Assert that the call() method is being called only once with the given arguments to fetch the existing
45
        // shared drives. Define the returned data object by this call.
46
        $servicemock->expects($this->once())
47
            ->method('call')
48
            ->with('shared_drives_list', [])
49
            ->willReturn((object)[
50
                'kind' => 'drive#driveList',
51
                'nextPageToken' => 'd838181f30b0f5',
52
                'drives' => $shareddrives,
53
            ]);
54
 
55
        $rootbrowser = new googledocs_root_content($servicemock,
56
            \repository_googledocs::REPOSITORY_ROOT_ID . '|Google+Drive', false);
57
        $contentnodes = $rootbrowser->get_content_nodes('', [$this, 'filter']);
58
 
59
        // Assert that the returned array of repository content nodes is equal to the expected one.
60
        $this->assertEquals($expected, $contentnodes);
61
    }
62
 
63
    /**
64
     * Data provider for test_get_content_nodes().
65
     *
66
     * @return array
67
     */
1441 ariadna 68
    public static function get_content_nodes_provider(): array {
1 efrain 69
        $rootid = \repository_googledocs::REPOSITORY_ROOT_ID;
70
        $mydriveid = \repository_googledocs::MY_DRIVE_ROOT_ID;
71
        $shareddrivesid = \repository_googledocs::SHARED_DRIVES_ROOT_ID;
72
 
73
        return [
1441 ariadna 74
            'Shared drives exist.' => [
1 efrain 75
                [
1441 ariadna 76
                    self::create_google_drive_shared_drive_object('d85b21c0f86cb5', 'Shared Drive 1'),
77
                    self::create_google_drive_shared_drive_object('d85b21c0f86cb0', 'Shared Drive 3'),
1 efrain 78
                ],
79
                [
1441 ariadna 80
                    self::create_folder_content_node_array($mydriveid,
81
                        get_string('mydrive', 'repository_googledocs'),
82
                        "{$rootid}|Google+Drive"),
83
                    self::create_folder_content_node_array($shareddrivesid,
84
                        get_string('shareddrives', 'repository_googledocs'),
85
                        "{$rootid}|Google+Drive"),
1 efrain 86
                ],
1441 ariadna 87
            ],
88
            'Shared drives do not exist.' => [
89
                [],
90
                [
91
                    self::create_folder_content_node_array($mydriveid,
92
                        get_string('mydrive', 'repository_googledocs'),
93
                        "{$rootid}|Google+Drive"),
94
                ],
95
            ],
1 efrain 96
        ];
97
    }
98
}