mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-61966 block_myoverview: Update to provider for user preferences.
This commit is contained in:
parent
6d4bc5bd34
commit
5eb8ad87fc
@ -27,20 +27,35 @@ namespace block_myoverview\privacy;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Privacy Subsystem for block_myoverview implementing null_provider.
|
||||
* Privacy Subsystem for block_myoverview.
|
||||
*
|
||||
* @copyright 2018 Zig Tan <zig@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements \core_privacy\local\metadata\null_provider {
|
||||
class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\user_preference_provider {
|
||||
|
||||
/**
|
||||
* Get the language string identifier with the component's language
|
||||
* file to explain why this plugin stores no data.
|
||||
* Returns meta-data information about the myoverview block.
|
||||
*
|
||||
* @return string
|
||||
* @param \core_privacy\local\metadata\collection $collection A collection of meta-data.
|
||||
* @return \core_privacy\local\metadata\collection Return the collection of meta-data.
|
||||
*/
|
||||
public static function get_reason() : string {
|
||||
return 'privacy:metadata';
|
||||
public static function get_metadata(\core_privacy\local\metadata\collection $collection) :
|
||||
\core_privacy\local\metadata\collection {
|
||||
$collection->add_user_preference('block_myoverview_last_tab', 'privacy:metadata:overviewlasttab');
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all user preferences for the myoverview block
|
||||
*
|
||||
* @param int $userid The userid of the user whose data is to be exported.
|
||||
*/
|
||||
public static function export_user_preferences(int $userid) {
|
||||
$preference = get_user_preferences('block_myoverview_last_tab', null, $userid);
|
||||
if (isset($preference)) {
|
||||
\core_privacy\local\request\writer::export_user_preference('block_myoverview', 'block_myoverview_last_tab',
|
||||
$preference, get_string('privacy:metadata:overviewlasttab', 'block_myoverview'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,4 @@ $string['sortbydates'] = 'Sort by dates';
|
||||
$string['timeline'] = 'Timeline';
|
||||
$string['viewcourse'] = 'View course';
|
||||
$string['viewcoursename'] = 'View course {$a}';
|
||||
$string['privacy:metadata'] = 'The Course overview block only shows data stored in other locations.';
|
||||
$string['privacy:metadata:overviewlasttab'] = 'This stores the last tab selected by the user on the overview block.';
|
||||
|
80
blocks/myoverview/tests/privacy_test.php
Normal file
80
blocks/myoverview/tests/privacy_test.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the block_myoverview implementation of the privacy API.
|
||||
*
|
||||
* @package block_myoverview
|
||||
* @category test
|
||||
* @copyright 2018 Adrian Greeve <adriangreeve.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_privacy\local\request\writer;
|
||||
use \block_myoverview\privacy\provider;
|
||||
|
||||
/**
|
||||
* Unit tests for the block_myoverview implementation of the privacy API.
|
||||
*
|
||||
* @copyright 2018 Adrian Greeve <adriangreeve.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_myoverview_privacy_testcase extends \core_privacy\tests\provider_testcase {
|
||||
|
||||
/**
|
||||
* Ensure that export_user_preferences returns no data if the user has not visited the myoverview block.
|
||||
*/
|
||||
public function test_export_user_preferences_no_pref() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
provider::export_user_preferences($user->id);
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
$this->assertFalse($writer->has_any_data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the preference courses is exported properly.
|
||||
*/
|
||||
public function test_export_user_preferences_course_preference() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
set_user_preference('block_myoverview_last_tab', 'courses', $user);
|
||||
|
||||
provider::export_user_preferences($user->id);
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
$blockpreferences = $writer->get_user_preferences('block_myoverview');
|
||||
$this->assertEquals('courses', $blockpreferences->block_myoverview_last_tab->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the preference timeline is exported properly.
|
||||
*/
|
||||
public function test_export_user_preferences_timeline_preference() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
set_user_preference('block_myoverview_last_tab', 'timeline', $user);
|
||||
|
||||
provider::export_user_preferences($user->id);
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
$blockpreferences = $writer->get_user_preferences('block_myoverview');
|
||||
$this->assertEquals('timeline', $blockpreferences->block_myoverview_last_tab->value);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user