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 core_reportbuilder\local\report\filter; 23 24 /** 25 * Unit tests for course selector filter 26 * 27 * @package core_reportbuilder 28 * @covers \core_reportbuilder\local\filters\base 29 * @covers \core_reportbuilder\local\filters\course_selector 30 * @copyright 2021 David Matamoros <davidmc@moodle.com> 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class course_selector_test extends advanced_testcase { 34 35 /** 36 * Test getting filter SQL 37 */ 38 public function test_get_sql_filter(): void { 39 global $DB; 40 41 $this->resetAfterTest(); 42 43 $course1 = $this->getDataGenerator()->create_course([ 44 'fullname' => "Time travel", 45 ]); 46 47 $course2 = $this->getDataGenerator()->create_course([ 48 'fullname' => "Quantum computing", 49 ]); 50 51 $course3 = $this->getDataGenerator()->create_course([ 52 'fullname' => "Space travel", 53 ]); 54 55 $filter = new filter( 56 course_selector::class, 57 'test', 58 new \lang_string('course'), 59 'testentity', 60 'id' 61 ); 62 63 // Create instance of our filter, passing given courses ids. 64 [$select, $params] = text::create($filter)->get_sql_filter([ 65 $filter->get_unique_identifier() . '_values' => [$course1->id, $course3->id], 66 ]); 67 $fullnames = $DB->get_fieldset_select('course', 'fullname', $select, $params); 68 $this->assertEqualsCanonicalizing(['Time travel', 'Space travel'], $fullnames); 69 70 // Test without passing any course id. 71 [$select, $params] = text::create($filter)->get_sql_filter([ 72 $filter->get_unique_identifier() . '_values' => [], 73 ]); 74 $fullnames = $DB->get_fieldset_select('course', 'fullname', $select, $params); 75 $this->assertEqualsCanonicalizing(['Time travel', 'Quantum computing', 'Space travel', 'PHPUnit test site'], $fullnames); 76 } 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body