$temp->add(new admin_setting_heading('searchengineheading', new lang_string('searchengine', 'admin'), ''));
$temp->add(new admin_setting_configselect('searchengine',
new lang_string('selectsearchengine', 'admin'), '', 'solr', $engines));
- $temp->add(new admin_setting_heading('searchindexingheading', new lang_string('searchoptions', 'admin'), ''));
+ $temp->add(new admin_setting_heading('searchoptionsheading', new lang_string('searchoptions', 'admin'), ''));
$temp->add(new admin_setting_configcheckbox('searchindexwhendisabled',
new lang_string('searchindexwhendisabled', 'admin'), new lang_string('searchindexwhendisabled_desc', 'admin'),
0));
$temp->add(new admin_setting_configduration('searchindextime',
new lang_string('searchindextime', 'admin'), new lang_string('searchindextime_desc', 'admin'),
600));
+ $options = [
+ 0 => new lang_string('searchallavailablecourses_off', 'admin'),
+ 1 => new lang_string('searchallavailablecourses_on', 'admin')
+ ];
+ $temp->add(new admin_setting_configselect('searchallavailablecourses',
+ new lang_string('searchallavailablecourses', 'admin'),
+ new lang_string('searchallavailablecourses_desc', 'admin'),
+ 0, $options));
$ADMIN->add('searchplugins', $temp);
$ADMIN->add('searchplugins', new admin_externalpage('searchareas', new lang_string('searchareas', 'admin'),
$this->assertEquals($contexts['block_html-content'], $limitedcontexts['block_html-content']);
}
+ /**
+ * Test get_areas_user_accesses with regard to the 'all available courses' config option.
+ *
+ * @return void
+ */
+ public function test_search_user_accesses_allavailable() {
+ global $DB, $CFG;
+
+ $this->resetAfterTest();
+
+ // Front page, including a forum.
+ $frontpage = $DB->get_record('course', array('id' => SITEID));
+ $forumfront = $this->getDataGenerator()->create_module('forum', array('course' => $frontpage->id));
+ $forumfrontctx = context_module::instance($forumfront->cmid);
+
+ // Course 1 does not allow guest access.
+ $course1 = $this->getDataGenerator()->create_course((object)array(
+ 'enrol_guest_status_0' => ENROL_INSTANCE_DISABLED,
+ 'enrol_guest_password_0' => ''));
+ $forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
+ $forum1ctx = context_module::instance($forum1->cmid);
+
+ // Course 2 does not allow guest but is accessible by all users.
+ $course2 = $this->getDataGenerator()->create_course((object)array(
+ 'enrol_guest_status_0' => ENROL_INSTANCE_DISABLED,
+ 'enrol_guest_password_0' => ''));
+ $course2ctx = context_course::instance($course2->id);
+ $forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
+ $forum2ctx = context_module::instance($forum2->cmid);
+ assign_capability('moodle/course:view', CAP_ALLOW, $CFG->defaultuserroleid, $course2ctx->id);
+
+ // Course 3 allows guest access without password.
+ $course3 = $this->getDataGenerator()->create_course((object)array(
+ 'enrol_guest_status_0' => ENROL_INSTANCE_ENABLED,
+ 'enrol_guest_password_0' => ''));
+ $forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
+ $forum3ctx = context_module::instance($forum3->cmid);
+
+ // Student user is enrolled in course 1.
+ $student = $this->getDataGenerator()->create_user();
+ $this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student');
+
+ // No access user is just a user with no permissions.
+ $noaccess = $this->getDataGenerator()->create_user();
+
+ // First test without the all available option.
+ $search = testable_core_search::instance();
+
+ // Admin user can access everything.
+ $this->setAdminUser();
+ $this->assertTrue($search->get_areas_user_accesses());
+
+ // No-access user can access only the front page forum.
+ $this->setUser($noaccess);
+ $contexts = $search->get_areas_user_accesses();
+ $this->assertEquals([$forumfrontctx->id], array_keys($contexts[$this->forumpostareaid]));
+
+ // Student can access the front page forum plus the enrolled one.
+ $this->setUser($student);
+ $contexts = $search->get_areas_user_accesses();
+ $this->assertEquals([$forum1ctx->id, $forumfrontctx->id],
+ array_keys($contexts[$this->forumpostareaid]));
+
+ // Now turn on the all available option.
+ set_config('searchallavailablecourses', 1);
+
+ // Admin user can access everything.
+ $this->setAdminUser();
+ $this->assertTrue($search->get_areas_user_accesses());
+
+ // No-access user can access the front page forum and course 2, 3.
+ $this->setUser($noaccess);
+ $contexts = $search->get_areas_user_accesses();
+ $this->assertEquals([$forum2ctx->id, $forum3ctx->id, $forumfrontctx->id],
+ array_keys($contexts[$this->forumpostareaid]));
+
+ // Student can access the front page forum plus the enrolled one plus courses 2, 3.
+ $this->setUser($student);
+ $contexts = $search->get_areas_user_accesses();
+ $this->assertEquals([$forum1ctx->id, $forum2ctx->id, $forum3ctx->id, $forumfrontctx->id],
+ array_keys($contexts[$this->forumpostareaid]));
+ }
+
/**
* test_is_search_area
*