/** * Test that expected results are returned, even with low check_access success rate. * * @dataProvider file_indexing_provider */ public function test_solr_filling($fileindexing) { $this->engine->test_set_config('fileindexing', $fileindexing); $user1 = self::getDataGenerator()->create_user(); $user2 = self::getDataGenerator()->create_user(); // We are going to create a bunch of records that user 1 can see with 2 keywords. // Then we are going to create a bunch for user 2 with only 1 of the keywords. // If user 2 searches for both keywords, solr will return all of the user 1 results, then the user 2 results. // This is because the user 1 results will match 2 keywords, while the others will match only 1. $record = new \stdClass(); // First create a bunch of records for user 1 to see. $record->denyuserids = array($user2->id); $record->content = 'Something1 Something2'; $maxresults = (int) (\core_search\manager::MAX_RESULTS * 0.75); for ($i = 0; $i < $maxresults; $i++) { $this->generator->create_record($record); } // Then create a bunch of records for user 2 to see. $record->denyuserids = array($user1->id); $record->content = 'Something1'; for ($i = 0; $i < $maxresults; $i++) { $this->generator->create_record($record); } $this->search->index(); // Check that user 1 sees all their results. $this->setUser($user1); $querydata = new stdClass(); $querydata->q = 'Something1 Something2'; $results = $this->search->search($querydata); $this->assertCount($maxresults, $results); // Check that user 2 will see theirs, even though they may be crouded out. $this->setUser($user2); $results = $this->search->search($querydata); $this->assertCount($maxresults, $results); }
public function test_alloweduserid() { $engine = $this->search->get_engine(); $area = new core_mocksearch\search\role_capabilities(); // Get the first record for the recordset. $recordset = $area->get_recordset_by_timestamp(); foreach ($recordset as $r) { $record = $r; break; } $recordset->close(); // Get the doc and insert the default doc. $doc = $area->get_document($record); $engine->add_document($doc->export_for_engine()); $users = array(); $users[] = $this->getDataGenerator()->create_user(); $users[] = $this->getDataGenerator()->create_user(); $users[] = $this->getDataGenerator()->create_user(); // Add a record that only user 100 can see. $originalid = $doc->get('id'); // Now add a custom doc for each user. foreach ($users as $user) { $doc->set('id', $originalid . '-' . $user->id); $doc->set('owneruserid', $user->id); $engine->add_document($doc->export_for_engine()); } $engine->area_index_complete($area->get_area_id()); $querydata = new stdClass(); $querydata->q = 'message'; $querydata->title = $doc->get('title'); // We are going to go through each user and see if they get the original and the owned doc. foreach ($users as $user) { $this->setUser($user); $results = $this->search->search($querydata); $this->assertCount(2, $results); $owned = 0; $notowned = 0; // We don't know what order we will get the results in, so we are doing this. foreach ($results as $result) { $owneruserid = $result->get('owneruserid'); if (empty($owneruserid)) { $notowned++; $this->assertEquals(0, $owneruserid); $this->assertEquals($originalid, $result->get('id')); } else { $owned++; $this->assertEquals($user->id, $owneruserid); $this->assertEquals($originalid . '-' . $user->id, $result->get('id')); } } $this->assertEquals(1, $owned); $this->assertEquals(1, $notowned); } // Now test a user with no owned results. $otheruser = $this->getDataGenerator()->create_user(); $this->setUser($otheruser); $results = $this->search->search($querydata); $this->assertCount(1, $results); $this->assertEquals(0, $results[0]->get('owneruserid')); $this->assertEquals($originalid, $results[0]->get('id')); }