[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Core search class adapted to unit test. 19 * 20 * @package core_search 21 * @copyright 2015 David Monllao {@link http://www.davidmonllao.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once (__DIR__ . '/mock_search_engine.php'); 28 29 /** 30 * Core search class adapted to unit test. 31 * 32 * Note that by default all core search areas are returned when calling get_search_areas_list, 33 * if you want to use the mock search area you can use testable_core_search::add_search_area 34 * although if you want to add mock search areas on top of the core ones you should call 35 * testable_core_search::add_core_search_areas before calling testable_core_search::add_search_area. 36 * 37 * @package core_search 38 * @copyright 2015 David Monllao {@link http://www.davidmonllao.com} 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class testable_core_search extends \core_search\manager { 42 43 /** 44 * Attaches the mock engine to search. 45 * 46 * Auto enables global search. 47 * 48 * @param \core_search\engine|bool $searchengine 49 * @return testable_core_search 50 */ 51 public static function instance($searchengine = false) { 52 53 // One per request, this should be purged during testing. 54 if (self::$instance !== null) { 55 return self::$instance; 56 } 57 58 set_config('enableglobalsearch', true); 59 60 // Default to the mock one. 61 if ($searchengine === false) { 62 $searchengine = new \mock_search\engine(); 63 } 64 65 self::$instance = new testable_core_search($searchengine); 66 67 return self::$instance; 68 } 69 70 /** 71 * Changes visibility. 72 * 73 * @return array 74 */ 75 public function get_areas_user_accesses($limitcourseids = false) { 76 return parent::get_areas_user_accesses($limitcourseids); 77 } 78 79 /** 80 * Adds an enabled search component to the search areas list. 81 * 82 * @param string $areaid 83 * @param \core_search\base $searcharea 84 * @return void 85 */ 86 public function add_search_area($areaid, \core_search\base $searcharea) { 87 self::$enabledsearchareas[$areaid] = $searcharea; 88 self::$allsearchareas[$areaid] = $searcharea; 89 } 90 91 /** 92 * Loads all core search areas. 93 * 94 * @return void 95 */ 96 public function add_core_search_areas() { 97 self::get_search_areas_list(false); 98 self::get_search_areas_list(true); 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |