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\node;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
global $CFG;
22
require_once($CFG->dirroot . '/repository/googledocs/tests/repository_googledocs_testcase.php');
23
 
24
/**
25
 * Class containing unit tests for the repository file node class.
26
 *
27
 * @package    repository_googledocs
28
 * @copyright  2021 Mihail Geshoski <mihail@moodle.com>
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
1441 ariadna 31
final class file_node_test extends \repository_googledocs_testcase {
1 efrain 32
    /**
33
     * Test create_node_array().
34
     *
35
     * @dataProvider create_node_array_provider
36
     * @param \stdClass $gdfile The Google Drive file object
37
     * @param array $configsettings The googledoc repository config settings that should be set
38
     * @param array|null $expected The expected repository file node array
39
     */
11 efrain 40
    public function test_create_node_array(\stdClass $gdfile, array $configsettings, ?array $expected): void {
1 efrain 41
        $this->resetAfterTest();
42
        // Set the required config settings.
43
        array_walk($configsettings, function($value, $name) {
44
            set_config($name, $value, 'googledocs');
45
        });
46
 
47
        $filenode = new file_node($gdfile);
48
        $filenodearray = $filenode->create_node_array();
49
        // Assert that the returned repository file node array by create_node_array() is equal to the expected one.
50
        $this->assertEquals($expected, $filenodearray);
51
    }
52
 
53
    /**
54
     * Data provider for test_create_node_array().
55
     *
56
     * @return array
57
     */
1441 ariadna 58
    public static function create_node_array_provider(): array {
1 efrain 59
        return [
60
            'Google Drive file with an extension.' =>
61
                [
1441 ariadna 62
                    self::create_google_drive_file_object('d85b21c0f86cb0', 'File.pdf',
1 efrain 63
                        'application/pdf', 'pdf', '1000', '01/01/21 0:30'),
64
                    [],
1441 ariadna 65
                    self::create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', 'File.pdf', '1000',
1 efrain 66
                        '1609432200', 'https://googleusercontent.com/type/application/pdf', '',
67
                        'download'),
68
                ],
69
            'Google Drive file that has webContentLink and webViewLink.' =>
70
                [
1441 ariadna 71
                    self::create_google_drive_file_object('d85b21c0f86cb0', 'File.pdf',
1 efrain 72
                        'application/pdf', 'pdf', null, '',
73
                        'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download',
74
                        'https://drive.google.com/file/d/d85b21c0f86cb0/view?usp=drivesdk'),
75
                    [
76
                        'documentformat' => 'rtf',
77
                    ],
1441 ariadna 78
                    self::create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', 'File.pdf', null,
1 efrain 79
                        '', 'https://googleusercontent.com/type/application/pdf',
80
                        'https://drive.google.com/file/d/d85b21c0f86cb0/view?usp=drivesdk', 'download'),
81
                ],
82
            'Google Drive file that has webContentLink and no webViewLink.' =>
83
                [
1441 ariadna 84
                    self::create_google_drive_file_object('d85b21c0f86cb0', 'File.pdf',
1 efrain 85
                        'application/pdf', 'pdf', null, '',
86
                        'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download', ''),
87
                    [],
1441 ariadna 88
                    self::create_file_content_node_array('d85b21c0f86cb0', 'File.pdf', 'File.pdf', null,
1 efrain 89
                        '', 'https://googleusercontent.com/type/application/pdf',
90
                        'https://drive.google.com/uc?id=d85b21c0f86cb0&export=download', 'download'),
91
                ],
92
            'Google Drive file without an extension (Google document file; documentformat config set to rtf).' =>
93
                [
1441 ariadna 94
                    self::create_google_drive_file_object('d85b21c0f86cb0', 'File',
1 efrain 95
                        'application/vnd.google-apps.document', null),
96
                    [
97
                        'documentformat' => 'rtf',
98
                    ],
1441 ariadna 99
                    self::create_file_content_node_array('d85b21c0f86cb0', 'File', 'File.gdoc', '', '',
1 efrain 100
                        'https://googleusercontent.com/type/application/vnd.google-apps.document', '',
101
                        'application/rtf', 'document'),
102
                ],
103
            'Google Drive file without an extension (Google presentation file; presentationformat config not set).' =>
104
                [
1441 ariadna 105
                    self::create_google_drive_file_object('d85b21c0f86cb0', 'File',
1 efrain 106
                        'application/vnd.google-apps.presentation', null),
107
                    [
108
                        'documentformat' => 'rtf',
109
                    ],
110
                    null,
111
                ],
112
            'Google Drive file without an extension (File type not supported).' =>
113
                [
1441 ariadna 114
                    self::create_google_drive_file_object('d85b21c0f86cb0', 'File',
1 efrain 115
                        'application/vnd.google-apps.unknownmimetype', null),
116
                    [],
117
                    null,
118
                ],
119
        ];
120
    }
121
}