MDL-63793 block_myoverview: Persist the user's paging limit preference
[moodle.git] / blocks / timeline / tests / privacy_test.php
CommitLineData
9e95193e
P
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 the block_timeline implementation of the privacy API.
19 *
20 * @package block_timeline
21 * @category test
22 * @copyright 2018 Peter Dias <peter@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28use \core_privacy\local\request\writer;
29use \block_timeline\privacy\provider;
30
31/**
32 * Unit tests for the block_timeline implementation of the privacy API.
33 *
34 * @copyright 2018 Peter Dias <peter@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class block_timeline_privacy_testcase extends \core_privacy\tests\provider_testcase {
38
39 /**
40 * Ensure that export_user_preferences returns no data if the user has not visited the myoverview block.
41 */
42 public function test_export_user_preferences_no_pref() {
43 $this->resetAfterTest();
44
45 $user = $this->getDataGenerator()->create_user();
46 provider::export_user_preferences($user->id);
47 $writer = writer::with_context(\context_system::instance());
48 $this->assertFalse($writer->has_any_data());
49 }
50
51 /**
52 * Test that the preference courses is exported properly.
53 */
54 public function test_export_user_preferences_date_sort_preference() {
55 $this->resetAfterTest();
56
57 $user = $this->getDataGenerator()->create_user();
58 set_user_preference('block_timeline_user_sort_preference', 'sortbydates', $user);
59
60 provider::export_user_preferences($user->id);
61 $writer = writer::with_context(\context_system::instance());
62 $blockpreferences = $writer->get_user_preferences('block_timeline');
63 $this->assertEquals('Sort by dates', $blockpreferences->block_timeline_user_sort_preference->value);
64 }
65
66 /**
67 * Test that the preference timeline is exported properly.
68 */
69 public function test_export_user_preferences_course_sort_preference() {
70 $this->resetAfterTest();
71
72 $user = $this->getDataGenerator()->create_user();
73 set_user_preference('block_timeline_user_sort_preference', 'sortbycourses', $user);
74
75 provider::export_user_preferences($user->id);
76 $writer = writer::with_context(\context_system::instance());
77 $blockpreferences = $writer->get_user_preferences('block_timeline');
78 $this->assertEquals('Sort by courses', $blockpreferences->block_timeline_user_sort_preference->value);
79 }
80
81 /**
82 * Test that the preference timeline is exported properly.
83 */
84 public function test_export_user_preferences_7day_filter_preference() {
85 $this->resetAfterTest();
86
87 $user = $this->getDataGenerator()->create_user();
88 set_user_preference('block_timeline_user_filter_preference', 'next7days', $user);
89
90 provider::export_user_preferences($user->id);
91 $writer = writer::with_context(\context_system::instance());
92 $blockpreferences = $writer->get_user_preferences('block_timeline');
93 $this->assertEquals('Next 7 days', $blockpreferences->block_timeline_user_filter_preference->value);
94 }
95
96 /**
97 * Test that the preference timeline is exported properly.
98 */
99 public function test_export_user_preferences_all_filter_preference() {
100 $this->resetAfterTest();
101
102 $user = $this->getDataGenerator()->create_user();
103 set_user_preference('block_timeline_user_filter_preference', 'all', $user);
104
105 provider::export_user_preferences($user->id);
106 $writer = writer::with_context(\context_system::instance());
107 $blockpreferences = $writer->get_user_preferences('block_timeline');
108 $this->assertEquals('All', $blockpreferences->block_timeline_user_filter_preference->value);
109 }
110}