MDL-63185 mod_quiz: replace existing tests to use new step
[moodle.git] / repository / flickr / tests / privacy_test.php
blob1d9613beef41bd98dd1474b51314aaaf2d0aab92
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/>.
16 /**
17 * Privacy tests for repository_flickr.
19 * @package repository_flickr
20 * @category test
21 * @copyright 2018 Zig Tan <zig@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 defined('MOODLE_INTERNAL') || die();
26 use \repository_flickr\privacy\provider;
27 use \core_privacy\local\request\approved_contextlist;
28 use \core_privacy\local\request\writer;
29 use \core_privacy\tests\provider_testcase;
31 /**
32 * Unit tests for repository/flickr/privacy/provider
34 * @copyright 2018 Zig Tan <zig@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class repository_flickr_privacy_testcase extends provider_testcase {
38 /**
39 * Overriding setUp() function to always reset after tests.
41 public function setUp() {
42 $this->resetAfterTest(true);
45 /**
46 * Test for provider::export_user_preferences().
48 public function test_export_user_preferences() {
49 global $DB;
51 // Test setup.
52 $user = $this->getDataGenerator()->create_user();
53 $this->setUser($user);
54 $contextlist = provider::get_contexts_for_userid($user->id);
55 $approvedcontextlist = new approved_contextlist($user, 'repository_flickr', $contextlist->get_contextids());
56 $user = $approvedcontextlist->get_user();
57 $contextuser = context_user::instance($user->id);
59 // Test exporting of Flickr repository user preferences *without* OAuth token/secret preference configured.
60 provider::export_user_preferences($user->id);
61 $writer = writer::with_context($contextuser);
63 // Verify there is no user preferences data exported.
64 $this->assertFalse($writer->has_any_data());
66 // Test exporting of Flickr repository user preferences *with* OAuth token/secret preference configured.
67 $preference = (object) [
68 'userid' => $user->id,
69 'name' => 'repository_flickr_access_token',
70 'value' => 'dummy flickr oauth access token'
72 $DB->insert_record('user_preferences', $preference);
73 $preference = (object) [
74 'userid' => $user->id,
75 'name' => 'repository_flickr_access_token_secret',
76 'value' => 'dummy flickr oauth access token secret'
78 $DB->insert_record('user_preferences', $preference);
79 provider::export_user_preferences($user->id);
80 $writer = writer::with_context($contextuser);
82 // Verify there is user preferences data exported.
83 $this->assertTrue($writer->has_any_data());
84 $userpreferences = $writer->get_user_preferences('repository_flickr');
86 // Verify the OAuth token is not an empty string value and the OAuth secret is an empty string value.
87 $accesstoken = $userpreferences->repository_flickr_access_token;
88 $this->assertFalse(empty($accesstoken->value));
89 $accesstokensecret = $userpreferences->repository_flickr_access_token_secret;
90 $this->assertTrue(empty($accesstokensecret->value));