public function setUp() { $this->resetAfterTest(); set_config('enableglobalsearch', true); if (!function_exists('solr_get_version')) { $this->markTestSkipped('Solr extension is not loaded.'); } if (!defined('TEST_SEARCH_SOLR_HOSTNAME') || !defined('TEST_SEARCH_SOLR_INDEXNAME') || !defined('TEST_SEARCH_SOLR_PORT')) { $this->markTestSkipped('Solr extension test server not set.'); } set_config('hostname', TEST_SEARCH_SOLR_HOSTNAME, 'search_solr'); set_config('port', TEST_SEARCH_SOLR_PORT, 'search_solr'); set_config('indexname', TEST_SEARCH_SOLR_INDEXNAME, 'search_solr'); if (defined('TEST_SEARCH_SOLR_USERNAME')) { set_config('server_username', TEST_SEARCH_SOLR_USERNAME); } if (defined('TEST_SEARCH_SOLR_PASSWORD')) { set_config('server_password', TEST_SEARCH_SOLR_PASSWORD); } // Inject search solr engine into the testable core search as we need to add the mock // search component to it. $searchengine = new \search_solr\engine(); $this->search = testable_core_search::instance($searchengine); $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'role_capabilities'); $this->search->add_search_area($areaid, new core_mocksearch\search\role_capabilities()); $this->setAdminUser(); // Cleanup before doing anything on it as the index it is out of this test control. $this->search->delete_index(); // Add moodle fields if they don't exist. $schema = new \search_solr\schema(); $schema->setup(false); }
public function setUp() { $this->resetAfterTest(); set_config('enableglobalsearch', true); // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this. $search = testable_core_search::instance(); }
/** * Setting up the test environment * @return void */ public function setUp() { $this->resetAfterTest(true); set_config('enableglobalsearch', true); $this->messagesentareaid = \core_search\manager::generate_areaid('core_message', 'message_sent'); // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this. $search = testable_core_search::instance(); }
public function setUp() { $this->resetAfterTest(); set_config('enableglobalsearch', true); // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this. $search = testable_core_search::instance(); $this->generator = self::getDataGenerator()->get_plugin_generator('core_search'); $this->generator->setup(); }
public function setUp() { $this->resetAfterTest(true); $this->setAdminUser(); set_config('enableglobalsearch', true); $this->wikicollabpageareaid = \core_search\manager::generate_areaid('mod_wiki', 'collaborative_page'); // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this. $search = testable_core_search::instance(); }
/** * Attaches the mock engine to search. * * Auto enables global search. * * @param \core_search\engine|bool $searchengine * @return testable_core_search */ public static function instance($searchengine = false) { // One per request, this should be purged during testing. if (self::$instance !== null) { return self::$instance; } set_config('enableglobalsearch', true); // Default to the mock one. if ($searchengine === false) { $searchengine = new \mock_search\engine(); } self::$instance = new testable_core_search($searchengine); return self::$instance; }
public function setUp() { $this->resetAfterTest(); set_config('enableglobalsearch', true); if (!function_exists('solr_get_version')) { $this->markTestSkipped('Solr extension is not loaded.'); } if (!defined('TEST_SEARCH_SOLR_HOSTNAME') || !defined('TEST_SEARCH_SOLR_INDEXNAME') || !defined('TEST_SEARCH_SOLR_PORT')) { $this->markTestSkipped('Solr extension test server not set.'); } set_config('server_hostname', TEST_SEARCH_SOLR_HOSTNAME, 'search_solr'); set_config('server_port', TEST_SEARCH_SOLR_PORT, 'search_solr'); set_config('indexname', TEST_SEARCH_SOLR_INDEXNAME, 'search_solr'); if (defined('TEST_SEARCH_SOLR_USERNAME')) { set_config('server_username', TEST_SEARCH_SOLR_USERNAME, 'search_solr'); } if (defined('TEST_SEARCH_SOLR_PASSWORD')) { set_config('server_password', TEST_SEARCH_SOLR_PASSWORD, 'search_solr'); } if (defined('TEST_SEARCH_SOLR_SSLCERT')) { set_config('secure', true, 'search_solr'); set_config('ssl_cert', TEST_SEARCH_SOLR_SSLCERT, 'search_solr'); } if (defined('TEST_SEARCH_SOLR_SSLKEY')) { set_config('ssl_key', TEST_SEARCH_SOLR_SSLKEY, 'search_solr'); } if (defined('TEST_SEARCH_SOLR_KEYPASSWORD')) { set_config('ssl_keypassword', TEST_SEARCH_SOLR_KEYPASSWORD, 'search_solr'); } if (defined('TEST_SEARCH_SOLR_CAINFOCERT')) { set_config('ssl_cainfo', TEST_SEARCH_SOLR_CAINFOCERT, 'search_solr'); } set_config('fileindexing', 1, 'search_solr'); // We are only test indexing small string files, so setting this as low as we can. set_config('maxindexfilekb', 1, 'search_solr'); $this->generator = self::getDataGenerator()->get_plugin_generator('core_search'); $this->generator->setup(); // Inject search solr engine into the testable core search as we need to add the mock // search component to it. $this->engine = new \search_solr\testable_engine(); $this->search = testable_core_search::instance($this->engine); $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area'); $this->search->add_search_area($areaid, new core_mocksearch\search\mock_search_area()); $this->setAdminUser(); // Cleanup before doing anything on it as the index it is out of this test control. $this->search->delete_index(); // Add moodle fields if they don't exist. $schema = new \search_solr\schema(); $schema->setup(false); }
/** * 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')); }
/** * Adding this test here as get_areas_user_accesses process is the same, results just depend on the context level. * * @return void */ public function test_search_user_accesses() { global $DB; $this->resetAfterTest(); $frontpage = $DB->get_record('course', array('id' => SITEID)); $course1 = $this->getDataGenerator()->create_course(); $course2 = $this->getDataGenerator()->create_course(); $teacher = $this->getDataGenerator()->create_user(); $student = $this->getDataGenerator()->create_user(); $noaccess = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($teacher->id, $course1->id, 'teacher'); $this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student'); $frontpageforum = $this->getDataGenerator()->create_module('forum', array('course' => $frontpage->id)); $forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id)); $forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id)); $forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id)); $frontpageforumcontext = context_module::instance($frontpageforum->cmid); $context1 = context_module::instance($forum1->cmid); $context2 = context_module::instance($forum2->cmid); $context3 = context_module::instance($forum3->cmid); $search = testable_core_search::instance(); $this->setAdminUser(); $this->assertTrue($search->get_areas_user_accesses()); // Can access the frontpage ones. $this->setUser($noaccess); $contexts = $search->get_areas_user_accesses(); $this->assertEquals(array($frontpageforumcontext->id => $frontpageforumcontext->id), $contexts[$this->forumpostareaid]); $this->setUser($teacher); $contexts = $search->get_areas_user_accesses(); $frontpageandcourse1 = array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id, $context2->id => $context2->id); $this->assertEquals($frontpageandcourse1, $contexts[$this->forumpostareaid]); $this->setUser($student); $contexts = $search->get_areas_user_accesses(); $this->assertEquals($frontpageandcourse1, $contexts[$this->forumpostareaid]); // Hide the activity. set_coursemodule_visible($forum2->cmid, 0); $contexts = $search->get_areas_user_accesses(); $this->assertEquals(array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id), $contexts[$this->forumpostareaid]); }
/** * Adding this test here as get_areas_user_accesses process is the same, results just depend on the context level. * * @return void */ public function test_search_user_accesses() { global $DB; $this->resetAfterTest(); $frontpage = $DB->get_record('course', array('id' => SITEID)); $course1 = $this->getDataGenerator()->create_course(); $course1ctx = context_course::instance($course1->id); $course2 = $this->getDataGenerator()->create_course(); $course2ctx = context_course::instance($course2->id); $teacher = $this->getDataGenerator()->create_user(); $teacherctx = context_user::instance($teacher->id); $student = $this->getDataGenerator()->create_user(); $studentctx = context_user::instance($student->id); $noaccess = $this->getDataGenerator()->create_user(); $noaccessctx = context_user::instance($noaccess->id); $this->getDataGenerator()->enrol_user($teacher->id, $course1->id, 'teacher'); $this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student'); $frontpageforum = $this->getDataGenerator()->create_module('forum', array('course' => $frontpage->id)); $forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id)); $forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id)); $forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id)); $frontpageforumcontext = context_module::instance($frontpageforum->cmid); $context1 = context_module::instance($forum1->cmid); $context2 = context_module::instance($forum2->cmid); $context3 = context_module::instance($forum3->cmid); $search = testable_core_search::instance(); $mockareaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area'); $search->add_core_search_areas(); $search->add_search_area($mockareaid, new core_mocksearch\search\mock_search_area()); $this->setAdminUser(); $this->assertTrue($search->get_areas_user_accesses()); $sitectx = \context_course::instance(SITEID); $systemctxid = \context_system::instance()->id; // Can access the frontpage ones. $this->setUser($noaccess); $contexts = $search->get_areas_user_accesses(); $this->assertEquals(array($frontpageforumcontext->id => $frontpageforumcontext->id), $contexts[$this->forumpostareaid]); $this->assertEquals(array($sitectx->id => $sitectx->id), $contexts[$this->mycoursesareaid]); $mockctxs = array($noaccessctx->id => $noaccessctx->id, $systemctxid => $systemctxid); $this->assertEquals($mockctxs, $contexts[$mockareaid]); $this->setUser($teacher); $contexts = $search->get_areas_user_accesses(); $frontpageandcourse1 = array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id, $context2->id => $context2->id); $this->assertEquals($frontpageandcourse1, $contexts[$this->forumpostareaid]); $this->assertEquals(array($sitectx->id => $sitectx->id, $course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]); $mockctxs = array($teacherctx->id => $teacherctx->id, $systemctxid => $systemctxid); $this->assertEquals($mockctxs, $contexts[$mockareaid]); $this->setUser($student); $contexts = $search->get_areas_user_accesses(); $this->assertEquals($frontpageandcourse1, $contexts[$this->forumpostareaid]); $this->assertEquals(array($sitectx->id => $sitectx->id, $course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]); $mockctxs = array($studentctx->id => $studentctx->id, $systemctxid => $systemctxid); $this->assertEquals($mockctxs, $contexts[$mockareaid]); // Hide the activity. set_coursemodule_visible($forum2->cmid, 0); $contexts = $search->get_areas_user_accesses(); $this->assertEquals(array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id), $contexts[$this->forumpostareaid]); // Now test course limited searches. set_coursemodule_visible($forum2->cmid, 1); $this->getDataGenerator()->enrol_user($student->id, $course2->id, 'student'); $contexts = $search->get_areas_user_accesses(); $allcontexts = array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id, $context2->id => $context2->id, $context3->id => $context3->id); $this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]); $this->assertEquals(array($sitectx->id => $sitectx->id, $course1ctx->id => $course1ctx->id, $course2ctx->id => $course2ctx->id), $contexts[$this->mycoursesareaid]); $contexts = $search->get_areas_user_accesses(array($course1->id, $course2->id)); $allcontexts = array($context1->id => $context1->id, $context2->id => $context2->id, $context3->id => $context3->id); $this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]); $this->assertEquals(array($course1ctx->id => $course1ctx->id, $course2ctx->id => $course2ctx->id), $contexts[$this->mycoursesareaid]); $contexts = $search->get_areas_user_accesses(array($course2->id)); $allcontexts = array($context3->id => $context3->id); $this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]); $this->assertEquals(array($course2ctx->id => $course2ctx->id), $contexts[$this->mycoursesareaid]); $contexts = $search->get_areas_user_accesses(array($course1->id)); $allcontexts = array($context1->id => $context1->id, $context2->id => $context2->id); $this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]); $this->assertEquals(array($course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]); }
/** * Set up function. In this instance we are setting up database * records to be used in the unit tests. */ protected function setUp() { global $DB, $CFG; parent::setUp(); $this->resetAfterTest(true); set_config('enableglobalsearch', true); $this->databaseentryareaid = \core_search\manager::generate_areaid('mod_data', 'entry'); // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this. $search = testable_core_search::instance(); }