示例#1
0
 /**
  * Test that paged results are what we expect.
  *
  * @dataProvider file_indexing_provider
  */
 public function test_manager_paged_search($fileindexing)
 {
     $this->engine->test_set_config('fileindexing', $fileindexing);
     $user = self::getDataGenerator()->create_user();
     $this->setup_user_hidden_docs($user);
     $this->search->index();
     // Check that user 1 sees all their results.
     $this->setUser($user);
     $querydata = new stdClass();
     $querydata->q = 'Something1 Something2 Something3 Something4';
     // On this first page, it should have determined the first 10 of 40 are bad, so there could be up to 30 left.
     $results = $this->search->paged_search($querydata, 0);
     $this->assertEquals(30, $results->totalcount);
     $this->assertCount(10, $results->results);
     $this->assertEquals(0, $results->actualpage);
     // On the second page, it should have found the next 10 bad ones, so we no know there are only 20 total.
     $results = $this->search->paged_search($querydata, 1);
     $this->assertEquals(20, $results->totalcount);
     $this->assertCount(10, $results->results);
     $this->assertEquals(1, $results->actualpage);
     // Try to get an additional page - we should get back page 1 results, since that is the last page with valid results.
     $results = $this->search->paged_search($querydata, 2);
     $this->assertEquals(20, $results->totalcount);
     $this->assertCount(10, $results->results);
     $this->assertEquals(1, $results->actualpage);
 }
示例#2
0
 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'));
 }