See Release Notes
Long Term Support Release
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 declare(strict_types=1); 18 19 namespace core_reportbuilder\local\filters; 20 21 use advanced_testcase; 22 use lang_string; 23 use core_reportbuilder\local\report\filter; 24 25 /** 26 * Unit tests for boolean report filter 27 * 28 * @package core_reportbuilder 29 * @covers \core_reportbuilder\local\filters\base 30 * @covers \core_reportbuilder\local\filters\boolean_select 31 * @copyright 2021 Paul Holden <paulh@moodle.com> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class boolean_select_test extends advanced_testcase { 35 36 /** 37 * Data provider for {@see test_get_sql_filter_simple} 38 * 39 * @return array 40 */ 41 public function get_sql_filter_simple_provider(): array { 42 return [ 43 [boolean_select::ANY_VALUE, true], 44 [boolean_select::CHECKED, true], 45 [boolean_select::NOT_CHECKED, false], 46 ]; 47 } 48 49 /** 50 * Test getting filter SQL 51 * 52 * @param int $operator 53 * @param bool $expectuser 54 * 55 * @dataProvider get_sql_filter_simple_provider 56 */ 57 public function test_get_sql_filter_simple(int $operator, bool $expectuser): void { 58 global $DB; 59 60 $this->resetAfterTest(); 61 62 $user = $this->getDataGenerator()->create_user([ 63 'suspended' => 1, 64 ]); 65 66 $filter = new filter( 67 boolean_select::class, 68 'test', 69 new lang_string('yes'), 70 'testentity', 71 'suspended' 72 ); 73 74 // Create instance of our filter, passing given operator. 75 [$select, $params] = boolean_select::create($filter)->get_sql_filter([ 76 $filter->get_unique_identifier() . '_operator' => $operator, 77 ]); 78 79 $usernames = $DB->get_fieldset_select('user', 'username', $select, $params); 80 if ($expectuser) { 81 $this->assertContains($user->username, $usernames); 82 } else { 83 $this->assertNotContains($user->username, $usernames); 84 } 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body