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
/**
18
 * Provides the {@see \core_form\privacy\provider_test} class.
19
 *
20
 * @package     core_form
21
 * @category    test
22
 * @copyright   2018 David Mudrák <david@moodle.com>
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
namespace core_form\privacy;
26
 
27
use core_form\privacy\provider;
28
use core_privacy\local\request\writer;
29
 
30
/**
31
 * Unit tests for the privacy API implementation.
32
 *
33
 * @copyright 2018 David Mudrák <david@moodle.com>
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
1441 ariadna 36
final class provider_test extends \core_privacy\tests\provider_testcase {
1 efrain 37
    /**
38
     * When no preference exists, there should be no export.
39
     */
11 efrain 40
    public function test_no_preference(): void {
1 efrain 41
        global $USER;
42
        $this->resetAfterTest();
43
        $this->setAdminUser();
44
 
45
        provider::export_user_preferences($USER->id);
46
        $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
47
    }
48
 
49
    /**
50
     * Test that the recently selected filepicker view mode is exported.
51
     *
52
     * @dataProvider data_filemanager_recentviewmode
53
     * @param string $val Value of the preference filemanager_recentviewmode
54
     * @param string $desc Text describing the preference
55
     */
11 efrain 56
    public function test_filemanager_recentviewmode(string $val, string $desc): void {
1 efrain 57
        $this->resetAfterTest();
58
 
59
        // Create test user, add some preferences.
60
        $user = $this->getDataGenerator()->create_user();
61
        $this->setUser($user);
62
 
63
        set_user_preference('filemanager_recentviewmode', $val, $user);
64
 
65
        // Switch to admin user (so we can validate preferences of the correct user are being exported).
66
        $this->setAdminUser();
67
 
68
        // Export test users preferences.
69
        provider::export_user_preferences($user->id);
70
        $this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
71
 
72
        $prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_form');
73
        $this->assertNotEmpty($prefs->filemanager_recentviewmode);
74
        $this->assertNotEmpty($prefs->filemanager_recentviewmode->value);
75
        $this->assertNotEmpty($prefs->filemanager_recentviewmode->description);
76
        $this->assertEquals($val, $prefs->filemanager_recentviewmode->value);
77
        $this->assertStringContainsString($desc, $prefs->filemanager_recentviewmode->description);
78
    }
79
 
80
    /**
81
     * Provides data for the {@link self::test_filemanager_recentviewmode()} method.
82
     *
83
     * @return array
84
     */
1441 ariadna 85
    public static function data_filemanager_recentviewmode(): array {
1 efrain 86
        return [
87
            'icons' => [
88
                'val' => '1',
89
                'desc' => get_string('displayasicons', 'core_repository'),
90
            ],
91
            'tree' => [
92
                'val' => '2',
93
                'desc' => get_string('displayastree', 'core_repository'),
94
            ],
95
            'details' => [
96
                'val' => '3',
97
                'desc' => get_string('displaydetails', 'core_repository'),
98
            ],
99
            'unknown' => [
100
                'val' => 'unexpectedvalue_foo_bar',
101
                'desc' => 'unexpectedvalue_foo_bar',
102
            ],
103
        ];
104
    }
105
}