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 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
declare(strict_types=1);
18
 
19
namespace core_reportbuilder;
20
 
21
use advanced_testcase;
22
use context_system;
23
use stdClass;
24
 
25
/**
26
 * Unit tests for the system report factory class
27
 *
28
 * @package     core_reportbuilder
29
 * @covers      \core_reportbuilder\system_report_factory
30
 * @copyright   2020 Paul Holden <paulh@moodle.com>
31
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class system_report_factory_test extends advanced_testcase {
34
 
35
    /**
36
     * Test creating a valid/available system report
37
     */
38
    public function test_create(): void {
39
        global $CFG;
40
        require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_available.php");
41
 
42
        $this->resetAfterTest();
43
 
44
        $systemreport = system_report_factory::create(system_report_available::class, context_system::instance());
45
        $this->assertInstanceOf(system_report::class, $systemreport);
46
    }
47
 
48
    /**
49
     * Test that creating a system report returns the same persistent if it already exists
50
     */
51
    public function test_create_previously_exists(): void {
52
        global $CFG;
53
        require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_available.php");
54
 
55
        $this->resetAfterTest();
56
 
57
        $systemreportone = system_report_factory::create(system_report_available::class, context_system::instance());
58
        $systemreporttwo = system_report_factory::create(system_report_available::class, context_system::instance());
59
 
60
        // Assert we have the same persistent for each.
61
        $this->assertEquals($systemreportone->get_report_persistent()->get('id'),
62
            $systemreporttwo->get_report_persistent()->get('id'));
63
    }
64
 
65
    /**
66
     * Test creating an system report with an invalid source
67
     */
68
    public function test_create_invalid(): void {
69
        $this->expectException(source_invalid_exception::class);
70
        system_report_factory::create(stdClass::class, context_system::instance());
71
    }
72
 
73
    /**
74
     * Test creating an unavailable system report
75
     */
76
    public function test_create_unavailable(): void {
77
        global $CFG;
78
        require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_unavailable.php");
79
 
80
        $this->resetAfterTest();
81
 
82
        $this->expectException(source_unavailable_exception::class);
83
        system_report_factory::create(system_report_unavailable::class, context_system::instance());
84
    }
85
}