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
/**
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
 */
1441 ariadna 35
final class lib_test extends \advanced_testcase {
1 efrain 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 {
1441 ariadna 53
        parent::setUp();
1 efrain 54
        $this->user = $this->getDataGenerator()->create_user();
55
        $this->course = $this->getDataGenerator()->create_course();
56
        $this->tree = new \core_user\output\myprofile\tree();
57
        $this->resetAfterTest();
58
    }
59
 
60
    /**
61
     * Test report_log_supports_logstore.
62
     */
11 efrain 63
    public function test_report_participation_supports_logstore(): void {
1 efrain 64
        $logmanager = get_log_manager();
65
        $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store');
66
 
67
        $supportedstores = array(
68
            'logstore_standard' => '\logstore_standard\log\store'
69
        );
70
 
71
        // Make sure all supported stores are installed.
72
        $expectedstores = array_keys(array_intersect($allstores, $supportedstores));
73
        $stores = $logmanager->get_supported_logstores('report_stats');
74
        $stores = array_keys($stores);
75
        foreach ($expectedstores as $expectedstore) {
76
            $this->assertContains($expectedstore, $stores);
77
        }
78
    }
79
 
80
    /**
81
     * Tests the report_stats_myprofile_navigation() function.
82
     */
11 efrain 83
    public function test_report_stats_myprofile_navigation(): void {
1 efrain 84
        $this->setAdminUser();
85
        $iscurrentuser = false;
86
 
87
        // Enable stats.
88
        set_config('enablestats', true);
89
 
90
        report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
91
        $reflector = new \ReflectionObject($this->tree);
92
        $nodes = $reflector->getProperty('nodes');
93
        $this->assertArrayHasKey('stats', $nodes->getValue($this->tree));
94
    }
95
 
96
    /**
97
     * Tests the report_stats_myprofile_navigation() function when stats are disabled.
98
     */
11 efrain 99
    public function test_report_stats_myprofile_navigation_stats_disabled(): void {
1 efrain 100
        $this->setAdminUser();
101
        $iscurrentuser = false;
102
 
103
        // Disable stats.
104
        set_config('enablestats', false);
105
 
106
        report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
107
        $reflector = new \ReflectionObject($this->tree);
108
        $nodes = $reflector->getProperty('nodes');
109
        $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree));
110
    }
111
 
112
    /**
113
     * Tests the report_stats_myprofile_navigation() function without permission.
114
     */
11 efrain 115
    public function test_report_stats_myprofile_navigation_without_permission(): void {
1 efrain 116
        // Try to see as a user without permission.
117
        $this->setUser($this->user);
118
        $iscurrentuser = true;
119
 
120
        // Enable stats.
121
        set_config('enablestats', true);
122
 
123
        report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
124
        $reflector = new \ReflectionObject($this->tree);
125
        $nodes = $reflector->getProperty('nodes');
126
        $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree));
127
    }
128
}