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 |
namespace tool_monitor;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Unit tests for the subscription class.
|
|
|
21 |
* @since 3.2.0
|
|
|
22 |
*
|
|
|
23 |
* @package tool_monitor
|
|
|
24 |
* @category test
|
|
|
25 |
* @copyright 2016 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
class subscription_test extends \advanced_testcase {
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* @var \tool_monitor\subscription $subscription object.
|
|
|
32 |
*/
|
|
|
33 |
private $subscription;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Test set up.
|
|
|
37 |
*/
|
|
|
38 |
public function setUp(): void {
|
|
|
39 |
$this->resetAfterTest(true);
|
|
|
40 |
|
|
|
41 |
// Create the mock subscription.
|
|
|
42 |
$sub = new \stdClass();
|
|
|
43 |
$sub->id = 100;
|
|
|
44 |
$sub->name = 'My test rule';
|
|
|
45 |
$sub->courseid = 20;
|
|
|
46 |
$mockbuilder = $this->getMockBuilder('\tool_monitor\subscription');
|
|
|
47 |
$mockbuilder->onlyMethods([]);
|
|
|
48 |
$mockbuilder->setConstructorArgs(array($sub));
|
|
|
49 |
$this->subscription = $mockbuilder->getMock();
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Test for the magic __isset method.
|
|
|
54 |
*/
|
11 |
efrain |
55 |
public function test_magic_isset(): void {
|
1 |
efrain |
56 |
$this->assertEquals(true, isset($this->subscription->name));
|
|
|
57 |
$this->assertEquals(true, isset($this->subscription->courseid));
|
|
|
58 |
$this->assertEquals(false, isset($this->subscription->ruleid));
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Test for the magic __get method.
|
|
|
63 |
*/
|
11 |
efrain |
64 |
public function test_magic_get(): void {
|
1 |
efrain |
65 |
$this->assertEquals(20, $this->subscription->courseid);
|
|
|
66 |
$this->expectException(\coding_exception::class);
|
|
|
67 |
$this->subscription->ruleid;
|
|
|
68 |
}
|
|
|
69 |
}
|