Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Privacy tests for repository_flickr.
18
 *
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
23
 */
24
namespace repository_flickr\privacy;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
use repository_flickr\privacy\provider;
29
use core_privacy\local\request\approved_contextlist;
30
use core_privacy\local\request\writer;
31
use core_privacy\tests\provider_testcase;
32
 
33
/**
34
 * Unit tests for repository/flickr/privacy/provider
35
 *
36
 * @copyright  2018 Zig Tan <zig@moodle.com>
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
1441 ariadna 39
final class provider_test extends provider_testcase {
1 efrain 40
    /**
41
     * Overriding setUp() function to always reset after tests.
42
     */
43
    public function setUp(): void {
1441 ariadna 44
        parent::setUp();
1 efrain 45
        $this->resetAfterTest(true);
46
    }
47
 
48
    /**
49
     * Test for provider::export_user_preferences().
50
     */
11 efrain 51
    public function test_export_user_preferences(): void {
1 efrain 52
        global $DB;
53
 
54
        // Test setup.
55
        $user = $this->getDataGenerator()->create_user();
56
        $this->setUser($user);
57
        $contextlist = provider::get_contexts_for_userid($user->id);
58
        $approvedcontextlist = new approved_contextlist($user, 'repository_flickr', $contextlist->get_contextids());
59
        $user = $approvedcontextlist->get_user();
60
        $contextuser = \context_user::instance($user->id);
61
 
62
        // Test exporting of Flickr repository user preferences *without* OAuth token/secret preference configured.
63
        provider::export_user_preferences($user->id);
64
        $writer = writer::with_context($contextuser);
65
 
66
        // Verify there is no user preferences data exported.
67
        $this->assertFalse($writer->has_any_data());
68
 
69
        // Test exporting of Flickr repository user preferences *with* OAuth token/secret preference configured.
70
        set_user_preferences([
71
            'repository_flickr_access_token' => 'dummy flickr oauth access token',
72
            'repository_flickr_access_token_secret' => 'dummy flickr oauth access token secret',
73
        ], $user->id);
74
 
75
        provider::export_user_preferences($user->id);
76
        $writer = writer::with_context($contextuser);
77
 
78
        // Verify there is user preferences data exported.
79
        $this->assertTrue($writer->has_any_data());
80
        $userpreferences = $writer->get_user_preferences('repository_flickr');
81
 
82
        // Verify the OAuth token is not an empty string value and the OAuth secret is an empty string value.
83
        $accesstoken = $userpreferences->repository_flickr_access_token;
84
        $this->assertFalse(empty($accesstoken->value));
85
        $accesstokensecret = $userpreferences->repository_flickr_access_token_secret;
86
        $this->assertTrue(empty($accesstokensecret->value));
87
    }
88
}