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
namespace core_editor\privacy;
18
 
19
use core_privacy\local\request\writer;
20
use core_editor\privacy\provider;
21
 
22
/**
23
 * Privacy provider tests class.
24
 *
25
 * @package    core_editor
26
 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1441 ariadna 28
 * @covers \core_editor\privacy\provider
1 efrain 29
 */
1441 ariadna 30
final class provider_test extends \core_privacy\tests\provider_testcase {
1 efrain 31
    /**
32
     * When no preference exists, there should be no export.
33
     */
11 efrain 34
    public function test_no_preference(): void {
1 efrain 35
        global $USER;
36
        $this->resetAfterTest();
37
        $this->setAdminUser();
38
 
39
        provider::export_user_preferences($USER->id);
40
        /** @var \core_privacy\tests\request\content_writer $writer */
41
        $writer = writer::with_context(\context_system::instance());
42
        $this->assertFalse($writer->has_any_data());
43
    }
44
 
45
    /**
46
     * When preference exists but is empty, there should be no export.
47
     */
11 efrain 48
    public function test_empty_preference(): void {
1 efrain 49
        $this->resetAfterTest();
50
 
51
        // Create test user, add some preferences.
52
        $user = $this->getDataGenerator()->create_user();
53
        $this->setUser($user);
54
 
55
        set_user_preference('htmleditor', '', $user);
56
 
57
        // Switch to admin user (so we can validate preferences of the correct user are being exported).
58
        $this->setAdminUser();
59
 
60
        // Export test users preferences.
61
        provider::export_user_preferences($user->id);
62
        /** @var \core_privacy\tests\request\content_writer $writer */
63
        $writer = writer::with_context(\context_system::instance());
64
        $this->assertFalse($writer->has_any_data());
65
    }
66
 
67
    /**
68
     * When an editor is set, the name of that editor will be reported.
69
     */
1441 ariadna 70
    public function test_editor_tiny(): void {
1 efrain 71
        $this->resetAfterTest();
72
 
73
        // Create test user, add some preferences.
74
        $user = $this->getDataGenerator()->create_user();
75
        $this->setUser($user);
76
 
1441 ariadna 77
        set_user_preference('htmleditor', 'tiny');
1 efrain 78
 
79
        // Switch to admin user (so we can validate preferences of the correct user are being exported).
80
        $this->setAdminUser();
81
 
82
        // Export test users preferences.
83
        provider::export_user_preferences($user->id);
84
        /** @var \core_privacy\tests\request\content_writer $writer */
85
        $writer = writer::with_context(\context_system::instance());
86
        $this->assertTrue($writer->has_any_data());
87
 
88
        $prefs = $writer->get_user_preferences('core_editor');
89
        $this->assertNotEmpty($prefs->htmleditor);
90
        $this->assertNotEmpty($prefs->htmleditor->value);
91
        $this->assertNotEmpty($prefs->htmleditor->description);
1441 ariadna 92
        $this->assertEquals('tiny', $prefs->htmleditor->value);
1 efrain 93
 
94
        $this->assertEquals(
95
            get_string(
96
                'privacy:preference:htmleditor',
97
                'core_editor',
1441 ariadna 98
                get_string('pluginname', "editor_tiny")
1 efrain 99
            ),
100
            $prefs->htmleditor->description
101
        );
102
    }
103
}