Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | 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 report library functions.
19
 *
20
 * @package    report_stats
21
 * @copyright  2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
23
 */
24
namespace report_stats;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
/**
29
 * Class report_stats_lib_testcase
30
 *
31
 * @package    report_stats
32
 * @copyright  2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
34
 */
35
class lib_test extends \advanced_testcase {
36
 
37
    /**
38
     * @var stdClass The user.
39
     */
40
    private $user;
41
 
42
    /**
43
     * @var stdClass The course.
44
     */
45
    private $course;
46
 
47
    /**
48
     * @var \core_user\output\myprofile\tree The navigation tree.
49
     */
50
    private $tree;
51
 
52
    public function setUp(): void {
53
        $this->user = $this->getDataGenerator()->create_user();
54
        $this->course = $this->getDataGenerator()->create_course();
55
        $this->tree = new \core_user\output\myprofile\tree();
56
        $this->resetAfterTest();
57
    }
58
 
59
    /**
60
     * Test report_log_supports_logstore.
61
     */
62
    public function test_report_participation_supports_logstore() {
63
        $logmanager = get_log_manager();
64
        $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store');
65
 
66
        $supportedstores = array(
67
            'logstore_standard' => '\logstore_standard\log\store'
68
        );
69
 
70
        // Make sure all supported stores are installed.
71
        $expectedstores = array_keys(array_intersect($allstores, $supportedstores));
72
        $stores = $logmanager->get_supported_logstores('report_stats');
73
        $stores = array_keys($stores);
74
        foreach ($expectedstores as $expectedstore) {
75
            $this->assertContains($expectedstore, $stores);
76
        }
77
    }
78
 
79
    /**
80
     * Tests the report_stats_myprofile_navigation() function.
81
     */
82
    public function test_report_stats_myprofile_navigation() {
83
        $this->setAdminUser();
84
        $iscurrentuser = false;
85
 
86
        // Enable stats.
87
        set_config('enablestats', true);
88
 
89
        report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
90
        $reflector = new \ReflectionObject($this->tree);
91
        $nodes = $reflector->getProperty('nodes');
92
        $this->assertArrayHasKey('stats', $nodes->getValue($this->tree));
93
    }
94
 
95
    /**
96
     * Tests the report_stats_myprofile_navigation() function when stats are disabled.
97
     */
98
    public function test_report_stats_myprofile_navigation_stats_disabled() {
99
        $this->setAdminUser();
100
        $iscurrentuser = false;
101
 
102
        // Disable stats.
103
        set_config('enablestats', false);
104
 
105
        report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
106
        $reflector = new \ReflectionObject($this->tree);
107
        $nodes = $reflector->getProperty('nodes');
108
        $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree));
109
    }
110
 
111
    /**
112
     * Tests the report_stats_myprofile_navigation() function without permission.
113
     */
114
    public function test_report_stats_myprofile_navigation_without_permission() {
115
        // Try to see as a user without permission.
116
        $this->setUser($this->user);
117
        $iscurrentuser = true;
118
 
119
        // Enable stats.
120
        set_config('enablestats', true);
121
 
122
        report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
123
        $reflector = new \ReflectionObject($this->tree);
124
        $nodes = $reflector->getProperty('nodes');
125
        $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree));
126
    }
127
}