Skip to content

Commit 67fc491

Browse files
committed
Issue #66: Debug search result
1 parent ccadfac commit 67fc491

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

classes/search/cmsfield.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function get_document($record, $options = []) {
167167
public function check_access($id) {
168168
try {
169169
$data = $this->get_data($id);
170-
$cminfo = $this->get_cm('cms', $data->instanceid, $data->courseid);
170+
$cminfo = $this->get_cm('cms', $data->id, $data->courseid);
171171
$context = \context_module::instance($cminfo->id);
172172
} catch (\dml_missing_record_exception $ex) {
173173
return \core_search\manager::ACCESS_DELETED;
@@ -220,10 +220,9 @@ public function get_context_url(\core_search\document $doc) {
220220
protected function get_data($id) {
221221
global $DB;
222222
if (empty($this->cmsdata[$id])) {
223-
$sql = "SELECT mcd.*, mc.id AS cmsid, mc.course AS courseid
224-
FROM {customfield_data} mcd
225-
JOIN {cms} mc ON mc.id = mcd.instanceid
226-
WHERE mcd.id = :id";
223+
$sql = "SELECT mc.id, mc.course AS courseid
224+
FROM {cms} mc
225+
WHERE mc.id = :id";
227226
$this->cmsdata[$id] = $DB->get_record_sql($sql, ['id' => $id], MUST_EXIST);
228227
}
229228
return $this->cmsdata[$id];

tests/search/search_test.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function setUp(): void {
106106
* Test search enabled.
107107
*
108108
* @return void
109+
* @covers \core_search\manager::get_search_area
109110
*/
110111
public function test_search_enabled(): void {
111112
$searcharea = \core_search\manager::get_search_area($this->cmsareaid);
@@ -125,6 +126,8 @@ public function test_search_enabled(): void {
125126
* Indexing mod cms contents.
126127
*
127128
* @return void
129+
* @covers ::get_document_recordset
130+
* @covers ::get_document
128131
*/
129132
public function test_get_document_recordset(): void {
130133
global $DB;
@@ -210,6 +213,8 @@ public function test_get_document_recordset(): void {
210213
* Test default value from cms content type
211214
*
212215
* @return void
216+
* @covers ::get_document_recordset
217+
* @covers ::get_document
213218
*/
214219
public function test_default_content(): void {
215220
global $DB;
@@ -273,6 +278,7 @@ public function test_default_content(): void {
273278
* Test check_access.
274279
*
275280
* @return void
281+
* @covers ::check_access
276282
*/
277283
public function test_check_access(): void {
278284
global $DB;
@@ -286,25 +292,23 @@ public function test_check_access(): void {
286292

287293
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
288294

289-
// Name for cms is coming from "title_mustache" in cms_type.
290295
$generator = self::getDataGenerator()->get_plugin_generator('mod_cms');
291296
$record = new \stdClass();
292297
$record->course = $course->id;
293298
$record->customfield_overview = 'Test overview text 1';
294299
$record->typeid = $this->cmstype->get('id');
295-
$generator->create_instance_with_data($record);
300+
$cms = $generator->create_instance_with_data($record);
296301

297302
$records = $DB->get_records('customfield_data', ['fieldid' => $this->field->get('id')]);
298303
$this->assertCount(1, $records);
299-
$data = current($records);
300304

301305
$this->setAdminUser();
302-
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($data->id));
306+
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($cms->id));
303307

304308
$this->setUser($user1);
305-
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($data->id));
309+
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($cms->id));
306310

307311
$this->setUser($user2);
308-
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($data->id));
312+
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($cms->id));
309313
}
310314
}

0 commit comments

Comments
 (0)