diff --git a/repository/googledocs/classes/local/node/file_node.php b/repository/googledocs/classes/local/node/file_node.php index bbcb7f032a5..142714c9469 100644 --- a/repository/googledocs/classes/local/node/file_node.php +++ b/repository/googledocs/classes/local/node/file_node.php @@ -31,6 +31,9 @@ class file_node implements node { /** @var string|null The title of the file node. */ private $title; + /** @var string The name of the file. */ + private $name; + /** @var string|null The file's export format. */ private $exportformat; @@ -54,6 +57,7 @@ class file_node implements node { public function __construct(\stdClass $gdfile) { $this->id = $gdfile->id; $this->title = $this->generate_file_title($gdfile); + $this->name = $gdfile->name; $this->exportformat = $this->generate_file_export_format($gdfile); $this->link = $this->generate_file_link($gdfile); $this->modified = ($gdfile->modifiedTime) ? strtotime($gdfile->modifiedTime) : ''; @@ -90,7 +94,7 @@ class file_node implements node { 'source' => json_encode( [ 'id' => $this->id, - 'name' => $this->title, + 'name' => $this->name, 'link' => $this->link, 'exportformat' => $this->exportformat, ] diff --git a/repository/googledocs/tests/googledocs_search_content_test.php b/repository/googledocs/tests/googledocs_search_content_test.php index f0b1339f037..4862bb1b9c9 100644 --- a/repository/googledocs/tests/googledocs_search_content_test.php +++ b/repository/googledocs/tests/googledocs_search_content_test.php @@ -125,7 +125,7 @@ class repository_googledocs_search_testcase extends \googledocs_content_testcase 'application/pdf', 'pdf', '1000', '', 'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download'), $this->create_google_drive_folder_object('0c4ad262c65333', 'Test folder 1'), - $this->create_google_drive_file_object('bed5a0f08d412a', 'Test file 1', + $this->create_google_drive_file_object('bed5a0f08d412a', 'Test file 1.pdf', 'application/pdf', 'pdf'), $this->create_google_drive_folder_object('9c4ad262c65333', 'Test folder 2'), ], @@ -134,10 +134,11 @@ class repository_googledocs_search_testcase extends \googledocs_content_testcase "{$rootid}|Google+Drive/{$searchnodeid}|" . urlencode("{$searchforstring} 'test'")), $this->create_folder_content_node_array('9c4ad262c65333', 'Test folder 2', "{$rootid}|Google+Drive/{$searchnodeid}|" . urlencode("{$searchforstring} 'test'")), - $this->create_file_content_node_array('bed5a0f08d412a', 'Test file 1', null, - '', 'https://googleusercontent.com/type/application/pdf', '', 'download'), - $this->create_file_content_node_array('d85b21c0f86cb0', 'Test file 3.pdf', '1000', - '', 'https://googleusercontent.com/type/application/pdf', + $this->create_file_content_node_array('bed5a0f08d412a', 'Test file 1.pdf', + 'Test file 1.pdf', null, '', 'https://googleusercontent.com/type/application/pdf', + '', 'download'), + $this->create_file_content_node_array('d85b21c0f86cb0', 'Test file 3.pdf', + 'Test file 3.pdf', '1000', '', 'https://googleusercontent.com/type/application/pdf', 'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download', 'download'), ], ], @@ -179,8 +180,8 @@ class repository_googledocs_search_testcase extends \googledocs_content_testcase ], [ $this->create_file_content_node_array('d85b21c0f86cb0', 'Testing file 3.pdf', - '1000', '', 'https://googleusercontent.com/type/application/pdf', - '', 'download'), + 'Testing file 3.pdf', '1000', '', + 'https://googleusercontent.com/type/application/pdf', '', 'download'), ], ], 'No content that matches the search criteria; shared drives do not exist.' => diff --git a/repository/googledocs/tests/local/browser/googledocs_drive_content_test.php b/repository/googledocs/tests/local/browser/googledocs_drive_content_test.php index 08a92c125c2..11f9763573a 100644 --- a/repository/googledocs/tests/local/browser/googledocs_drive_content_test.php +++ b/repository/googledocs/tests/local/browser/googledocs_drive_content_test.php @@ -120,7 +120,7 @@ class repository_googledocs_drive_browser_testcase extends \googledocs_content_t $this->create_google_drive_file_object('d85b21c0f86cb0', 'File 3.pdf', 'application/pdf', 'pdf', '1000'), $this->create_google_drive_folder_object('0c4ad262c65333', 'Folder 1'), - $this->create_google_drive_file_object('bed5a0f08d412a', 'File 1', + $this->create_google_drive_file_object('bed5a0f08d412a', 'File 1.pdf', 'application/pdf', 'pdf'), ], [ @@ -128,10 +128,12 @@ class repository_googledocs_drive_browser_testcase extends \googledocs_content_t "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"), $this->create_folder_content_node_array('1c4ad262c65333', 'Folder 2', "{$rootid}|Google+Drive/{$mydriveid}|My+Drive"), - $this->create_file_content_node_array('bed5a0f08d412a', 'File 1', null, '', - 'https://googleusercontent.com/type/application/pdf', '', 'download'), - $this->create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', '1000', '', - 'https://googleusercontent.com/type/application/pdf', '', 'download'), + $this->create_file_content_node_array('bed5a0f08d412a', 'File 1.pdf', 'File 1.pdf', + null, '', 'https://googleusercontent.com/type/application/pdf', '', + 'download'), + $this->create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', 'File 3.pdf', + '1000', '', 'https://googleusercontent.com/type/application/pdf', '', + 'download'), ], ], 'Only folders exist in the drive; shared drives do not exist; ordering not applied.' => @@ -171,10 +173,12 @@ class repository_googledocs_drive_browser_testcase extends \googledocs_content_t 'application/msword', 'doc', '2000'), ], [ - $this->create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', '1000', '', - 'https://googleusercontent.com/type/application/pdf', '', 'download'), - $this->create_file_content_node_array('f85b21c0f86cb0', 'File 2.doc', '2000', '', - 'https://googleusercontent.com/type/application/msword', '', 'download'), + $this->create_file_content_node_array('d85b21c0f86cb0', 'File 3.pdf', 'File 3.pdf', + '1000', '', 'https://googleusercontent.com/type/application/pdf', '', + 'download'), + $this->create_file_content_node_array('f85b21c0f86cb0', 'File 2.doc', 'File 2.doc', + '2000', '', 'https://googleusercontent.com/type/application/msword', '', + 'download'), ], ], 'Contents do not exist in the drive; shared drives do not exist.' => diff --git a/repository/googledocs/tests/local/node/file_node_test.php b/repository/googledocs/tests/local/node/file_node_test.php index fd98de9ab99..4723248e6d5 100644 --- a/repository/googledocs/tests/local/node/file_node_test.php +++ b/repository/googledocs/tests/local/node/file_node_test.php @@ -64,8 +64,9 @@ class file_node_testcase extends \repository_googledocs_testcase { $this->create_google_drive_file_object('d85b21c0f86cb0', 'File.pdf', 'application/pdf', 'pdf', '1000', '01/01/21 0:30'), [], - $this->create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', '1000', '1609432200', - 'https://googleusercontent.com/type/application/pdf', '', 'download'), + $this->create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', 'File.pdf', '1000', + '1609432200', 'https://googleusercontent.com/type/application/pdf', '', + 'download'), ], 'Google Drive file that has webContentLink and webViewLink.' => [ @@ -76,8 +77,8 @@ class file_node_testcase extends \repository_googledocs_testcase { [ 'documentformat' => 'rtf', ], - $this->create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', null, '', - 'https://googleusercontent.com/type/application/pdf', + $this->create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', 'File.pdf', null, + '', 'https://googleusercontent.com/type/application/pdf', 'https://drive.google.com/file/d/d85b21c0f86cb0/view?usp=drivesdk', 'download'), ], 'Google Drive file that has webContentLink and no webViewLink.' => @@ -86,8 +87,8 @@ class file_node_testcase extends \repository_googledocs_testcase { 'application/pdf', 'pdf', null, '', 'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download', ''), [], - $this->create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', null, '', - 'https://googleusercontent.com/type/application/pdf', + $this->create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', 'File.pdf', null, + '', 'https://googleusercontent.com/type/application/pdf', 'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download', 'download'), ], 'Google Drive file without an extension (Google document file; documentformat config set to rtf).' => @@ -97,7 +98,7 @@ class file_node_testcase extends \repository_googledocs_testcase { [ 'documentformat' => 'rtf', ], - $this->create_file_content_node_array('d85b21c0f86cb0', 'File.gdoc', '', '', + $this->create_file_content_node_array('d85b21c0f86cb0', 'File', 'File.gdoc', '', '', 'https://googleusercontent.com/type/application/vnd.google-apps.document', '', 'application/rtf'), ], diff --git a/repository/googledocs/tests/repository_googledocs_testcase.php b/repository/googledocs/tests/repository_googledocs_testcase.php index 9bb325d5f44..8dd541e56f8 100644 --- a/repository/googledocs/tests/repository_googledocs_testcase.php +++ b/repository/googledocs/tests/repository_googledocs_testcase.php @@ -54,6 +54,7 @@ abstract class repository_googledocs_testcase extends \advanced_testcase { * * @param string $id The ID of the file * @param string $name The name of the file + * @param string $title The title of the file node * @param string|null $size The size of the file * @param string $modified The date of the last modification * @param string $thumbnail The thumbnail of the file @@ -61,12 +62,12 @@ abstract class repository_googledocs_testcase extends \advanced_testcase { * @param string|null $exportformat The export format of the file * @return array The repository file node array */ - protected function create_file_content_node_array(string $id, string $name, ?string $size = null, + protected function create_file_content_node_array(string $id, string $name, string $title, ?string $size = null, string $modified = '', string $thumbnail = '' , string $link = '', string $exportformat = ''): array { return [ 'id' => $id, - 'title' => $name, + 'title' => $title, 'source' => json_encode([ 'id' => $id, 'name' => $name,