Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 55... Línea 55...
55
        // Stop it from faking time in the search manager (if set by test).
55
        // Stop it from faking time in the search manager (if set by test).
56
        \testable_core_search::fake_current_time();
56
        \testable_core_search::fake_current_time();
57
        parent::tearDown();
57
        parent::tearDown();
58
    }
58
    }
Línea 59... Línea 59...
59
 
59
 
Línea 60... Línea 60...
60
    public function test_search_enabled() {
60
    public function test_search_enabled(): void {
Línea 61... Línea 61...
61
 
61
 
62
        $this->resetAfterTest();
62
        $this->resetAfterTest();
Línea 78... Línea 78...
78
     * @param bool|null $allcourses Enable searching all courses (null to leave as the default).
78
     * @param bool|null $allcourses Enable searching all courses (null to leave as the default).
79
     * @param bool|null $enablearea Enable the course search area (null to leave as the default).
79
     * @param bool|null $enablearea Enable the course search area (null to leave as the default).
80
     * @param string $expected The expected course search url.
80
     * @param string $expected The expected course search url.
81
     * @dataProvider data_course_search_url
81
     * @dataProvider data_course_search_url
82
     */
82
     */
83
    public function test_course_search_url(?bool $gsenabled, ?bool $allcourses, ?bool $enablearea, string $expected) {
83
    public function test_course_search_url(?bool $gsenabled, ?bool $allcourses, ?bool $enablearea, string $expected): void {
84
        $this->resetAfterTest();
84
        $this->resetAfterTest();
Línea 85... Línea 85...
85
 
85
 
86
        if (!is_null($gsenabled)) {
86
        if (!is_null($gsenabled)) {
87
            set_config('enableglobalsearch', $gsenabled);
87
            set_config('enableglobalsearch', $gsenabled);
Línea 127... Línea 127...
127
     * @param bool|null $allcourses Enable searching all courses (null to leave as the default).
127
     * @param bool|null $allcourses Enable searching all courses (null to leave as the default).
128
     * @param bool|null $enablearea Enable the course search area (null to leave as the default).
128
     * @param bool|null $enablearea Enable the course search area (null to leave as the default).
129
     * @param bool $expected The expected result.
129
     * @param bool $expected The expected result.
130
     * @dataProvider data_can_replace_course_search
130
     * @dataProvider data_can_replace_course_search
131
     */
131
     */
132
    public function test_can_replace_course_search(?bool $gsenabled, ?bool $allcourses, ?bool $enablearea, bool $expected) {
132
    public function test_can_replace_course_search(?bool $gsenabled, ?bool $allcourses, ?bool $enablearea, bool $expected): void {
133
        $this->resetAfterTest();
133
        $this->resetAfterTest();
Línea 134... Línea 134...
134
 
134
 
135
        if (!is_null($gsenabled)) {
135
        if (!is_null($gsenabled)) {
136
            set_config('enableglobalsearch', $gsenabled);
136
            set_config('enableglobalsearch', $gsenabled);
Línea 167... Línea 167...
167
            'no global search, no all courses' => [false, false, true, false],
167
            'no global search, no all courses' => [false, false, true, false],
168
            'no global search, no search area' => [false, true, false, false],
168
            'no global search, no search area' => [false, true, false, false],
169
        ];
169
        ];
170
    }
170
    }
Línea 171... Línea 171...
171
 
171
 
172
    public function test_search_areas() {
172
    public function test_search_areas(): void {
Línea 173... Línea 173...
173
        global $CFG;
173
        global $CFG;
Línea 174... Línea 174...
174
 
174
 
Línea 203... Línea 203...
203
        // Now we check the real result.
203
        // Now we check the real result.
204
        \core_search\manager::clear_static();
204
        \core_search\manager::clear_static();
205
        $this->assertArrayHasKey($this->forumpostareaid, \core_search\manager::get_search_areas_list(true));
205
        $this->assertArrayHasKey($this->forumpostareaid, \core_search\manager::get_search_areas_list(true));
206
    }
206
    }
Línea 207... Línea 207...
207
 
207
 
Línea 208... Línea 208...
208
    public function test_search_config() {
208
    public function test_search_config(): void {
Línea 209... Línea 209...
209
 
209
 
Línea 263... Línea 263...
263
    }
263
    }
Línea 264... Línea 264...
264
 
264
 
265
    /**
265
    /**
266
     * Tests the get_last_indexing_duration method in the base area class.
266
     * Tests the get_last_indexing_duration method in the base area class.
267
     */
267
     */
268
    public function test_get_last_indexing_duration() {
268
    public function test_get_last_indexing_duration(): void {
Línea 269... Línea 269...
269
        $this->resetAfterTest();
269
        $this->resetAfterTest();
Línea 270... Línea 270...
270
 
270
 
Línea 287... Línea 287...
287
    }
287
    }
Línea 288... Línea 288...
288
 
288
 
289
    /**
289
    /**
290
     * Tests that partial indexing works correctly.
290
     * Tests that partial indexing works correctly.
291
     */
291
     */
292
    public function test_partial_indexing() {
292
    public function test_partial_indexing(): void {
Línea 293... Línea 293...
293
        global $USER;
293
        global $USER;
294
 
294
 
Línea 387... Línea 387...
387
     * Tests the progress display while indexing.
387
     * Tests the progress display while indexing.
388
     *
388
     *
389
     * This tests the different logic about displaying progress for slow/fast and
389
     * This tests the different logic about displaying progress for slow/fast and
390
     * complete/incomplete processing.
390
     * complete/incomplete processing.
391
     */
391
     */
392
    public function test_index_progress() {
392
    public function test_index_progress(): void {
393
        $this->resetAfterTest();
393
        $this->resetAfterTest();
394
        $generator = $this->getDataGenerator();
394
        $generator = $this->getDataGenerator();
Línea 395... Línea 395...
395
 
395
 
396
        // Set up the fake search area.
396
        // Set up the fake search area.
Línea 470... Línea 470...
470
    /**
470
    /**
471
     * Tests that documents with modified time in the future are NOT indexed (as this would cause
471
     * Tests that documents with modified time in the future are NOT indexed (as this would cause
472
     * a problem by preventing it from indexing other documents modified between now and the future
472
     * a problem by preventing it from indexing other documents modified between now and the future
473
     * date).
473
     * date).
474
     */
474
     */
475
    public function test_future_documents() {
475
    public function test_future_documents(): void {
476
        $this->resetAfterTest();
476
        $this->resetAfterTest();
Línea 477... Línea 477...
477
 
477
 
478
        // Create a course and a forum.
478
        // Create a course and a forum.
479
        $generator = $this->getDataGenerator();
479
        $generator = $this->getDataGenerator();
Línea 520... Línea 520...
520
    }
520
    }
Línea 521... Línea 521...
521
 
521
 
522
    /**
522
    /**
523
     * Tests that indexing a specified context works correctly.
523
     * Tests that indexing a specified context works correctly.
524
     */
524
     */
525
    public function test_context_indexing() {
525
    public function test_context_indexing(): void {
Línea 526... Línea 526...
526
        global $USER;
526
        global $USER;
527
 
527
 
Línea 621... Línea 621...
621
    /**
621
    /**
622
     * Adding this test here as get_areas_user_accesses process is the same, results just depend on the context level.
622
     * Adding this test here as get_areas_user_accesses process is the same, results just depend on the context level.
623
     *
623
     *
624
     * @return void
624
     * @return void
625
     */
625
     */
626
    public function test_search_user_accesses() {
626
    public function test_search_user_accesses(): void {
627
        global $DB;
627
        global $DB;
Línea 628... Línea 628...
628
 
628
 
Línea 629... Línea 629...
629
        $this->resetAfterTest();
629
        $this->resetAfterTest();
Línea 770... Línea 770...
770
    /**
770
    /**
771
     * Tests the block support in get_search_user_accesses.
771
     * Tests the block support in get_search_user_accesses.
772
     *
772
     *
773
     * @return void
773
     * @return void
774
     */
774
     */
775
    public function test_search_user_accesses_blocks() {
775
    public function test_search_user_accesses_blocks(): void {
776
        global $DB;
776
        global $DB;
Línea 777... Línea 777...
777
 
777
 
778
        $this->resetAfterTest();
778
        $this->resetAfterTest();
Línea 888... Línea 888...
888
    }
888
    }
Línea 889... Línea 889...
889
 
889
 
890
    /**
890
    /**
891
     * Tests retrieval of users search areas when limiting to a course the user is not enrolled in
891
     * Tests retrieval of users search areas when limiting to a course the user is not enrolled in
892
     */
892
     */
893
    public function test_search_users_accesses_limit_non_enrolled_course() {
893
    public function test_search_users_accesses_limit_non_enrolled_course(): void {
Línea 894... Línea 894...
894
        global $DB;
894
        global $DB;
Línea 895... Línea 895...
895
 
895
 
Línea 927... Línea 927...
927
    /**
927
    /**
928
     * Test get_areas_user_accesses with regard to the 'all available courses' config option.
928
     * Test get_areas_user_accesses with regard to the 'all available courses' config option.
929
     *
929
     *
930
     * @return void
930
     * @return void
931
     */
931
     */
932
    public function test_search_user_accesses_allavailable() {
932
    public function test_search_user_accesses_allavailable(): void {
933
        global $DB, $CFG;
933
        global $DB, $CFG;
Línea 934... Línea 934...
934
 
934
 
Línea 935... Línea 935...
935
        $this->resetAfterTest();
935
        $this->resetAfterTest();
Línea 1008... Línea 1008...
1008
    }
1008
    }
Línea 1009... Línea 1009...
1009
 
1009
 
1010
    /**
1010
    /**
1011
     * Tests group-related aspects of the get_areas_user_accesses function.
1011
     * Tests group-related aspects of the get_areas_user_accesses function.
1012
     */
1012
     */
1013
    public function test_search_user_accesses_groups() {
1013
    public function test_search_user_accesses_groups(): void {
Línea 1014... Línea 1014...
1014
        global $DB;
1014
        global $DB;
1015
 
1015
 
Línea 1108... Línea 1108...
1108
    /**
1108
    /**
1109
     * test_is_search_area
1109
     * test_is_search_area
1110
     *
1110
     *
1111
     * @return void
1111
     * @return void
1112
     */
1112
     */
1113
    public function test_is_search_area() {
1113
    public function test_is_search_area(): void {
Línea 1114... Línea 1114...
1114
 
1114
 
1115
        $this->assertFalse(\testable_core_search::is_search_area('\asd\asd'));
1115
        $this->assertFalse(\testable_core_search::is_search_area('\asd\asd'));
1116
        $this->assertFalse(\testable_core_search::is_search_area('\mod_forum\search\posta'));
1116
        $this->assertFalse(\testable_core_search::is_search_area('\mod_forum\search\posta'));
1117
        $this->assertFalse(\testable_core_search::is_search_area('\core_search\base_mod'));
1117
        $this->assertFalse(\testable_core_search::is_search_area('\core_search\base_mod'));
Línea 1123... Línea 1123...
1123
    /**
1123
    /**
1124
     * Tests the request_index function used for reindexing certain contexts. This only tests
1124
     * Tests the request_index function used for reindexing certain contexts. This only tests
1125
     * adding things to the request list, it doesn't test that they are actually indexed by the
1125
     * adding things to the request list, it doesn't test that they are actually indexed by the
1126
     * scheduled task.
1126
     * scheduled task.
1127
     */
1127
     */
1128
    public function test_request_index() {
1128
    public function test_request_index(): void {
1129
        global $DB;
1129
        global $DB;
Línea 1130... Línea 1130...
1130
 
1130
 
Línea 1131... Línea 1131...
1131
        $this->resetAfterTest();
1131
        $this->resetAfterTest();
Línea 1232... Línea 1232...
1232
    }
1232
    }
Línea 1233... Línea 1233...
1233
 
1233
 
1234
    /**
1234
    /**
1235
     * Tests the process_index_requests function.
1235
     * Tests the process_index_requests function.
1236
     */
1236
     */
1237
    public function test_process_index_requests() {
1237
    public function test_process_index_requests(): void {
Línea 1238... Línea 1238...
1238
        global $DB;
1238
        global $DB;
Línea 1239... Línea 1239...
1239
 
1239
 
Línea 1369... Línea 1369...
1369
    }
1369
    }
Línea 1370... Línea 1370...
1370
 
1370
 
1371
    /**
1371
    /**
1372
     * Test search area categories.
1372
     * Test search area categories.
1373
     */
1373
     */
1374
    public function test_get_search_area_categories() {
1374
    public function test_get_search_area_categories(): void {
Línea 1375... Línea 1375...
1375
        $categories = \core_search\manager::get_search_area_categories();
1375
        $categories = \core_search\manager::get_search_area_categories();
1376
 
1376
 
1377
        $this->assertTrue(is_array($categories));
1377
        $this->assertTrue(is_array($categories));
Línea 1387... Línea 1387...
1387
    }
1387
    }
Línea 1388... Línea 1388...
1388
 
1388
 
1389
    /**
1389
    /**
1390
     * Test that we can find out if search area categories functionality is enabled.
1390
     * Test that we can find out if search area categories functionality is enabled.
1391
     */
1391
     */
1392
    public function test_is_search_area_categories_enabled() {
1392
    public function test_is_search_area_categories_enabled(): void {
Línea 1393... Línea 1393...
1393
        $this->resetAfterTest();
1393
        $this->resetAfterTest();
1394
 
1394
 
1395
        $this->assertFalse(\core_search\manager::is_search_area_categories_enabled());
1395
        $this->assertFalse(\core_search\manager::is_search_area_categories_enabled());
Línea 1400... Línea 1400...
1400
    }
1400
    }
Línea 1401... Línea 1401...
1401
 
1401
 
1402
    /**
1402
    /**
1403
     * Test that we can find out if hiding all results category is enabled.
1403
     * Test that we can find out if hiding all results category is enabled.
1404
     */
1404
     */
1405
    public function test_should_hide_all_results_category() {
1405
    public function test_should_hide_all_results_category(): void {
Línea 1406... Línea 1406...
1406
        $this->resetAfterTest();
1406
        $this->resetAfterTest();
1407
 
1407
 
1408
        $this->assertEquals(0, \core_search\manager::should_hide_all_results_category());
1408
        $this->assertEquals(0, \core_search\manager::should_hide_all_results_category());
Línea 1413... Línea 1413...
1413
    }
1413
    }
Línea 1414... Línea 1414...
1414
 
1414
 
1415
    /**
1415
    /**
1416
     * Test that we can get default search category name.
1416
     * Test that we can get default search category name.
1417
     */
1417
     */
1418
    public function test_get_default_area_category_name() {
1418
    public function test_get_default_area_category_name(): void {
Línea 1419... Línea 1419...
1419
        $this->resetAfterTest();
1419
        $this->resetAfterTest();
1420
 
1420
 
Línea 1431... Línea 1431...
1431
    }
1431
    }
Línea 1432... Línea 1432...
1432
 
1432
 
1433
    /**
1433
    /**
1434
     * Test that we can get correct search area category by its name.
1434
     * Test that we can get correct search area category by its name.
1435
     */
1435
     */
1436
    public function test_get_search_area_category_by_name() {
1436
    public function test_get_search_area_category_by_name(): void {
Línea 1437... Línea 1437...
1437
        $this->resetAfterTest();
1437
        $this->resetAfterTest();
1438
 
1438
 
Línea 1448... Línea 1448...
1448
    }
1448
    }
Línea 1449... Línea 1449...
1449
 
1449
 
1450
    /**
1450
    /**
1451
     * Test that we can check that "Include all visible courses" feature is enabled.
1451
     * Test that we can check that "Include all visible courses" feature is enabled.
1452
     */
1452
     */
1453
    public function test_include_all_courses_enabled() {
1453
    public function test_include_all_courses_enabled(): void {
1454
        $this->resetAfterTest();
1454
        $this->resetAfterTest();
1455
        $this->assertFalse(\core_search\manager::include_all_courses());
1455
        $this->assertFalse(\core_search\manager::include_all_courses());
1456
        set_config('searchincludeallcourses', 1);
1456
        set_config('searchincludeallcourses', 1);
1457
        $this->assertTrue(\core_search\manager::include_all_courses());
1457
        $this->assertTrue(\core_search\manager::include_all_courses());
Línea 1458... Línea 1458...
1458
    }
1458
    }
1459
 
1459
 
1460
    /**
1460
    /**
1461
     * Test that we can correctly build a list of courses for a course filter for the search results.
1461
     * Test that we can correctly build a list of courses for a course filter for the search results.
1462
     */
1462
     */
Línea 1463... Línea 1463...
1463
    public function test_build_limitcourseids() {
1463
    public function test_build_limitcourseids(): void {
1464
        global $USER;
1464
        global $USER;
Línea 1516... Línea 1516...
1516
     * @dataProvider parse_search_area_id_data_provider
1516
     * @dataProvider parse_search_area_id_data_provider
1517
     *
1517
     *
1518
     * @param string $areaid Area id to parse.
1518
     * @param string $areaid Area id to parse.
1519
     * @param array $expected Expected result of parsing.
1519
     * @param array $expected Expected result of parsing.
1520
     */
1520
     */
1521
    public function test_parse_search_area_id($areaid, $expected) {
1521
    public function test_parse_search_area_id($areaid, $expected): void {
1522
        $this->assertEquals($expected, \core_search\manager::parse_areaid($areaid));
1522
        $this->assertEquals($expected, \core_search\manager::parse_areaid($areaid));
1523
    }
1523
    }
Línea 1524... Línea 1524...
1524
 
1524
 
1525
    /**
1525
    /**
1526
     * Test that manager class will throw an exception when parsing an invalid area id.
1526
     * Test that manager class will throw an exception when parsing an invalid area id.
1527
     */
1527
     */
1528
    public function test_parse_invalid_search_area_id() {
1528
    public function test_parse_invalid_search_area_id(): void {
1529
        $this->expectException('coding_exception');
1529
        $this->expectException('coding_exception');
1530
        $this->expectExceptionMessage('Trying to parse invalid search area id invalid_area');
1530
        $this->expectExceptionMessage('Trying to parse invalid search area id invalid_area');
1531
        \core_search\manager::parse_areaid('invalid_area');
1531
        \core_search\manager::parse_areaid('invalid_area');
Línea 1532... Línea 1532...
1532
    }
1532
    }
1533
 
1533
 
1534
    /**
1534
    /**
1535
     * Test getting a coding exception when trying to lean up existing search area.
1535
     * Test getting a coding exception when trying to lean up existing search area.
1536
     */
1536
     */
Línea 1537... Línea 1537...
1537
    public function test_cleaning_up_existing_search_area() {
1537
    public function test_cleaning_up_existing_search_area(): void {
1538
        $expectedmessage = "Area mod_assign-activity exists. Please use appropriate search area class to manipulate the data.";
1538
        $expectedmessage = "Area mod_assign-activity exists. Please use appropriate search area class to manipulate the data.";
Línea 1544... Línea 1544...
1544
    }
1544
    }
Línea 1545... Línea 1545...
1545
 
1545
 
1546
    /**
1546
    /**
1547
     * Test clean up of non existing search area.
1547
     * Test clean up of non existing search area.
1548
     */
1548
     */
1549
    public function test_clean_up_non_existing_search_area() {
1549
    public function test_clean_up_non_existing_search_area(): void {
Línea 1550... Línea 1550...
1550
        global $DB;
1550
        global $DB;
Línea 1551... Línea 1551...
1551
 
1551
 
Línea 1577... Línea 1577...
1577
    }
1577
    }
Línea 1578... Línea 1578...
1578
 
1578
 
1579
    /**
1579
    /**
1580
     * Tests the context_deleted, course_deleting_start, and course_deleting_finish methods.
1580
     * Tests the context_deleted, course_deleting_start, and course_deleting_finish methods.
1581
     */
1581
     */
1582
    public function test_context_deletion() {
1582
    public function test_context_deletion(): void {
Línea 1583... Línea 1583...
1583
        $this->resetAfterTest();
1583
        $this->resetAfterTest();
1584
 
1584
 
1585
        // Create one course with 4 activities, and another with one.
1585
        // Create one course with 4 activities, and another with one.