MDL-62660 tool_dataprivacy: Add and update PHPUnit tests
[moodle.git] / admin / tool / monitor / tests / subscription_test.php
blobb3511b5e846f1622ed3c022b87f28ff65a9345f9
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.
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 defined('MOODLE_INTERNAL') || exit();
18 /**
19 * Unit tests for the subscription class.
20 * @since 3.2.0
22 * @package tool_monitor
23 * @category test
24 * @copyright 2016 Jake Dallimore <jrhdallimore@gmail.com>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 class tool_monitor_subscription_testcase extends advanced_testcase {
29 /**
30 * @var \tool_monitor\subscription $subscription object.
32 private $subscription;
34 /**
35 * Test set up.
37 public function setUp() {
38 $this->resetAfterTest(true);
40 // Create the mock subscription.
41 $sub = new stdClass();
42 $sub->id = 100;
43 $sub->name = 'My test rule';
44 $sub->courseid = 20;
45 $mockbuilder = $this->getMockBuilder('\tool_monitor\subscription');
46 $mockbuilder->setMethods(null);
47 $mockbuilder->setConstructorArgs(array($sub));
48 $this->subscription = $mockbuilder->getMock();
51 /**
52 * Test for the magic __isset method.
54 public function test_magic_isset() {
55 $this->assertEquals(true, isset($this->subscription->name));
56 $this->assertEquals(true, isset($this->subscription->courseid));
57 $this->assertEquals(false, isset($this->subscription->ruleid));
60 /**
61 * Test for the magic __get method.
63 * @expectedException coding_exception
65 public function test_magic_get() {
66 $this->assertEquals(20, $this->subscription->courseid);
67 $this->subscription->ruleid;