2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
20 * @package core_calendar
21 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 use core_calendar\local\event\proxies\std_proxy
;
32 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class core_calendar_std_proxy_testcase
extends advanced_testcase
{
37 * @var \stdClass[] $objects Array of objects to proxy.
41 public function setUp() {
46 'member3' => 'Something else'
50 'member2' => 87539319,
51 'member3' => 'nagot annat'
59 * @dataProvider test_proxy_testcases()
60 * @param int $id Object ID.
61 * @param string $member Object member to retrieve.
62 * @param mixed $expected Expected value of member.
64 public function test_proxy($id, $member, $expected) {
65 $proxy = new std_proxy($id, function($id) {
66 return $this->objects
[$id];
69 $this->assertEquals($proxy->get($member), $expected);
73 * Test setting values with a base class.
75 * @dataProvider test_proxy_testcases()
76 * @param int $id Object ID.
77 * @param string $member Object member to retrieve.
78 * @param mixed $storedvalue Value as would be stored externally.
80 public function test_base_values($id, $member, $storedvalue) {
81 $proxy = new std_proxy(
84 return $this->objects
[$id];
86 (object)['member1' => 'should clobber 1']
89 $expected = $member == 'member1' ?
'should clobber 1' : $storedvalue;
90 $this->assertEquals($proxy->get($member), $expected);
94 * Test getting a non existant member.
96 * @dataProvider test_get_set_testcases()
97 * @param int $id ID of the object being proxied.
99 public function test_get_invalid_member($id) {
100 $proxy = new std_proxy($id, function($id) {
101 return $this->objects
[$id];
104 $this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
105 $proxy->get('thisdoesnotexist');
109 * Test get proxied instance.
111 * @dataProvider test_get_set_testcases()
112 * @param int $id Object ID.
114 public function test_get_proxied_instance($id) {
115 $proxy = new std_proxy($id, function($id) {
116 return $this->objects
[$id];
119 $this->assertEquals($proxy->get_proxied_instance(), $this->objects
[$id]);
123 * Test cases for proxying test.
125 public function test_proxy_testcases() {
127 'Object 1 member 1' => [
132 'Object 1 member 2' => [
137 'Object 1 member 3' => [
142 'Object 2 member 1' => [
147 'Object 2 member 2' => [
152 'Object 3 member 3' => [
161 * Test cases for getting and setting tests.
163 public function test_get_set_testcases() {