Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * Unit tests for the filtered_userlist. 19 * 20 * @package tool_dataprivacy 21 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 /** 26 * Unit tests for the filtered_userlist. 27 * 28 * @package tool_dataprivacy 29 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class tool_dataprivacy_filtered_userlist_testcase extends advanced_testcase { 33 /** 34 * Test the apply_expired_contexts_filters function with arange of options. 35 * 36 * @dataProvider apply_expired_contexts_filters_provider 37 * @param array $initial The set of userids in the initial filterlist. 38 * @param array $expired The set of userids considered as expired. 39 * @param array $unexpired The set of userids considered as unexpired. 40 * @param array $expected The expected values. 41 */ 42 public function test_apply_expired_contexts_filters(array $initial, array $expired, array $unexpired, array $expected) { 43 $userlist = $this->getMockBuilder(\tool_dataprivacy\filtered_userlist::class) 44 ->disableOriginalConstructor() 45 ->setMethods(null) 46 ->getMock(); 47 48 $rc = new \ReflectionClass(\tool_dataprivacy\filtered_userlist::class); 49 $rcm = $rc->getMethod('set_userids'); 50 $rcm->setAccessible(true); 51 $rcm->invoke($userlist, $initial); 52 53 54 $userlist->apply_expired_context_filters($expired, $unexpired); 55 $filtered = $userlist->get_userids(); 56 57 sort($expected); 58 sort($filtered); 59 $this->assertEquals($expected, $filtered); 60 } 61 62 /** 63 * Data provider for the apply_expired_contexts_filters function. 64 * 65 * @return array 66 */ 67 public function apply_expired_contexts_filters_provider() : array { 68 return [ 69 // Entire list should be preserved. 70 'No overrides' => [ 71 'users' => [1, 2, 3, 4, 5], 72 'expired' => [], 73 'unexpired' => [], 74 [1, 2, 3, 4, 5], 75 ], 76 // The list should be filtered to only keep the expired users. 77 'Expired only' => [ 78 'users' => [1, 2, 3, 4, 5], 79 'expired' => [2, 3, 4], 80 'unexpired' => [], 81 'expected' => [2, 3, 4], 82 ], 83 // The list should be filtered to remove any unexpired users. 84 'Unexpired only' => [ 85 'users' => [1, 2, 3, 4, 5], 86 'expired' => [], 87 'unexpired' => [1, 5], 88 'expected' => [2, 3, 4], 89 ], 90 // The list should be filtered to only keep expired users who are not on the unexpired list. 91 'Combination of expired and unexpired' => [ 92 'users' => [1, 2, 3, 4, 5], 93 'expired' => [1, 2, 3], 94 'unexpired' => [1, 5], 95 'expected' => [2, 3], 96 ], 97 ]; 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body