MDL-51177 core: Ignore built files in stylelint
[moodle.git] / calendar / tests / std_proxy_test.php
blobdc9f25e3efbd3d24ebd89190f631cc1bd8c82fc4
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/>.
17 /**
18 * std_proxy tests.
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;
29 /**
30 * std_proxy testcase.
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 {
36 /**
37 * @var \stdClass[] $objects Array of objects to proxy.
39 public $objects;
41 public function setUp() {
42 $this->objects = [
43 1 => (object) [
44 'member1' => 'Hello',
45 'member2' => 1729,
46 'member3' => 'Something else'
48 5 => (object) [
49 'member1' => 'Hej',
50 'member2' => 87539319,
51 'member3' => 'nagot annat'
56 /**
57 * Test proxying.
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];
67 });
69 $this->assertEquals($proxy->get($member), $expected);
72 /**
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(
82 $id,
83 function($id) {
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);
93 /**
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() {
126 return [
127 'Object 1 member 1' => [
129 'member1',
130 'Hello'
132 'Object 1 member 2' => [
134 'member2',
135 1729
137 'Object 1 member 3' => [
139 'member3',
140 'Something else'
142 'Object 2 member 1' => [
144 'member1',
145 'Hej'
147 'Object 2 member 2' => [
149 'member2',
150 87539319
152 'Object 3 member 3' => [
154 'member3',
155 'nagot annat'
161 * Test cases for getting and setting tests.
163 public function test_get_set_testcases() {
164 return [
165 'Object 1' => [1],
166 'Object 2' => [5]