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