Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 148... Línea 148...
148
            'file-indexing-on' => array(1),
148
            'file-indexing-on' => array(1),
149
            'file-indexing-off' => array(0)
149
            'file-indexing-off' => array(0)
150
        );
150
        );
151
    }
151
    }
Línea 152... Línea 152...
152
 
152
 
153
    public function test_connection() {
153
    public function test_connection(): void {
154
        $this->assertTrue($this->engine->is_server_ready());
154
        $this->assertTrue($this->engine->is_server_ready());
Línea 155... Línea 155...
155
    }
155
    }
156
 
156
 
157
    /**
157
    /**
158
     * Tests that the alternate settings are used when configured.
158
     * Tests that the alternate settings are used when configured.
159
     */
159
     */
160
    public function test_alternate_settings() {
160
    public function test_alternate_settings(): void {
161
        // Index a couple of things.
161
        // Index a couple of things.
162
        $this->generator->create_record();
162
        $this->generator->create_record();
Línea 194... Línea 194...
194
    }
194
    }
Línea 195... Línea 195...
195
 
195
 
196
    /**
196
    /**
197
     * @dataProvider file_indexing_provider
197
     * @dataProvider file_indexing_provider
198
     */
198
     */
199
    public function test_index($fileindexing) {
199
    public function test_index($fileindexing): void {
Línea 200... Línea 200...
200
        global $DB;
200
        global $DB;
Línea 201... Línea 201...
201
 
201
 
Línea 223... Línea 223...
223
     *
223
     *
224
     * @dataProvider file_indexing_provider
224
     * @dataProvider file_indexing_provider
225
     *
225
     *
226
     * @return void
226
     * @return void
227
     */
227
     */
228
    public function test_search($fileindexing) {
228
    public function test_search($fileindexing): void {
229
        global $USER, $DB;
229
        global $USER, $DB;
Línea 230... Línea 230...
230
 
230
 
Línea 231... Línea 231...
231
        $this->engine->test_set_config('fileindexing', $fileindexing);
231
        $this->engine->test_set_config('fileindexing', $fileindexing);
Línea 305... Línea 305...
305
    }
305
    }
Línea 306... Línea 306...
306
 
306
 
307
    /**
307
    /**
308
     * @dataProvider file_indexing_provider
308
     * @dataProvider file_indexing_provider
309
     */
309
     */
310
    public function test_delete($fileindexing) {
310
    public function test_delete($fileindexing): void {
Línea 311... Línea 311...
311
        $this->engine->test_set_config('fileindexing', $fileindexing);
311
        $this->engine->test_set_config('fileindexing', $fileindexing);
312
 
312
 
313
        $this->generator->create_record();
313
        $this->generator->create_record();
Línea 325... Línea 325...
325
    }
325
    }
Línea 326... Línea 326...
326
 
326
 
327
    /**
327
    /**
328
     * @dataProvider file_indexing_provider
328
     * @dataProvider file_indexing_provider
329
     */
329
     */
330
    public function test_alloweduserid($fileindexing) {
330
    public function test_alloweduserid($fileindexing): void {
Línea 331... Línea 331...
331
        $this->engine->test_set_config('fileindexing', $fileindexing);
331
        $this->engine->test_set_config('fileindexing', $fileindexing);
Línea 332... Línea 332...
332
 
332
 
Línea 400... Línea 400...
400
    }
400
    }
Línea 401... Línea 401...
401
 
401
 
402
    /**
402
    /**
403
     * @dataProvider file_indexing_provider
403
     * @dataProvider file_indexing_provider
404
     */
404
     */
405
    public function test_highlight($fileindexing) {
405
    public function test_highlight($fileindexing): void {
Línea 406... Línea 406...
406
        global $PAGE;
406
        global $PAGE;
Línea 407... Línea 407...
407
 
407
 
Línea 426... Línea 426...
426
 
426
 
427
        $regex = '|<span class="highlight">message</span>|';
427
        $regex = '|<span class="highlight">message</span>|';
428
        $this->assertMatchesRegularExpression($regex, $exported['content']);
428
        $this->assertMatchesRegularExpression($regex, $exported['content']);
Línea 429... Línea 429...
429
    }
429
    }
430
 
430
 
431
    public function test_export_file_for_engine() {
431
    public function test_export_file_for_engine(): void {
432
        // Get area to work with.
432
        // Get area to work with.
Línea 433... Línea 433...
433
        $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
433
        $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
Línea 449... Línea 449...
449
        $this->assertEquals(\search_solr\document::INDEXED_FILE_TRUE, $filearray['solr_fileindexstatus']);
449
        $this->assertEquals(\search_solr\document::INDEXED_FILE_TRUE, $filearray['solr_fileindexstatus']);
450
        $this->assertEquals($file->get_filename(), $filearray['title']);
450
        $this->assertEquals($file->get_filename(), $filearray['title']);
451
        $this->assertEquals(978310800, \search_solr\document::import_time_from_engine($filearray['modified']));
451
        $this->assertEquals(978310800, \search_solr\document::import_time_from_engine($filearray['modified']));
452
    }
452
    }
Línea 453... Línea 453...
453
 
453
 
454
    public function test_index_file() {
454
    public function test_index_file(): void {
455
        // Very simple test.
455
        // Very simple test.
Línea 456... Línea 456...
456
        $file = $this->generator->create_file();
456
        $file = $this->generator->create_file();
457
 
457
 
Línea 464... Línea 464...
464
        $querydata->q = '"File contents"';
464
        $querydata->q = '"File contents"';
Línea 465... Línea 465...
465
 
465
 
466
        $this->assertCount(1, $this->search->search($querydata));
466
        $this->assertCount(1, $this->search->search($querydata));
Línea 467... Línea 467...
467
    }
467
    }
468
 
468
 
469
    public function test_reindexing_files() {
469
    public function test_reindexing_files(): void {
470
        // Get area to work with.
470
        // Get area to work with.
Línea 471... Línea 471...
471
        $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
471
        $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
Línea 559... Línea 559...
559
    }
559
    }
Línea 560... Línea 560...
560
 
560
 
561
    /**
561
    /**
562
     * Test indexing a file we don't consider indexable.
562
     * Test indexing a file we don't consider indexable.
563
     */
563
     */
564
    public function test_index_filtered_file() {
564
    public function test_index_filtered_file(): void {
565
        // Get area to work with.
565
        // Get area to work with.
566
        $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
566
        $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
Línea 567... Línea 567...
567
        $area = \core_search\manager::get_search_area($areaid);
567
        $area = \core_search\manager::get_search_area($areaid);
Línea 612... Línea 612...
612
        // And we should be able to find the filename.
612
        // And we should be able to find the filename.
613
        $querydata->q = 'smallfile';
613
        $querydata->q = 'smallfile';
614
        $this->assertCount(1, $this->search->search($querydata));
614
        $this->assertCount(1, $this->search->search($querydata));
615
    }
615
    }
Línea 616... Línea 616...
616
 
616
 
617
    public function test_delete_by_id() {
617
    public function test_delete_by_id(): void {
618
        // First get files in the index.
618
        // First get files in the index.
619
        $file = $this->generator->create_file();
619
        $file = $this->generator->create_file();
620
        $record = new \stdClass();
620
        $record = new \stdClass();
621
        $record->attachfileids = array($file->get_id());
621
        $record->attachfileids = array($file->get_id());
Línea 645... Línea 645...
645
    /**
645
    /**
646
     * Test that expected results are returned, even with low check_access success rate.
646
     * Test that expected results are returned, even with low check_access success rate.
647
     *
647
     *
648
     * @dataProvider file_indexing_provider
648
     * @dataProvider file_indexing_provider
649
     */
649
     */
650
    public function test_solr_filling($fileindexing) {
650
    public function test_solr_filling($fileindexing): void {
651
        $this->engine->test_set_config('fileindexing', $fileindexing);
651
        $this->engine->test_set_config('fileindexing', $fileindexing);
Línea 652... Línea 652...
652
 
652
 
653
        $user1 = self::getDataGenerator()->create_user();
653
        $user1 = self::getDataGenerator()->create_user();
Línea 728... Línea 728...
728
    /**
728
    /**
729
     * Test that counts are what we expect.
729
     * Test that counts are what we expect.
730
     *
730
     *
731
     * @dataProvider file_indexing_provider
731
     * @dataProvider file_indexing_provider
732
     */
732
     */
733
    public function test_get_query_total_count($fileindexing) {
733
    public function test_get_query_total_count($fileindexing): void {
734
        $this->engine->test_set_config('fileindexing', $fileindexing);
734
        $this->engine->test_set_config('fileindexing', $fileindexing);
Línea 735... Línea 735...
735
 
735
 
736
        $user = self::getDataGenerator()->create_user();
736
        $user = self::getDataGenerator()->create_user();
737
        $this->setup_user_hidden_docs($user);
737
        $this->setup_user_hidden_docs($user);
Línea 761... Línea 761...
761
    /**
761
    /**
762
     * Test that paged results are what we expect.
762
     * Test that paged results are what we expect.
763
     *
763
     *
764
     * @dataProvider file_indexing_provider
764
     * @dataProvider file_indexing_provider
765
     */
765
     */
766
    public function test_manager_paged_search($fileindexing) {
766
    public function test_manager_paged_search($fileindexing): void {
767
        $this->engine->test_set_config('fileindexing', $fileindexing);
767
        $this->engine->test_set_config('fileindexing', $fileindexing);
Línea 768... Línea 768...
768
 
768
 
769
        $user = self::getDataGenerator()->create_user();
769
        $user = self::getDataGenerator()->create_user();
770
        $this->setup_user_hidden_docs($user);
770
        $this->setup_user_hidden_docs($user);
Línea 795... Línea 795...
795
    }
795
    }
Línea 796... Línea 796...
796
 
796
 
797
    /**
797
    /**
798
     * Tests searching for results restricted to context id.
798
     * Tests searching for results restricted to context id.
799
     */
799
     */
800
    public function test_context_restriction() {
800
    public function test_context_restriction(): void {
801
        // Use real search areas.
801
        // Use real search areas.
802
        $this->search->clear_static();
802
        $this->search->clear_static();
Línea 803... Línea 803...
803
        $this->search->add_core_search_areas();
803
        $this->search->add_core_search_areas();
Línea 867... Línea 867...
867
 
867
 
868
    /**
868
    /**
869
     * Tests searching for results in groups, either by specified group ids or based on user
869
     * Tests searching for results in groups, either by specified group ids or based on user
870
     * access permissions.
870
     * access permissions.
871
     */
871
     */
872
    public function test_groups() {
872
    public function test_groups(): void {
Línea 873... Línea 873...
873
        global $USER;
873
        global $USER;
874
 
874
 
875
        // Use real search areas.
875
        // Use real search areas.
Línea 971... Línea 971...
971
    }
971
    }
Línea 972... Línea 972...
972
 
972
 
973
    /**
973
    /**
974
     * Tests searching for results restricted to specific user id(s).
974
     * Tests searching for results restricted to specific user id(s).
975
     */
975
     */
976
    public function test_user_restriction() {
976
    public function test_user_restriction(): void {
977
        // Use real search areas.
977
        // Use real search areas.
978
        $this->search->clear_static();
978
        $this->search->clear_static();
Línea 979... Línea 979...
979
        $this->search->add_core_search_areas();
979
        $this->search->add_core_search_areas();
Línea 1045... Línea 1045...
1045
    }
1045
    }
Línea 1046... Línea 1046...
1046
 
1046
 
1047
    /**
1047
    /**
1048
     * Tests searching for results containing words in italic text. (This used to fail.)
1048
     * Tests searching for results containing words in italic text. (This used to fail.)
1049
     */
1049
     */
1050
    public function test_italics() {
1050
    public function test_italics(): void {
Línea 1051... Línea 1051...
1051
        global $USER;
1051
        global $USER;
1052
 
1052
 
1053
        // Use real search areas.
1053
        // Use real search areas.
Línea 1124... Línea 1124...
1124
 
1124
 
1125
    /**
1125
    /**
1126
     * Tests the get_supported_orders function for contexts where we can only use relevance
1126
     * Tests the get_supported_orders function for contexts where we can only use relevance
1127
     * (system, category).
1127
     * (system, category).
1128
     */
1128
     */
1129
    public function test_get_supported_orders_relevance_only() {
1129
    public function test_get_supported_orders_relevance_only(): void {
Línea 1130... Línea 1130...
1130
        global $DB;
1130
        global $DB;
1131
 
1131
 
1132
        // System or category context: relevance only.
1132
        // System or category context: relevance only.
Línea 1142... Línea 1142...
1142
 
1142
 
1143
    /**
1143
    /**
1144
     * Tests the get_supported_orders function for contexts where we support location as well
1144
     * Tests the get_supported_orders function for contexts where we support location as well
1145
     * (course, activity, block).
1145
     * (course, activity, block).
1146
     */
1146
     */
1147
    public function test_get_supported_orders_relevance_and_location() {
1147
    public function test_get_supported_orders_relevance_and_location(): void {
Línea 1148... Línea 1148...
1148
        global $DB;
1148
        global $DB;
1149
 
1149
 
1150
        // Test with course context.
1150
        // Test with course context.
Línea 1183... Línea 1183...
1183
    }
1183
    }
Línea 1184... Línea 1184...
1184
 
1184
 
1185
    /**
1185
    /**
1186
     * Tests ordering by relevance vs location.
1186
     * Tests ordering by relevance vs location.
1187
     */
1187
     */
1188
    public function test_ordering() {
1188
    public function test_ordering(): void {
1189
        // Create 2 courses and 2 activities.
1189
        // Create 2 courses and 2 activities.
1190
        $generator = $this->getDataGenerator();
1190
        $generator = $this->getDataGenerator();
1191
        $course1 = $generator->create_course(['fullname' => 'Course 1']);
1191
        $course1 = $generator->create_course(['fullname' => 'Course 1']);
1192
        $course1context = \context_course::instance($course1->id);
1192
        $course1context = \context_course::instance($course1->id);
Línea 1232... Línea 1232...
1232
    }
1232
    }
Línea 1233... Línea 1233...
1233
 
1233
 
1234
    /**
1234
    /**
1235
     * Tests with bogus content (that can be entered into Moodle) to see if it crashes.
1235
     * Tests with bogus content (that can be entered into Moodle) to see if it crashes.
1236
     */
1236
     */
1237
    public function test_bogus_content() {
1237
    public function test_bogus_content(): void {
1238
        $generator = $this->getDataGenerator();
1238
        $generator = $this->getDataGenerator();
1239
        $course1 = $generator->create_course(['fullname' => 'Course 1']);
1239
        $course1 = $generator->create_course(['fullname' => 'Course 1']);
Línea 1240... Línea 1240...
1240
        $course1context = \context_course::instance($course1->id);
1240
        $course1context = \context_course::instance($course1->id);
Línea 1286... Línea 1286...
1286
    }
1286
    }
Línea 1287... Línea 1287...
1287
 
1287
 
1288
    /**
1288
    /**
1289
     * Tries out deleting data for a context or a course.
1289
     * Tries out deleting data for a context or a course.
1290
     */
1290
     */
1291
    public function test_deleted_contexts_and_courses() {
1291
    public function test_deleted_contexts_and_courses(): void {
1292
        // Create some courses and activities.
1292
        // Create some courses and activities.
1293
        $generator = $this->getDataGenerator();
1293
        $generator = $this->getDataGenerator();
1294
        $course1 = $generator->create_course(['fullname' => 'Course 1']);
1294
        $course1 = $generator->create_course(['fullname' => 'Course 1']);
1295
        $course1context = \context_course::instance($course1->id);
1295
        $course1context = \context_course::instance($course1->id);
Línea 1329... Línea 1329...
1329
    }
1329
    }
Línea 1330... Línea 1330...
1330
 
1330
 
1331
    /**
1331
    /**
1332
     * Specific test of the add_document_batch function (also used in many other tests).
1332
     * Specific test of the add_document_batch function (also used in many other tests).
1333
     */
1333
     */
1334
    public function test_add_document_batch() {
1334
    public function test_add_document_batch(): void {
1335
        // Get a default document.
1335
        // Get a default document.
1336
        $area = new \core_mocksearch\search\mock_search_area();
1336
        $area = new \core_mocksearch\search\mock_search_area();
1337
        $record = $this->generator->create_record();
1337
        $record = $this->generator->create_record();
1338
        $doc = $area->get_document($record);
1338
        $doc = $area->get_document($record);
Línea 1372... Línea 1372...
1372
 
1372
 
1373
    /**
1373
    /**
1374
     * Tests the batching logic, specifically the limit to 100 documents per
1374
     * Tests the batching logic, specifically the limit to 100 documents per
1375
     * batch, and not batching very large documents.
1375
     * batch, and not batching very large documents.
1376
     */
1376
     */
1377
    public function test_batching() {
1377
    public function test_batching(): void {
1378
        $area = new \core_mocksearch\search\mock_search_area();
1378
        $area = new \core_mocksearch\search\mock_search_area();
1379
        $record = $this->generator->create_record();
1379
        $record = $this->generator->create_record();
1380
        $doc = $area->get_document($record);
1380
        $doc = $area->get_document($record);
Línea 1429... Línea 1429...
1429
    /**
1429
    /**
1430
     * Tests with large documents. The point of this test is that we stop batching
1430
     * Tests with large documents. The point of this test is that we stop batching
1431
     * documents if they are bigger than 1MB, and the maximum batch count is 100,
1431
     * documents if they are bigger than 1MB, and the maximum batch count is 100,
1432
     * so the maximum size batch will be about 100 1MB documents.
1432
     * so the maximum size batch will be about 100 1MB documents.
1433
     */
1433
     */
1434
    public function test_add_document_batch_large() {
1434
    public function test_add_document_batch_large(): void {
1435
        // This test is a bit slow and not that important to run every time...
1435
        // This test is a bit slow and not that important to run every time...
1436
        if (!PHPUNIT_LONGTEST) {
1436
        if (!PHPUNIT_LONGTEST) {
1437
            $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
1437
            $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
1438
        }
1438
        }