Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of the Zoom plugin for 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
/**
18
 * Unit tests for error handling for zoom exceptions.
19
 *
20
 * @package    mod_zoom
21
 * @copyright  2019 UC Regents
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_zoom;
26
 
27
use basic_testcase;
28
 
29
/**
30
 * PHPunit testcase class.
31
 */
32
final class error_handling_test extends basic_testcase {
33
    /**
34
     * Exception for when the meeting isn't found on Zoom.
35
     * @var not_found_exception
36
     */
37
    private $meetingnotfoundexception;
38
 
39
    /**
40
     * Exception for when the user isn't found on Zoom.
41
     * @var not_found_exception
42
     */
43
    private $usernotfoundexception;
44
 
45
    /**
46
     * Exception for when the user is found in the system but they haven't
47
     * accepted their invite, so they don't have permissions to do what was
48
     * requested.
49
     * @var not_found_exception
50
     */
51
    private $invaliduserexception;
52
 
53
    /**
54
     * Exception for when the meeting isn't found on Zoom.
55
     * @var not_found_exception
56
     */
57
    private $othererrorcodeexception;
58
 
59
    /**
60
     * Setup to ensure that fixtures are loaded.
61
     */
62
    public static function setUpBeforeClass(): void {
63
        global $CFG;
64
        require_once($CFG->dirroot . '/mod/zoom/locallib.php');
65
    }
66
 
67
    /**
68
     * Setup before every test.
69
     */
70
    public function setUp(): void {
71
        $this->meetingnotfoundexception = new not_found_exception('meeting not found', 3001);
72
        $this->usernotfoundexception = new not_found_exception('user not found', 1001);
73
        $this->invaliduserexception = new not_found_exception('invalid user found', 1120);
74
        $this->othererrorcodeexception = new not_found_exception('other exception', -1);
75
    }
76
 
77
    /**
78
     * Tests that uuid are encoded properly for use in web service calls.
79
     * @covers ::zoom_is_meeting_gone_error
80
     * @covers ::zoom_is_user_not_found_error
81
     */
82
    public function test_correct_error_recognition(): void {
83
        // Check meeting not found behavior.
84
        $this->assertTrue(zoom_is_meeting_gone_error($this->meetingnotfoundexception));
85
        $this->assertTrue(zoom_is_meeting_gone_error($this->usernotfoundexception));
86
        $this->assertTrue(zoom_is_meeting_gone_error($this->invaliduserexception));
87
        $this->assertFalse(zoom_is_meeting_gone_error($this->othererrorcodeexception));
88
 
89
        // Check user not found behavior.
90
        $this->assertTrue(zoom_is_user_not_found_error($this->usernotfoundexception));
91
        $this->assertTrue(zoom_is_user_not_found_error($this->invaliduserexception));
92
        $this->assertFalse(zoom_is_user_not_found_error($this->meetingnotfoundexception));
93
        $this->assertFalse(zoom_is_user_not_found_error($this->othererrorcodeexception));
94
    }
95
}