Permalink
Browse files

MDL-55390 search: is_search_area unit tests

Added extra checking for search manager get_search_area.
  • Loading branch information...
dmonllao committed Aug 9, 2016
1 parent 05a9c36 commit f3d38863fe499fdac1bc13707430980611e671d8
Showing with 32 additions and 5 deletions.
  1. +6 −5 search/classes/manager.php
  2. +11 −0 search/tests/fixtures/testable_core_search.php
  3. +15 −0 search/tests/manager_test.php
View
@@ -207,7 +207,8 @@ public static function get_search_area($areaid) {
}
$classname = static::get_area_classname($areaid);
if (class_exists($classname)) {
if (class_exists($classname) && static::is_search_area($classname)) {
return new $classname();
}
@@ -730,12 +731,12 @@ public function get_areas_config($searchareas) {
/**
* Checks whether a classname is of an actual search area.
*
* @param string $searchareaname
* @param string $classname
* @return bool
*/
protected static function is_search_area($searchareaname) {
if (is_subclass_of($searchareaname, 'core_search\base')) {
return (new \ReflectionClass($searchareaname))->isInstantiable();
protected static function is_search_area($classname) {
if (is_subclass_of($classname, 'core_search\base')) {
return (new \ReflectionClass($classname))->isInstantiable();
}
return false;
@@ -97,4 +97,15 @@ public function add_core_search_areas() {
self::get_search_areas_list(false);
self::get_search_areas_list(true);
}
/**
* Changes visibility.
*
* @param string $classname
* @return bool
*/
public static function is_search_area($classname) {
return parent::is_search_area($classname);
}
}
@@ -253,4 +253,19 @@ public function test_search_user_accesses() {
$this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]);
}
/**
* test_is_search_area
*
* @return void
*/
public function test_is_search_area() {
$this->assertFalse(testable_core_search::is_search_area('\asd\asd'));
$this->assertFalse(testable_core_search::is_search_area('\mod_forum\search\posta'));
$this->assertFalse(testable_core_search::is_search_area('\core_search\base_mod'));
$this->assertTrue(testable_core_search::is_search_area('\mod_forum\search\post'));
$this->assertTrue(testable_core_search::is_search_area('\\mod_forum\\search\\post'));
$this->assertTrue(testable_core_search::is_search_area('mod_forum\\search\\post'));
}
}

0 comments on commit f3d3886

Please sign in to comment.