MDL-67271 core: Add test to find missing SVG icons
[moodle.git] / lib / tests / fixtures / event_fixtures.php
blob33d02ceb2ff09299bcb102e0ee352eb8e707dfc1
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_tests\event;
19 /**
20 * Fixtures for new event testing.
22 * @package core
23 * @category phpunit
24 * @copyright 2013 Petr Skoda {@link http://skodak.org}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
31 class unittest_executed extends \core\event\base {
32 public $nest = false;
34 public static function get_name() {
35 return 'xxx';
38 public function get_description() {
39 return 'yyy';
42 protected function init() {
43 $this->data['crud'] = 'u';
44 $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
47 public function get_url() {
48 return new \moodle_url('/somepath/somefile.php', array('id'=>$this->data['other']['sample']));
53 class unittest_observer {
54 public static $info = array();
55 public static $event = array();
57 public static function reset() {
58 self::$info = array();
59 self::$event = array();
62 public static function observe_one(unittest_executed $event) {
63 self::$info[] = 'observe_one-'.$event->other['sample'];
64 self::$event[] = $event;
67 public static function external_observer(unittest_executed $event) {
68 self::$info[] = 'external_observer-'.$event->other['sample'];
69 self::$event[] = $event;
72 public static function broken_observer(unittest_executed $event) {
73 self::$info[] = 'broken_observer-'.$event->other['sample'];
74 self::$event[] = $event;
75 throw new \Exception('someerror');
78 public static function observe_all(\core\event\base $event) {
79 if (!($event instanceof unittest_executed)) {
80 self::$info[] = 'observe_all-unknown';
81 self::$event[] = $event;
82 return;
84 self::$event[] = $event;
85 if (!empty($event->nest)) {
86 self::$info[] = 'observe_all-nesting-'.$event->other['sample'];
87 unittest_executed::create(array('context'=>\context_system::instance(), 'other'=>array('sample'=>666, 'xx'=>666)))->trigger();
88 } else {
89 self::$info[] = 'observe_all-'.$event->other['sample'];
93 public static function observe_all_alt(\core\event\base $event) {
94 self::$info[] = 'observe_all_alt';
95 self::$event[] = $event;
98 public static function legacy_handler($data) {
99 self::$info[] = 'legacy_handler-'.$data[0];
100 self::$event[] = $data;
104 class bad_event1 extends \core\event\base {
105 protected function init() {
106 //$this->data['crud'] = 'u';
107 $this->data['edulevel'] = self::LEVEL_OTHER;
111 class bad_event2 extends \core\event\base {
112 protected function init() {
113 $this->data['crud'] = 'u';
114 //$this->data['edulevel'] = 10;
118 class bad_event2b extends \core\event\base {
119 protected function init() {
120 $this->data['crud'] = 'u';
121 // Invalid level value.
122 $this->data['edulevel'] = -1;
126 class bad_event3 extends \core\event\base {
127 protected function init() {
128 $this->data['crud'] = 'u';
129 $this->data['edulevel'] = self::LEVEL_OTHER;
130 unset($this->data['courseid']);
134 class bad_event4 extends \core\event\base {
135 protected function init() {
136 $this->data['crud'] = 'u';
137 $this->data['edulevel'] = self::LEVEL_OTHER;
138 $this->data['xxx'] = 1;
142 class bad_event5 extends \core\event\base {
143 protected function init() {
144 $this->data['crud'] = 'x';
145 $this->data['edulevel'] = self::LEVEL_OTHER;
149 class bad_event6 extends \core\event\base {
150 protected function init() {
151 $this->data['crud'] = 'c';
152 $this->data['edulevel'] = self::LEVEL_OTHER;
153 $this->data['objecttable'] = 'xxx_xxx_xx';
157 class bad_event7 extends \core\event\base {
158 protected function init() {
159 $this->data['crud'] = 'c';
160 $this->data['edulevel'] = self::LEVEL_OTHER;
161 $this->data['objecttable'] = null;
165 class bad_event8 extends \core\event\base {
166 protected function init() {
167 $this->data['crud'] = 'c';
168 $this->data['edulevel'] = self::LEVEL_OTHER;
169 $this->data['objecttable'] = 'user';
173 class problematic_event1 extends \core\event\base {
174 protected function init() {
175 $this->data['crud'] = 'u';
176 $this->data['edulevel'] = self::LEVEL_OTHER;
180 class problematic_event2 extends \core\event\base {
181 protected function init() {
182 $this->data['crud'] = 'c';
183 $this->data['edulevel'] = self::LEVEL_OTHER;
184 $this->context = \context_system::instance();
188 class problematic_event3 extends \core\event\base {
189 protected function init() {
190 $this->data['crud'] = 'c';
191 $this->data['edulevel'] = self::LEVEL_OTHER;
192 $this->context = \context_system::instance();
195 protected function validate_data() {
196 parent::validate_data();
197 if (empty($this->data['other'])) {
198 debugging('other is missing');
203 class deprecated_event1 extends \core\event\base {
204 protected function init() {
205 $this->data['crud'] = 'c';
206 $this->data['level'] = self::LEVEL_TEACHING; // Tests edulevel hint.
207 $this->context = \context_system::instance();
211 class noname_event extends \core\event\base {
213 protected function init() {
214 $this->data['crud'] = 'c';
215 $this->data['edulevel'] = self::LEVEL_OTHER;
216 $this->context = \context_system::instance();
221 * Class course_module_viewed.
223 * Wrapper for testing \core\event\course_module_viewed.
225 class course_module_viewed extends \core\event\course_module_viewed {
226 protected function init() {
227 $this->data['crud'] = 'r';
228 $this->data['edulevel'] = self::LEVEL_OTHER;
229 $this->data['objecttable'] = 'feedback';
234 * Class course_module_viewed_noinit.
236 * Wrapper for testing \core\event\course_module_viewed.
238 class course_module_viewed_noinit extends \core\event\course_module_viewed {
242 * Event for testing core\event\grade_report_viewed.
244 class grade_report_viewed extends \core\event\grade_report_viewed {
248 * Event to test context used in event functions
250 class context_used_in_event extends \core\event\base {
251 public function get_description() {
252 return $this->context->instanceid . " Description";
255 protected function init() {
256 $this->data['crud'] = 'u';
257 $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
258 $this->context = \context_system::instance();
261 public function get_url() {
262 return new \moodle_url('/somepath/somefile.php', array('id' => $this->context->instanceid));
267 * This is an explanation of the event.
268 * - I'm making a point here.
269 * - I have a second {@link something} point here.
270 * - whitespace is intentional to test it's removal.
273 * I have something else *Yeah* that.
277 * @package core
278 * @category phpunit
279 * @copyright 2014 Adrian Greeve <adrian@moodle.com>
280 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
282 class full_docblock extends \core\event\base {
284 protected function init() {
290 * We have only the description in the docblock
291 * and nothing else.
293 class docblock_test2 extends \core\event\base {
295 protected function init() {
301 * Calendar event created event.
303 * @property-read array $other {
304 * Extra information about the event.
306 * - int timestart: timestamp for event time start.
307 * - string name: Name of the event.
308 * - int repeatid: Id of the parent event if present, else 0.
311 * @package core
312 * @since Moodle 2.7
313 * @copyright 2014 onwards Adrian Greeve
314 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
316 class docblock_test3 extends \core\event\base {
318 protected function init() {
323 class static_info_viewing extends \core\event\base {
325 protected function init() {
326 $this->data['crud'] = 'r';
327 $this->data['edulevel'] = self::LEVEL_OTHER;
328 $this->data['objecttable'] = 'mod_unittest';