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