Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @copyright  2018 Sara Arjona <sara@moodle.com>
22
 * @copyright  2018 Sara Arjona <sara@moodle.com>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
24
 */
25
namespace tool_policy\privacy;
25
namespace tool_policy\privacy;
Línea 26... Línea -...
26
 
-
 
27
use core_privacy\local\metadata\collection;
-
 
28
use tool_policy\privacy\provider;
-
 
29
use tool_policy\api;
-
 
30
use tool_policy\policy_version;
26
 
31
use core_privacy\local\request\approved_contextlist;
27
use core_privacy\local\request\approved_contextlist;
32
use core_privacy\local\request\writer;
-
 
-
 
28
use core_privacy\local\request\writer;
-
 
29
use tool_policy\api;
33
 
30
use tool_policy\policy_version;
Línea 34... Línea 31...
34
defined('MOODLE_INTERNAL') || die();
31
use tool_policy\privacy\provider;
35
 
32
 
36
/**
33
/**
37
 * Privacy provider tests class.
34
 * Privacy provider tests class.
38
 *
35
 *
39
 * @copyright  2018 Sara Arjona <sara@moodle.com>
36
 * @copyright  2018 Sara Arjona <sara@moodle.com>
40
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
38
 */
42
class provider_test extends \core_privacy\tests\provider_testcase {
39
final class provider_test extends \core_privacy\tests\provider_testcase {
Línea 43... Línea 40...
43
    /** @var stdClass The user object. */
40
    /** @var stdClass The user object. */
44
    protected $user;
41
    protected $user;
Línea 51... Línea 48...
51
 
48
 
52
    /**
49
    /**
53
     * Setup function. Will create a user.
50
     * Setup function. Will create a user.
54
     */
51
     */
-
 
52
    protected function setUp(): void {
55
    protected function setUp(): void {
53
        parent::setUp();
Línea 56... Línea 54...
56
        $this->resetAfterTest();
54
        $this->resetAfterTest();
57
 
55
 
Línea 73... Línea 71...
73
     */
71
     */
74
    public function test_get_contexts_for_userid(): void {
72
    public function test_get_contexts_for_userid(): void {
75
        global $CFG;
73
        global $CFG;
Línea 76... Línea 74...
76
 
74
 
77
        // When there are no policies or agreements context list is empty.
75
        // When there are no policies or agreements context list is empty.
78
        $contextlist = \tool_policy\privacy\provider::get_contexts_for_userid($this->manager->id);
76
        $contextlist = provider::get_contexts_for_userid($this->manager->id);
79
        $this->assertEmpty($contextlist);
77
        $this->assertEmpty($contextlist);
80
        $contextlist = \tool_policy\privacy\provider::get_contexts_for_userid($this->user->id);
78
        $contextlist = provider::get_contexts_for_userid($this->user->id);
Línea 81... Línea 79...
81
        $this->assertEmpty($contextlist);
79
        $this->assertEmpty($contextlist);
82
 
80
 
83
        // Create a policy.
81
        // Create a policy.
84
        $this->setUser($this->manager);
82
        $this->setUser($this->manager);
85
        $CFG->sitepolicyhandler = 'tool_policy';
83
        $CFG->sitepolicyhandler = 'tool_policy';
Línea 86... Línea 84...
86
        $policy = $this->add_policy();
84
        $policy = $this->add_policy();
87
        api::make_current($policy->get('id'));
85
        api::make_current($policy->get('id'));
88
 
86
 
Línea 89... Línea 87...
89
        // After creating a policy, there should be manager context.
87
        // After creating a policy, there should be manager context.
90
        $contextlist = \tool_policy\privacy\provider::get_contexts_for_userid($this->manager->id);
88
        $contextlist = provider::get_contexts_for_userid($this->manager->id);
91
        $this->assertEquals(1, $contextlist->count());
89
        $this->assertEquals(1, $contextlist->count());
Línea 92... Línea 90...
92
 
90
 
93
        // But when there are no agreements, user context list is empty.
91
        // But when there are no agreements, user context list is empty.
94
        $contextlist = \tool_policy\privacy\provider::get_contexts_for_userid($this->user->id);
92
        $contextlist = provider::get_contexts_for_userid($this->user->id);
Línea 95... Línea 93...
95
        $this->assertEmpty($contextlist);
93
        $this->assertEmpty($contextlist);
96
 
94
 
97
        // Agree to the policy.
95
        // Agree to the policy.
98
        $this->setUser($this->user);
96
        $this->setUser($this->user);
Línea 99... Línea 97...
99
        api::accept_policies([$policy->get('id')]);
97
        api::accept_policies([$policy->get('id')]);
100
 
98
 
Línea 275... Línea 273...
275
        // Request export for the manager.
273
        // Request export for the manager.
276
        $contextlist = provider::get_contexts_for_userid($this->manager->id);
274
        $contextlist = provider::get_contexts_for_userid($this->manager->id);
277
        $this->assertCount(3, $contextlist);
275
        $this->assertCount(3, $contextlist);
278
        $this->assertEqualsCanonicalizing(
276
        $this->assertEqualsCanonicalizing(
279
            [$managercontext->id, $usercontext->id, $systemcontext->id],
277
            [$managercontext->id, $usercontext->id, $systemcontext->id],
280
            $contextlist->get_contextids()
278
            array_values($contextlist->get_contextids()),
281
        );
279
        );
Línea 282... Línea 280...
282
 
280
 
283
        $approvedcontextlist = new approved_contextlist($this->user, 'tool_policy', [$usercontext->id]);
281
        $approvedcontextlist = new approved_contextlist($this->user, 'tool_policy', [$usercontext->id]);