Merge branch 'MDL-64851-master' of https://github.com/s-cenni/MDL-64851
[moodle.git] / blog / tests / external_test.php
CommitLineData
bb96ff71
JL
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.
13//
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
17/**
18 * Unit tests for blog external API.
19 *
20 * @package core_blog
21 * @copyright 2018 Juan Leyva
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27global $CFG;
28require_once($CFG->dirroot . '/blog/locallib.php');
29require_once($CFG->dirroot . '/blog/lib.php');
30
31/**
32 * Unit tests for blog external API.
33 *
34 * @package core_blog
35 * @copyright 2018 Juan Leyva
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class core_blog_external_testcase extends advanced_testcase {
39
40 private $courseid;
41 private $cmid;
42 private $userid;
43 private $groupid;
44 private $tagid;
45 private $postid;
46
47 protected function setUp() {
48 global $DB, $CFG;
49 parent::setUp();
50
51 $this->resetAfterTest();
52
53 // Create default course.
54 $course = $this->getDataGenerator()->create_course(array('category' => 1, 'shortname' => 'ANON'));
55 $this->assertNotEmpty($course);
56 $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
57 $this->assertNotEmpty($page);
58
59 // Create default user.
60 $user = $this->getDataGenerator()->create_user(array(
61 'username' => 'testuser',
62 'firstname' => 'Jimmy',
63 'lastname' => 'Kinnon'
64 ));
65 // Enrol user.
66 $this->getDataGenerator()->enrol_user($user->id, $course->id);
67
68 $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
69 $this->getDataGenerator()->create_group_member(array('groupid' => $group->id, 'userid' => $user->id));
70
71 // Create default post.
72 $post = new stdClass();
73 $post->userid = $user->id;
74 $post->courseid = $course->id;
75 $post->groupid = $group->id;
76 $post->content = 'test post content text';
77 $post->module = 'blog';
78 $post->id = $DB->insert_record('post', $post);
79
80 core_tag_tag::set_item_tags('core', 'post', $post->id, context_user::instance($user->id), array('tag1'));
81 $tagid = $DB->get_field('tag', 'id', array('name' => 'tag1'));
82
83 // Grab important ids.
84 $this->courseid = $course->id;
85 $this->cmid = $page->cmid;
86 $this->userid = $user->id;
87 $this->groupid = $group->id;
88 $this->tagid = $tagid;
89 $this->postid = $post->id;
90 $this->publishstate = 'site'; // To be override in tests.
91
92 // Set default blog level.
93 $CFG->bloglevel = BLOG_SITE_LEVEL;
94 }
95
96 /**
97 * Get global public entries even for not authenticated users.
98 * We get the entry since is public.
99 */
100 public function test_get_public_entries_global_level_by_non_logged_users() {
101 global $CFG, $DB;
102
103 $CFG->bloglevel = BLOG_GLOBAL_LEVEL;
104 $CFG->forcelogin = 0;
105 // Set current entry global.
106 $DB->set_field('post', 'publishstate', 'public', array('id' => $this->postid));
107
108 $result = core_blog\external::get_entries();
109 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
110 $this->assertCount(1, $result['entries']);
6c344ff2
JL
111 $this->assertCount(1, $result['entries'][0]['tags']);
112 $this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
113
bb96ff71
JL
114 $this->assertEquals($this->postid, $result['entries'][0]['id']);
115 }
116
117 /**
118 * Get global public entries even for not authenticated users in closed site.
119 */
120 public function test_get_public_entries_global_level_by_non_logged_users_closed_site() {
121 global $CFG, $DB;
122
123 $CFG->bloglevel = BLOG_GLOBAL_LEVEL;
124 $CFG->forcelogin = 1;
125 // Set current entry global.
126 $DB->set_field('post', 'publishstate', 'public', array('id' => $this->postid));
127
128 $this->expectException('moodle_exception');
129 core_blog\external::get_entries();
130 }
131
132 /**
133 * Get global public entries for guest users.
134 * We get the entry since is public.
135 */
136 public function test_get_public_entries_global_level_by_guest_users() {
137 global $CFG, $DB;
138
139 $CFG->bloglevel = BLOG_GLOBAL_LEVEL;
140 // Set current entry global.
141 $DB->set_field('post', 'publishstate', 'public', array('id' => $this->postid));
142
143 $this->setGuestUser();
144 $result = core_blog\external::get_entries();
145 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
146 $this->assertCount(1, $result['entries']);
6c344ff2
JL
147 $this->assertCount(1, $result['entries'][0]['tags']);
148 $this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
149
bb96ff71
JL
150 $this->assertEquals($this->postid, $result['entries'][0]['id']);
151 }
152
153 /**
154 * Get global not public entries even for not authenticated users withouth being authenticated.
155 * We don't get any because they are not public (restricted to site users).
156 */
157 public function test_get_not_public_entries_global_level_by_non_logged_users() {
158 global $CFG;
159
160 $CFG->bloglevel = BLOG_GLOBAL_LEVEL;
161
162 $result = core_blog\external::get_entries();
163 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
164 $this->assertCount(0, $result['entries']);
165 }
166
167 /**
168 * Get global not public entries users being guest.
169 * We don't get any because they are not public (restricted to real site users).
170 */
171 public function test_get_not_public_entries_global_level_by_guest_user() {
172 global $CFG;
173
174 $CFG->bloglevel = BLOG_GLOBAL_LEVEL;
175
176 $this->setGuestUser();
177 $result = core_blog\external::get_entries();
178 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
179 $this->assertCount(0, $result['entries']);
180 }
181
182 /**
183 * Get site not public entries for not authenticated users.
184 * We don't get any because they are not public (restricted to real site users).
185 */
186 public function test_get_not_public_entries_site_level_by_non_logged_users() {
187 $this->expectException('require_login_exception'); // In this case we get a security exception.
188 $result = core_blog\external::get_entries();
189 }
190
191 /**
192 * Get site not public entries for guest users.
193 * We don't get any because they are not public (restricted to real site users).
194 */
195 public function test_get_not_public_entries_site_level_by_guest_users() {
196
197 $this->setGuestUser();
198 $result = core_blog\external::get_entries();
199 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
200 $this->assertCount(0, $result['entries']);
201 }
202
203 /**
204 * Get site entries at site level by system users.
205 */
206 public function test_get_site_entries_site_level_by_normal_users() {
207
208 $this->setUser($this->userid);
209 $result = core_blog\external::get_entries();
210 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
211 $this->assertCount(1, $result['entries']);
212 $this->assertEquals($this->postid, $result['entries'][0]['id']);
213 }
214
215 /**
216 * Get draft site entries by authors.
217 */
218 public function test_get_draft_entries_site_level_by_author_users() {
219 global $DB;
220
221 // Set current entry global.
222 $DB->set_field('post', 'publishstate', 'draft', array('id' => $this->postid));
223
224 $this->setUser($this->userid);
225 $result = core_blog\external::get_entries();
226 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
227 $this->assertCount(1, $result['entries']);
228 $this->assertEquals($this->postid, $result['entries'][0]['id']);
229 }
230
231 /**
232 * Get draft site entries by not authors.
233 */
234 public function test_get_draft_entries_site_level_by_not_author_users() {
235 global $DB;
236
237 // Set current entry global.
238 $DB->set_field('post', 'publishstate', 'draft', array('id' => $this->postid));
239 $user = $this->getDataGenerator()->create_user();
240
241 $this->setUser($user);
242 $result = core_blog\external::get_entries();
243 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
244 $this->assertCount(0, $result['entries']);
245 }
246
247 /**
248 * Get draft site entries by admin.
249 */
250 public function test_get_draft_entries_site_level_by_admin_users() {
251 global $DB;
252
253 // Set current entry global.
254 $DB->set_field('post', 'publishstate', 'draft', array('id' => $this->postid));
255 $user = $this->getDataGenerator()->create_user();
256
257 $this->setAdminUser();
258 $result = core_blog\external::get_entries();
259 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
260 $this->assertCount(1, $result['entries']);
261 $this->assertEquals($this->postid, $result['entries'][0]['id']);
262 }
263
264 /**
265 * Get draft user entries by authors.
266 */
267 public function test_get_draft_entries_user_level_by_author_users() {
268 global $CFG, $DB;
269
270 $CFG->bloglevel = BLOG_USER_LEVEL;
271 // Set current entry global.
272 $DB->set_field('post', 'publishstate', 'draft', array('id' => $this->postid));
273
274 $this->setUser($this->userid);
275 $result = core_blog\external::get_entries();
276 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
277 $this->assertCount(1, $result['entries']);
278 $this->assertEquals($this->postid, $result['entries'][0]['id']);
279 }
280
281 /**
282 * Get draft user entries by not authors.
283 */
284 public function test_get_draft_entries_user_level_by_not_author_users() {
285 global $CFG, $DB;
286
287 $CFG->bloglevel = BLOG_USER_LEVEL;
288 // Set current entry global.
289 $DB->set_field('post', 'publishstate', 'draft', array('id' => $this->postid));
290 $user = $this->getDataGenerator()->create_user();
291
292 $this->setUser($user);
293 $result = core_blog\external::get_entries();
294 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
295 $this->assertCount(0, $result['entries']);
296 }
297
298 /**
299 * Get draft user entries by admin.
300 */
301 public function test_get_draft_entries_user_level_by_admin_users() {
302 global $CFG, $DB;
303
304 $CFG->bloglevel = BLOG_USER_LEVEL;
305 // Set current entry global.
306 $DB->set_field('post', 'publishstate', 'draft', array('id' => $this->postid));
307 $user = $this->getDataGenerator()->create_user();
308
309 $this->setAdminUser();
310 $result = core_blog\external::get_entries();
311 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
312 $this->assertCount(1, $result['entries']);
313 $this->assertEquals($this->postid, $result['entries'][0]['id']);
314 }
315
316 /**
317 * Test get all entries including testing pagination.
318 */
319 public function test_get_all_entries_including_pagination() {
320 global $DB, $USER;
321
322 $DB->set_field('post', 'publishstate', 'site', array('id' => $this->postid));
323
324 // Create another entry.
325 $this->setAdminUser();
326 $newpost = new stdClass();
327 $newpost->userid = $USER->id;
328 $newpost->content = 'test post content text';
329 $newpost->module = 'blog';
330 $newpost->publishstate = 'site';
331 $newpost->created = time() + HOURSECS;
332 $newpost->lastmodified = time() + HOURSECS;
333 $newpost->id = $DB->insert_record('post', $newpost);
334
335 $this->setUser($this->userid);
336 $result = core_blog\external::get_entries();
337 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
338 $this->assertCount(2, $result['entries']);
339 $this->assertEquals(2, $result['totalentries']);
6c344ff2
JL
340 $this->assertCount(0, $result['entries'][0]['tags']);
341 $this->assertCount(1, $result['entries'][1]['tags']);
342 $this->assertEquals('tag1', $result['entries'][1]['tags'][0]['rawname']);
bb96ff71
JL
343
344 $result = core_blog\external::get_entries(array(), 0, 1);
345 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
346 $this->assertCount(1, $result['entries']);
347 $this->assertEquals(2, $result['totalentries']);
348 $this->assertEquals($newpost->id, $result['entries'][0]['id']);
349
350 $result = core_blog\external::get_entries(array(), 1, 1);
351 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
352 $this->assertCount(1, $result['entries']);
353 $this->assertEquals(2, $result['totalentries']);
354 $this->assertEquals($this->postid, $result['entries'][0]['id']);
355 }
356
357 /**
358 * Test get entries filtering by course.
359 */
360 public function test_get_entries_filtering_by_course() {
361 global $CFG, $DB;
362
363 $DB->set_field('post', 'publishstate', 'site', array('id' => $this->postid));
364
365 $this->setAdminUser();
366 $coursecontext = context_course::instance($this->courseid);
367 $anothercourse = $this->getDataGenerator()->create_course();
368
369 // Add blog associations with a course.
370 $blog = new blog_entry($this->postid);
371 $blog->add_association($coursecontext->id);
372
373 // There is one entry associated with a course.
374 $result = core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $this->courseid)));
375 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
376 $this->assertCount(1, $result['entries']);
6c344ff2
JL
377 $this->assertCount(1, $result['entries'][0]['tags']);
378 $this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
bb96ff71
JL
379
380 // There is no entry associated with a wrong course.
381 $result = core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $anothercourse->id)));
382 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
383 $this->assertCount(0, $result['entries']);
384
385 // There is no entry associated with a module.
386 $result = core_blog\external::get_entries(array(array('name' => 'cmid', 'value' => $this->cmid)));
387 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
388 $this->assertCount(0, $result['entries']);
389 }
390
391 /**
392 * Test get entries filtering by module.
393 */
394 public function test_get_entries_filtering_by_module() {
395 global $CFG, $DB;
396
397 $DB->set_field('post', 'publishstate', 'site', array('id' => $this->postid));
398
399 $this->setAdminUser();
400 $coursecontext = context_course::instance($this->courseid);
401 $contextmodule = context_module::instance($this->cmid);
402 $anothermodule = $this->getDataGenerator()->create_module('page', array('course' => $this->courseid));
403
404 // Add blog associations with a module.
405 $blog = new blog_entry($this->postid);
406 $blog->add_association($contextmodule->id);
407
408 // There is no entry associated with a course.
409 $result = core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $this->courseid)));
410 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
411 $this->assertCount(0, $result['entries']);
412
413 // There is one entry associated with a module.
414 $result = core_blog\external::get_entries(array(array('name' => 'cmid', 'value' => $this->cmid)));
415 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
416 $this->assertCount(1, $result['entries']);
417
418 // There is no entry associated with a wrong module.
419 $result = core_blog\external::get_entries(array(array('name' => 'cmid', 'value' => $anothermodule->cmid)));
420 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
421 $this->assertCount(0, $result['entries']);
422 }
423
424 /**
425 * Test get entries filtering by author.
426 */
427 public function test_get_entries_filtering_by_author() {
428 $this->setAdminUser();
429 // Filter by author.
430 $result = core_blog\external::get_entries(array(array('name' => 'userid', 'value' => $this->userid)));
431 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
432 $this->assertCount(1, $result['entries']);
433 // No author.
434 $anotheruser = $this->getDataGenerator()->create_user();
435 $result = core_blog\external::get_entries(array(array('name' => 'userid', 'value' => $anotheruser->id)));
436 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
437 $this->assertCount(0, $result['entries']);
438 }
439
440 /**
441 * Test get entries filtering by entry.
442 */
443 public function test_get_entries_filtering_by_entry() {
444 $this->setAdminUser();
445 // Filter by correct entry.
446 $result = core_blog\external::get_entries(array(array('name' => 'entryid', 'value' => $this->postid)));
447 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
448 $this->assertCount(1, $result['entries']);
449 // Non-existent entry.
450 $this->expectException('moodle_exception');
451 $result = core_blog\external::get_entries(array(array('name' => 'entryid', 'value' => -1)));
452 }
453
454 /**
455 * Test get entries filtering by search.
456 */
457 public function test_get_entries_filtering_by_search() {
458 $this->setAdminUser();
459 // Filter by correct search.
460 $result = core_blog\external::get_entries(array(array('name' => 'search', 'value' => 'test')));
461 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
462 $this->assertCount(1, $result['entries']);
463 // Non-existent search.
464 $result = core_blog\external::get_entries(array(array('name' => 'search', 'value' => 'abc')));
465 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
466 $this->assertCount(0, $result['entries']);
467 }
468
469 /**
470 * Test get entries filtering by tag.
471 */
472 public function test_get_entries_filtering_by_tag() {
473 $this->setAdminUser();
474 // Filter by correct tag.
475 $result = core_blog\external::get_entries(array(array('name' => 'tag', 'value' => 'tag1')));
476 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
477 $this->assertCount(1, $result['entries']);
478 // Create tag.
479 $tag = $this->getDataGenerator()->create_tag(array('userid' => $this->userid, 'name' => 'tag2',
480 'isstandard' => 1));
481
482 $result = core_blog\external::get_entries(array(array('name' => 'tag', 'value' => 'tag2')));
483 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
484 $this->assertCount(0, $result['entries']);
485 }
486
487 /**
488 * Test get entries filtering by tag id.
489 */
490 public function test_get_entries_filtering_by_tagid() {
491 $this->setAdminUser();
492 // Filter by correct tag.
493 $result = core_blog\external::get_entries(array(array('name' => 'tagid', 'value' => $this->tagid)));
494 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
495 $this->assertCount(1, $result['entries']);
496 // Non-existent tag.
497
498 // Create tag.
499 $tag = $this->getDataGenerator()->create_tag(array('userid' => $this->userid, 'name' => 'tag2',
500 'isstandard' => 1));
501
502 $result = core_blog\external::get_entries(array(array('name' => 'tagid', 'value' => $tag->id)));
503 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
504 $this->assertCount(0, $result['entries']);
505 }
506
507 /**
508 * Test get entries filtering by group.
509 */
510 public function test_get_entries_filtering_by_group() {
511 $this->setAdminUser();
512 // Add blog associations with a course.
513 $coursecontext = context_course::instance($this->courseid);
514 $blog = new blog_entry($this->postid);
515 $blog->add_association($coursecontext->id);
516
517 // Filter by correct group.
518 $result = core_blog\external::get_entries(array(array('name' => 'groupid', 'value' => $this->groupid)));
519 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
520 $this->assertCount(1, $result['entries']);
521 // Non-existent group.
522 $anotheruser = $this->getDataGenerator()->create_user();
523 $this->expectException('moodle_exception');
524 core_blog\external::get_entries(array(array('name' => 'groupid', 'value' => -1)));
525 }
526
527 /**
528 * Test get entries multiple filter.
529 */
530 public function test_get_entries_multiple_filter() {
531 $this->setAdminUser();
532 // Add blog associations with a course.
533 $coursecontext = context_course::instance($this->courseid);
534 $blog = new blog_entry($this->postid);
535 $blog->add_association($coursecontext->id);
536
537 $result = core_blog\external::get_entries(array(
538 array('name' => 'tagid', 'value' => $this->tagid),
539 array('name' => 'userid', 'value' => $this->userid),
540 ));
541 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
542 $this->assertCount(1, $result['entries']);
543
544 // Non-existent multiple filter.
545 $result = core_blog\external::get_entries(array(
546 array('name' => 'search', 'value' => 'www'),
547 array('name' => 'userid', 'value' => $this->userid),
548 ));
549 $result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
550 $this->assertCount(0, $result['entries']);
551 }
552
553 /**
554 * Test get entries filtering by invalid_filter.
555 */
556 public function test_get_entries_filtering_by_invalid_filter() {
557 $this->setAdminUser();
558 // Filter by incorrect filter.
559 $this->expectException('moodle_exception');
560 $result = core_blog\external::get_entries(array(array('name' => 'zzZZzz', 'value' => 'wwWWww')));
561 }
562
563 /**
564 * Test get entries when blog is disabled.
565 */
566 public function test_get_entries_blog_disabled() {
567 global $CFG;
568
569 $this->setAdminUser();
570 $CFG->enableblogs = 0;
571 // Filter by incorrect filter.
572 $this->expectException('moodle_exception');
573 $result = core_blog\external::get_entries(array(array('name' => 'zzZZzz', 'value' => 'wwWWww')));
574 }
ca48cc91
JL
575
576 /**
577 * Test view_blog_entries without filter.
578 */
579 public function test_view_blog_entries_without_filtering() {
580 // Test user with full capabilities.
581 $this->setUser($this->userid);
582 // Trigger and capture the event.
583 $sink = $this->redirectEvents();
584 $result = core_blog\external::view_entries();
585 $result = external_api::clean_returnvalue(core_blog\external::view_entries_returns(), $result);
586
587 $events = $sink->get_events();
588 $this->assertCount(1, $events);
589 $event = array_shift($events);
590 // Checking that the event contains the expected values (empty, no filtering done).
591 $this->assertInstanceOf('\core\event\blog_entries_viewed', $event);
592 $this->assertEmpty($event->get_data()['relateduserid']);
593 $this->assertEmpty($event->get_data()['other']['entryid']);
594 $this->assertEmpty($event->get_data()['other']['tagid']);
595 $this->assertEmpty($event->get_data()['other']['userid']);
596 $this->assertEmpty($event->get_data()['other']['modid']);
597 $this->assertEmpty($event->get_data()['other']['groupid']);
598 $this->assertEmpty($event->get_data()['other']['search']);
599 $this->assertEmpty($event->get_data()['other']['courseid']);
600 $this->assertEventContextNotUsed($event);
601 $this->assertNotEmpty($event->get_name());
602 }
603
604 /**
605 * Test view_blog_entries doing filtering.
606 */
607 public function test_view_blog_entries_with_filtering() {
608 // Test user with full capabilities.
609 $this->setUser($this->userid);
610 // Trigger and capture the event.
611 $sink = $this->redirectEvents();
612 $result = core_blog\external::view_entries(array(
613 array('name' => 'tagid', 'value' => $this->tagid),
614 array('name' => 'userid', 'value' => $this->userid),
615 ));
616 $result = external_api::clean_returnvalue(core_blog\external::view_entries_returns(), $result);
617
618 $events = $sink->get_events();
619 $this->assertCount(1, $events);
620 $event = array_shift($events);
621 // Checking that the event contains the expected values (filter by user and tag).
622 $this->assertInstanceOf('\core\event\blog_entries_viewed', $event);
623 $this->assertEquals($this->userid, $event->get_data()['relateduserid']);
624 $this->assertEmpty($event->get_data()['other']['entryid']);
625 $this->assertEquals($this->tagid, $event->get_data()['other']['tagid']);
626 $this->assertEquals($this->userid, $event->get_data()['other']['userid']);
627 $this->assertEmpty($event->get_data()['other']['modid']);
628 $this->assertEmpty($event->get_data()['other']['groupid']);
629 $this->assertEmpty($event->get_data()['other']['search']);
630 $this->assertEmpty($event->get_data()['other']['courseid']);
631 $this->assertEventContextNotUsed($event);
632 $this->assertNotEmpty($event->get_name());
633 }
bb96ff71
JL
634}
635