Automatically generated installer lang files
[moodle.git] / calendar / tests / coursecat_proxy_test.php
blob669105cae294edc0e70a5ee5407aa7a1320338ad
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 namespace core_calendar;
19 use core_calendar\local\event\proxies\coursecat_proxy;
21 /**
22 * coursecat_proxy testcase.
24 * @package core_calendar
25 * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 class coursecat_proxy_test extends \advanced_testcase {
30 public function test_valid_coursecat() {
31 global $DB;
32 $this->resetAfterTest();
34 $name = '2027-2028 Academic Year';
35 $generator = $this->getDataGenerator();
36 $category = $generator->create_category([
37 'name' => $name,
38 ]);
39 \cache_helper::purge_by_event('changesincoursecat');
41 // Fetch the proxy.
42 $startreads = $DB->perf_get_reads();
43 $proxy = new coursecat_proxy($category->id);
44 $this->assertInstanceOf(coursecat_proxy::class, $proxy);
45 $this->assertEquals(0, $DB->perf_get_reads() - $startreads);
47 // Fetch the ID - this is known and doesn't require a cache read.
48 $this->assertEquals($category->id, $proxy->get('id'));
49 $this->assertEquals(0, $DB->perf_get_reads() - $startreads);
51 // Fetch the name - not known, and requires a read.
52 $this->assertEquals($name, $proxy->get('name'));
53 $this->assertEquals(1, $DB->perf_get_reads() - $startreads);
55 $this->assertInstanceOf('core_course_category', $proxy->get_proxied_instance());