See Release Notes
Long Term Support Release
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 */ 32 class googledocs_root_content_test extends \googledocs_content_testcase { 33 34 /** 35 * Test get_content_nodes(). 36 * 37 * @dataProvider get_content_nodes_provider 38 * @param array $shareddrives The array containing the existing shared drives 39 * @param array $expected The expected array which contains the generated repository content nodes 40 */ 41 public function test_get_content_nodes(array $shareddrives, array $expected) { 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 $rootbrowser = new googledocs_root_content($servicemock, 57 \repository_googledocs::REPOSITORY_ROOT_ID . '|Google+Drive', false); 58 $contentnodes = $rootbrowser->get_content_nodes('', [$this, 'filter']); 59 60 // Assert that the returned array of repository content nodes is equal to the expected one. 61 $this->assertEquals($expected, $contentnodes); 62 } 63 64 /** 65 * Data provider for test_get_content_nodes(). 66 * 67 * @return array 68 */ 69 public function get_content_nodes_provider(): array { 70 71 $rootid = \repository_googledocs::REPOSITORY_ROOT_ID; 72 $mydriveid = \repository_googledocs::MY_DRIVE_ROOT_ID; 73 $shareddrivesid = \repository_googledocs::SHARED_DRIVES_ROOT_ID; 74 75 return [ 76 'Shared drives exist.' => 77 [ 78 [ 79 $this->create_google_drive_shared_drive_object('d85b21c0f86cb5', 'Shared Drive 1'), 80 $this->create_google_drive_shared_drive_object('d85b21c0f86cb0', 'Shared Drive 3'), 81 ], 82 [ 83 $this->create_folder_content_node_array($mydriveid, 84 get_string('mydrive', 'repository_googledocs'), 85 "{$rootid}|Google+Drive"), 86 $this->create_folder_content_node_array($shareddrivesid, 87 get_string('shareddrives', 'repository_googledocs'), 88 "{$rootid}|Google+Drive"), 89 ], 90 ], 91 'Shared drives do not exist.' => 92 [ 93 [], 94 [ 95 $this->create_folder_content_node_array($mydriveid, 96 get_string('mydrive', 'repository_googledocs'), 97 "{$rootid}|Google+Drive"), 98 ], 99 ], 100 ]; 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body