mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 03:16:42 +02:00
Merge branch 'MDL-60880-master' of https://github.com/sammarshallou/moodle
This commit is contained in:
commit
97812f14c1
14 changed files with 330 additions and 32 deletions
|
@ -106,6 +106,7 @@ class search_base_testcase extends advanced_testcase {
|
|||
|
||||
// Construct the search document.
|
||||
$rec = new \stdClass();
|
||||
$rec->contextid = 1;
|
||||
$area = new core_mocksearch\search\mock_search_area();
|
||||
$record = $this->generator->create_record($rec);
|
||||
$document = $area->get_document($record);
|
||||
|
|
|
@ -7,10 +7,13 @@ Feature: Use global search interface
|
|||
Background:
|
||||
Given the following config values are set as admin:
|
||||
| enableglobalsearch | 1 |
|
||||
And the following "courses" exist:
|
||||
| shortname | fullname |
|
||||
| F1 | Amphibians |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| page | PageName1 | PageDesc1 | Acceptance test site | PAGE1 |
|
||||
| forum | ForumName1 | ForumDesc1 | Acceptance test site | FORUM1 |
|
||||
| activity | name | intro | course | idnumber |
|
||||
| page | PageName1 | PageDesc1 | F1 | PAGE1 |
|
||||
| forum | ForumName1 | ForumDesc1 | F1 | FORUM1 |
|
||||
And I log in as "admin"
|
||||
|
||||
@javascript
|
||||
|
@ -47,3 +50,44 @@ Feature: Use global search interface
|
|||
# Check the link works.
|
||||
And I follow "ForumName1"
|
||||
And I should see "ForumName1" in the ".breadcrumb" "css_element"
|
||||
|
||||
@javascript
|
||||
Scenario: Search starting from site context (no within option)
|
||||
Given global search expects the query "frogs" and will return:
|
||||
| type | idnumber |
|
||||
| activity | PAGE1 |
|
||||
When I search for "frogs" using the header global search box
|
||||
And I expand all fieldsets
|
||||
Then I should not see "Search within"
|
||||
And I should see "Courses"
|
||||
|
||||
@javascript
|
||||
Scenario: Search starting from course context (within option lists course)
|
||||
Given global search expects the query "frogs" and will return:
|
||||
| type | idnumber |
|
||||
| activity | PAGE1 |
|
||||
When I am on "Amphibians" course homepage
|
||||
And I search for "frogs" using the header global search box
|
||||
And I expand all fieldsets
|
||||
Then I should see "Search within"
|
||||
And I select "Everywhere you can access" from the "Search within" singleselect
|
||||
And I should see "Courses"
|
||||
And I select "Course: Amphibians" from the "Search within" singleselect
|
||||
And I should not see "Courses"
|
||||
|
||||
@javascript
|
||||
Scenario: Search starting from forum context (within option lists course and forum)
|
||||
Given global search expects the query "frogs" and will return:
|
||||
| type | idnumber |
|
||||
| activity | PAGE1 |
|
||||
When I am on "Amphibians" course homepage
|
||||
And I follow "ForumName1"
|
||||
And I search for "frogs" using the header global search box
|
||||
And I expand all fieldsets
|
||||
And I should see "Search within"
|
||||
And I select "Everywhere you can access" from the "Search within" singleselect
|
||||
And I should see "Courses"
|
||||
And I select "Course: Amphibians" from the "Search within" singleselect
|
||||
And I should not see "Courses"
|
||||
And I select "Forum: ForumName1" from the "Search within" singleselect
|
||||
And I should not see "Courses"
|
||||
|
|
2
search/tests/fixtures/mock_search_area.php
vendored
2
search/tests/fixtures/mock_search_area.php
vendored
|
@ -36,7 +36,7 @@ class mock_search_area extends \core_search\base {
|
|||
* Multiple context level so we can test get_areas_user_accesses.
|
||||
* @var int[]
|
||||
*/
|
||||
protected static $levels = [CONTEXT_SYSTEM, CONTEXT_USER];
|
||||
protected static $levels = [CONTEXT_COURSE, CONTEXT_USER];
|
||||
|
||||
/**
|
||||
* To make things easier, base class required config stuff.
|
||||
|
|
|
@ -72,8 +72,8 @@ class testable_core_search extends \core_search\manager {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_areas_user_accesses($limitcourseids = false) {
|
||||
return parent::get_areas_user_accesses($limitcourseids);
|
||||
public function get_areas_user_accesses($limitcourseids = false, $limitcontextids = false) {
|
||||
return parent::get_areas_user_accesses($limitcourseids, $limitcontextids);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -118,7 +118,7 @@ class core_search_generator extends component_generator_base {
|
|||
}
|
||||
|
||||
if (!isset($options->contextid)) {
|
||||
$info->contextid = \context_system::instance()->id;
|
||||
$info->contextid = \context_course::instance(SITEID)->id;
|
||||
} else {
|
||||
$info->contextid = $options->contextid;
|
||||
}
|
||||
|
|
|
@ -526,6 +526,7 @@ class search_manager_testcase extends advanced_testcase {
|
|||
$this->resetAfterTest();
|
||||
|
||||
$frontpage = $DB->get_record('course', array('id' => SITEID));
|
||||
$frontpagectx = context_course::instance($frontpage->id);
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$course1ctx = context_course::instance($course1->id);
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
|
@ -557,14 +558,13 @@ class search_manager_testcase extends advanced_testcase {
|
|||
$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);
|
||||
$mockctxs = array($noaccessctx->id => $noaccessctx->id, $frontpagectx->id => $frontpagectx->id);
|
||||
$this->assertEquals($mockctxs, $contexts[$mockareaid]);
|
||||
|
||||
$this->setUser($teacher);
|
||||
|
@ -574,7 +574,8 @@ class search_manager_testcase extends advanced_testcase {
|
|||
$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);
|
||||
$mockctxs = array($teacherctx->id => $teacherctx->id,
|
||||
$frontpagectx->id => $frontpagectx->id, $course1ctx->id => $course1ctx->id);
|
||||
$this->assertEquals($mockctxs, $contexts[$mockareaid]);
|
||||
|
||||
$this->setUser($student);
|
||||
|
@ -582,7 +583,8 @@ class search_manager_testcase extends advanced_testcase {
|
|||
$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);
|
||||
$mockctxs = array($studentctx->id => $studentctx->id,
|
||||
$frontpagectx->id => $frontpagectx->id, $course1ctx->id => $course1ctx->id);
|
||||
$this->assertEquals($mockctxs, $contexts[$mockareaid]);
|
||||
|
||||
// Hide the activity.
|
||||
|
@ -616,6 +618,32 @@ class search_manager_testcase extends advanced_testcase {
|
|||
$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]);
|
||||
|
||||
// Test context limited search with no course limit.
|
||||
$contexts = $search->get_areas_user_accesses(false,
|
||||
[$frontpageforumcontext->id, $course2ctx->id]);
|
||||
$this->assertEquals([$frontpageforumcontext->id => $frontpageforumcontext->id],
|
||||
$contexts[$this->forumpostareaid]);
|
||||
$this->assertEquals([$course2ctx->id => $course2ctx->id],
|
||||
$contexts[$this->mycoursesareaid]);
|
||||
|
||||
// Test context limited search with course limit.
|
||||
$contexts = $search->get_areas_user_accesses([$course1->id, $course2->id],
|
||||
[$frontpageforumcontext->id, $course2ctx->id]);
|
||||
$this->assertArrayNotHasKey($this->forumpostareaid, $contexts);
|
||||
$this->assertEquals([$course2ctx->id => $course2ctx->id],
|
||||
$contexts[$this->mycoursesareaid]);
|
||||
|
||||
// Single context and course.
|
||||
$contexts = $search->get_areas_user_accesses([$course1->id], [$context1->id]);
|
||||
$this->assertEquals([$context1->id => $context1->id], $contexts[$this->forumpostareaid]);
|
||||
$this->assertArrayNotHasKey($this->mycoursesareaid, $contexts);
|
||||
|
||||
// For admins, this is still limited only if we specify the things, so it should be same.
|
||||
$this->setAdminUser();
|
||||
$contexts = $search->get_areas_user_accesses([$course1->id], [$context1->id]);
|
||||
$this->assertEquals([$context1->id => $context1->id], $contexts[$this->forumpostareaid]);
|
||||
$this->assertArrayNotHasKey($this->mycoursesareaid, $contexts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -624,6 +652,8 @@ class search_manager_testcase extends advanced_testcase {
|
|||
* @return void
|
||||
*/
|
||||
public function test_search_user_accesses_blocks() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
|
@ -715,6 +745,26 @@ class search_manager_testcase extends advanced_testcase {
|
|||
$this->setUser($student1);
|
||||
$limitedcontexts = $search->get_areas_user_accesses([$course3->id]);
|
||||
$this->assertEquals($contexts['block_html-content'], $limitedcontexts['block_html-content']);
|
||||
|
||||
// Get block context ids for the blocks that appear.
|
||||
global $DB;
|
||||
$blockcontextids = $DB->get_fieldset_sql('
|
||||
SELECT x.id
|
||||
FROM {block_instances} bi
|
||||
JOIN {context} x ON x.instanceid = bi.id AND x.contextlevel = ?
|
||||
WHERE (parentcontextid = ? OR parentcontextid = ?)
|
||||
AND blockname = ?
|
||||
ORDER BY bi.id', [CONTEXT_BLOCK, $context1->id, $context3->id, 'html']);
|
||||
|
||||
// Context limited search (no course).
|
||||
$contexts = $search->get_areas_user_accesses(false,
|
||||
[$blockcontextids[0], $blockcontextids[2]]);
|
||||
$this->assertCount(2, $contexts['block_html-content']);
|
||||
|
||||
// Context limited search (with course 3).
|
||||
$contexts = $search->get_areas_user_accesses([$course2->id, $course3->id],
|
||||
[$blockcontextids[0], $blockcontextids[2]]);
|
||||
$this->assertCount(1, $contexts['block_html-content']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue