Proyectos de Subversion Moodle

Rev

Rev 1 | | 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
/**
18
 * Tests for gradereport_user library functions.
19
 *
20
 * @package    gradereport_user
21
 * @copyright  2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
23
 */
24
namespace gradereport_user;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
global $CFG;
29
require_once($CFG->dirroot . '/grade/report/user/lib.php');
30
 
31
/**
32
 * Class gradereport_user_lib_testcase.
33
 *
34
 * @package    gradereport_user
35
 * @copyright  2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
37
 */
38
class lib_test extends \advanced_testcase {
39
 
40
    /**
41
     * @var stdClass The user.
42
     */
43
    private $user;
44
 
45
    /**
46
     * @var stdClass The course.
47
     */
48
    private $course;
49
 
50
    /**
51
     * @var \core_user\output\myprofile\tree The navigation tree.
52
     */
53
    private $tree;
54
 
55
    public function setUp(): void {
56
        $this->user = $this->getDataGenerator()->create_user();
57
        $this->course = $this->getDataGenerator()->create_course();
58
        $this->tree = new \core_user\output\myprofile\tree();
59
        $this->resetAfterTest();
60
    }
61
 
62
    /**
63
     * Tests the gradereport_user_myprofile_navigation() function.
64
     */
11 efrain 65
    public function test_gradereport_user_myprofile_navigation(): void {
1 efrain 66
        $this->setAdminUser();
67
        $iscurrentuser = false;
68
 
69
        gradereport_user_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
70
        $reflector = new \ReflectionObject($this->tree);
71
        $nodes = $reflector->getProperty('nodes');
72
        $this->assertArrayHasKey('grade', $nodes->getValue($this->tree));
73
    }
74
 
75
    /**
76
     * Tests the gradereport_user_myprofile_navigation() function for a user
77
     * without permission to view the grade node.
78
     */
11 efrain 79
    public function test_gradereport_user_myprofile_navigation_without_permission(): void {
1 efrain 80
        $this->setUser($this->user);
81
        $iscurrentuser = true;
82
 
83
        gradereport_user_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
84
        $reflector = new \ReflectionObject($this->tree);
85
        $nodes = $reflector->getProperty('nodes');
86
        $this->assertArrayNotHasKey('grade', $nodes->getValue($this->tree));
87
    }
88
}