Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 119... Línea 119...
119
    }
119
    }
Línea 120... Línea 120...
120
 
120
 
121
    /**
121
    /**
122
     * Tests cache configuration
122
     * Tests cache configuration
123
     */
123
     */
124
    public function test_cache_config() {
124
    public function test_cache_config(): void {
Línea 125... Línea 125...
125
        global $CFG;
125
        global $CFG;
126
 
126
 
127
        if (defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH &&
127
        if (defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH &&
Línea 195... Línea 195...
195
    }
195
    }
Línea 196... Línea 196...
196
 
196
 
197
    /**
197
    /**
198
     * Tests for cache keys that would break on windows.
198
     * Tests for cache keys that would break on windows.
199
     */
199
     */
200
    public function test_windows_nasty_keys() {
200
    public function test_windows_nasty_keys(): void {
201
        $instance = cache_config_testing::instance();
201
        $instance = cache_config_testing::instance();
202
        $instance->phpunit_add_definition('phpunit/windowskeytest', array(
202
        $instance->phpunit_add_definition('phpunit/windowskeytest', array(
203
            'mode' => cache_store::MODE_APPLICATION,
203
            'mode' => cache_store::MODE_APPLICATION,
204
            'component' => 'phpunit',
204
            'component' => 'phpunit',
Línea 214... Línea 214...
214
    /**
214
    /**
215
     * Tests set_identifiers fails post cache creation.
215
     * Tests set_identifiers fails post cache creation.
216
     *
216
     *
217
     * set_identifiers cannot be called after initial cache instantiation, as you need to create a difference cache.
217
     * set_identifiers cannot be called after initial cache instantiation, as you need to create a difference cache.
218
     */
218
     */
219
    public function test_set_identifiers() {
219
    public function test_set_identifiers(): void {
220
        $instance = cache_config_testing::instance();
220
        $instance = cache_config_testing::instance();
221
        $instance->phpunit_add_definition('phpunit/identifier', array(
221
        $instance->phpunit_add_definition('phpunit/identifier', array(
222
            'mode' => cache_store::MODE_APPLICATION,
222
            'mode' => cache_store::MODE_APPLICATION,
223
            'component' => 'phpunit',
223
            'component' => 'phpunit',
224
            'area' => 'identifier',
224
            'area' => 'identifier',
Línea 235... Línea 235...
235
    }
235
    }
Línea 236... Línea 236...
236
 
236
 
237
    /**
237
    /**
238
     * Tests the default application cache
238
     * Tests the default application cache
239
     */
239
     */
240
    public function test_default_application_cache() {
240
    public function test_default_application_cache(): void {
241
        $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'applicationtest');
241
        $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'applicationtest');
242
        $this->assertInstanceOf(cache_application::class, $cache);
242
        $this->assertInstanceOf(cache_application::class, $cache);
Línea 243... Línea 243...
243
        $this->run_on_cache($cache);
243
        $this->run_on_cache($cache);
Línea 256... Línea 256...
256
    }
256
    }
Línea 257... Línea 257...
257
 
257
 
258
    /**
258
    /**
259
     * Tests the default session cache
259
     * Tests the default session cache
260
     */
260
     */
261
    public function test_default_session_cache() {
261
    public function test_default_session_cache(): void {
262
        $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'applicationtest');
262
        $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'applicationtest');
263
        $this->assertInstanceOf(cache_session::class, $cache);
263
        $this->assertInstanceOf(cache_session::class, $cache);
264
        $this->run_on_cache($cache);
264
        $this->run_on_cache($cache);
Línea 265... Línea 265...
265
    }
265
    }
266
 
266
 
267
    /**
267
    /**
268
     * Tests the default request cache
268
     * Tests the default request cache
269
     */
269
     */
270
    public function test_default_request_cache() {
270
    public function test_default_request_cache(): void {
271
        $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'applicationtest');
271
        $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'applicationtest');
272
        $this->assertInstanceOf(cache_request::class, $cache);
272
        $this->assertInstanceOf(cache_request::class, $cache);
Línea 273... Línea 273...
273
        $this->run_on_cache($cache);
273
        $this->run_on_cache($cache);
274
    }
274
    }
275
 
275
 
276
    /**
276
    /**
277
     * Tests using a cache system when there are no stores available (who knows what the admin did to achieve this).
277
     * Tests using a cache system when there are no stores available (who knows what the admin did to achieve this).
278
     */
278
     */
279
    public function test_on_cache_without_store() {
279
    public function test_on_cache_without_store(): void {
280
        $instance = cache_config_testing::instance(true);
280
        $instance = cache_config_testing::instance(true);
281
        $instance->phpunit_add_definition('phpunit/nostoretest1', array(
281
        $instance->phpunit_add_definition('phpunit/nostoretest1', array(
Línea 533... Línea 533...
533
    }
533
    }
Línea 534... Línea 534...
534
 
534
 
535
    /**
535
    /**
536
     * Tests a definition using a data loader
536
     * Tests a definition using a data loader
537
     */
537
     */
538
    public function test_definition_data_loader() {
538
    public function test_definition_data_loader(): void {
539
        $instance = cache_config_testing::instance(true);
539
        $instance = cache_config_testing::instance(true);
540
        $instance->phpunit_add_definition('phpunit/datasourcetest', array(
540
        $instance->phpunit_add_definition('phpunit/datasourcetest', array(
541
            'mode' => cache_store::MODE_APPLICATION,
541
            'mode' => cache_store::MODE_APPLICATION,
542
            'component' => 'phpunit',
542
            'component' => 'phpunit',
Línea 577... Línea 577...
577
     * Tests a definition using a data loader with versioned keys.
577
     * Tests a definition using a data loader with versioned keys.
578
     *
578
     *
579
     * @covers ::get_versioned
579
     * @covers ::get_versioned
580
     * @covers ::set_versioned
580
     * @covers ::set_versioned
581
     */
581
     */
582
    public function test_definition_data_loader_versioned() {
582
    public function test_definition_data_loader_versioned(): void {
583
        // Create two definitions, one using a non-versionable data source and the other using
583
        // Create two definitions, one using a non-versionable data source and the other using
584
        // a versionable one.
584
        // a versionable one.
585
        $instance = cache_config_testing::instance(true);
585
        $instance = cache_config_testing::instance(true);
586
        $instance->phpunit_add_definition('phpunit/datasourcetest1', array(
586
        $instance->phpunit_add_definition('phpunit/datasourcetest1', array(
587
            'mode' => cache_store::MODE_APPLICATION,
587
            'mode' => cache_store::MODE_APPLICATION,
Línea 629... Línea 629...
629
    }
629
    }
Línea 630... Línea 630...
630
 
630
 
631
    /**
631
    /**
632
     * Tests a definition using an overridden loader
632
     * Tests a definition using an overridden loader
633
     */
633
     */
634
    public function test_definition_overridden_loader() {
634
    public function test_definition_overridden_loader(): void {
635
        $instance = cache_config_testing::instance(true);
635
        $instance = cache_config_testing::instance(true);
636
        $instance->phpunit_add_definition('phpunit/overridetest', array(
636
        $instance->phpunit_add_definition('phpunit/overridetest', array(
637
            'mode' => cache_store::MODE_APPLICATION,
637
            'mode' => cache_store::MODE_APPLICATION,
638
            'component' => 'phpunit',
638
            'component' => 'phpunit',
Línea 654... Línea 654...
654
    }
654
    }
Línea 655... Línea 655...
655
 
655
 
656
    /**
656
    /**
657
     * Test the mappingsonly setting.
657
     * Test the mappingsonly setting.
658
     */
658
     */
659
    public function test_definition_mappings_only() {
659
    public function test_definition_mappings_only(): void {
660
        /** @var cache_config_testing $instance */
660
        /** @var cache_config_testing $instance */
661
        $instance = cache_config_testing::instance(true);
661
        $instance = cache_config_testing::instance(true);
662
        $instance->phpunit_add_definition('phpunit/mappingsonly', array(
662
        $instance->phpunit_add_definition('phpunit/mappingsonly', array(
663
            'mode' => cache_store::MODE_APPLICATION,
663
            'mode' => cache_store::MODE_APPLICATION,
Línea 683... Línea 683...
683
    }
683
    }
Línea 684... Línea 684...
684
 
684
 
685
    /**
685
    /**
686
     * Test a very basic definition.
686
     * Test a very basic definition.
687
     */
687
     */
688
    public function test_definition() {
688
    public function test_definition(): void {
689
        $instance = cache_config_testing::instance();
689
        $instance = cache_config_testing::instance();
690
        $instance->phpunit_add_definition('phpunit/test', array(
690
        $instance->phpunit_add_definition('phpunit/test', array(
691
            'mode' => cache_store::MODE_APPLICATION,
691
            'mode' => cache_store::MODE_APPLICATION,
692
            'component' => 'phpunit',
692
            'component' => 'phpunit',
Línea 701... Línea 701...
701
    }
701
    }
Línea 702... Línea 702...
702
 
702
 
703
    /**
703
    /**
704
     * Test a definition using the simple keys.
704
     * Test a definition using the simple keys.
705
     */
705
     */
706
    public function test_definition_simplekeys() {
706
    public function test_definition_simplekeys(): void {
707
        $instance = cache_config_testing::instance();
707
        $instance = cache_config_testing::instance();
708
        $instance->phpunit_add_definition('phpunit/simplekeytest', array(
708
        $instance->phpunit_add_definition('phpunit/simplekeytest', array(
709
            'mode' => cache_store::MODE_APPLICATION,
709
            'mode' => cache_store::MODE_APPLICATION,
710
            'component' => 'phpunit',
710
            'component' => 'phpunit',
Línea 727... Línea 727...
727
    }
727
    }
Línea 728... Línea 728...
728
 
728
 
729
    /**
729
    /**
730
     * Test a negative TTL on an application cache.
730
     * Test a negative TTL on an application cache.
731
     */
731
     */
732
    public function test_application_ttl_negative() {
732
    public function test_application_ttl_negative(): void {
733
        $instance = cache_config_testing::instance(true);
733
        $instance = cache_config_testing::instance(true);
734
        $instance->phpunit_add_definition('phpunit/ttltest', array(
734
        $instance->phpunit_add_definition('phpunit/ttltest', array(
735
            'mode' => cache_store::MODE_APPLICATION,
735
            'mode' => cache_store::MODE_APPLICATION,
736
            'component' => 'phpunit',
736
            'component' => 'phpunit',
Línea 776... Línea 776...
776
    }
776
    }
Línea 777... Línea 777...
777
 
777
 
778
    /**
778
    /**
779
     * Test a positive TTL on an application cache.
779
     * Test a positive TTL on an application cache.
780
     */
780
     */
781
    public function test_application_ttl_positive() {
781
    public function test_application_ttl_positive(): void {
782
        $instance = cache_config_testing::instance(true);
782
        $instance = cache_config_testing::instance(true);
783
        $instance->phpunit_add_definition('phpunit/ttltest', array(
783
        $instance->phpunit_add_definition('phpunit/ttltest', array(
784
            'mode' => cache_store::MODE_APPLICATION,
784
            'mode' => cache_store::MODE_APPLICATION,
785
            'component' => 'phpunit',
785
            'component' => 'phpunit',
Línea 825... Línea 825...
825
    }
825
    }
Línea 826... Línea 826...
826
 
826
 
827
    /**
827
    /**
828
     * Test a negative TTL on an session cache.
828
     * Test a negative TTL on an session cache.
829
     */
829
     */
830
    public function test_session_ttl_positive() {
830
    public function test_session_ttl_positive(): void {
831
        $instance = cache_config_testing::instance(true);
831
        $instance = cache_config_testing::instance(true);
832
        $instance->phpunit_add_definition('phpunit/ttltest', array(
832
        $instance->phpunit_add_definition('phpunit/ttltest', array(
833
            'mode' => cache_store::MODE_SESSION,
833
            'mode' => cache_store::MODE_SESSION,
834
            'component' => 'phpunit',
834
            'component' => 'phpunit',
Línea 874... Línea 874...
874
    }
874
    }
Línea 875... Línea 875...
875
 
875
 
876
    /**
876
    /**
877
     * Tests manual locking operations on an application cache
877
     * Tests manual locking operations on an application cache
878
     */
878
     */
879
    public function test_application_manual_locking() {
879
    public function test_application_manual_locking(): void {
880
        $instance = cache_config_testing::instance();
880
        $instance = cache_config_testing::instance();
881
        $instance->phpunit_add_definition('phpunit/lockingtest', array(
881
        $instance->phpunit_add_definition('phpunit/lockingtest', array(
882
            'mode' => cache_store::MODE_APPLICATION,
882
            'mode' => cache_store::MODE_APPLICATION,
883
            'component' => 'phpunit',
883
            'component' => 'phpunit',
Línea 912... Línea 912...
912
    }
912
    }
Línea 913... Línea 913...
913
 
913
 
914
    /**
914
    /**
915
     * Tests application cache event invalidation
915
     * Tests application cache event invalidation
916
     */
916
     */
917
    public function test_application_event_invalidation() {
917
    public function test_application_event_invalidation(): void {
918
        $instance = cache_config_testing::instance();
918
        $instance = cache_config_testing::instance();
919
        $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array(
919
        $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array(
920
            'mode' => cache_store::MODE_APPLICATION,
920
            'mode' => cache_store::MODE_APPLICATION,
921
            'component' => 'phpunit',
921
            'component' => 'phpunit',
Línea 947... Línea 947...
947
    }
947
    }
Línea 948... Línea 948...
948
 
948
 
949
    /**
949
    /**
950
     * Tests session cache event invalidation
950
     * Tests session cache event invalidation
951
     */
951
     */
952
    public function test_session_event_invalidation() {
952
    public function test_session_event_invalidation(): void {
953
        $instance = cache_config_testing::instance();
953
        $instance = cache_config_testing::instance();
954
        $instance->phpunit_add_definition('phpunit/test_session_event_invalidation', array(
954
        $instance->phpunit_add_definition('phpunit/test_session_event_invalidation', array(
955
            'mode' => cache_store::MODE_SESSION,
955
            'mode' => cache_store::MODE_SESSION,
956
            'component' => 'phpunit',
956
            'component' => 'phpunit',
Línea 983... Línea 983...
983
    }
983
    }
Línea 984... Línea 984...
984
 
984
 
985
    /**
985
    /**
986
     * Tests application cache definition invalidation
986
     * Tests application cache definition invalidation
987
     */
987
     */
988
    public function test_application_definition_invalidation() {
988
    public function test_application_definition_invalidation(): void {
989
        $instance = cache_config_testing::instance();
989
        $instance = cache_config_testing::instance();
990
        $instance->phpunit_add_definition('phpunit/definitioninvalidation', array(
990
        $instance->phpunit_add_definition('phpunit/definitioninvalidation', array(
991
            'mode' => cache_store::MODE_APPLICATION,
991
            'mode' => cache_store::MODE_APPLICATION,
992
            'component' => 'phpunit',
992
            'component' => 'phpunit',
Línea 1019... Línea 1019...
1019
    }
1019
    }
Línea 1020... Línea 1020...
1020
 
1020
 
1021
    /**
1021
    /**
1022
     * Tests session cache definition invalidation
1022
     * Tests session cache definition invalidation
1023
     */
1023
     */
1024
    public function test_session_definition_invalidation() {
1024
    public function test_session_definition_invalidation(): void {
1025
        $instance = cache_config_testing::instance();
1025
        $instance = cache_config_testing::instance();
1026
        $instance->phpunit_add_definition('phpunit/test_session_definition_invalidation', array(
1026
        $instance->phpunit_add_definition('phpunit/test_session_definition_invalidation', array(
1027
            'mode' => cache_store::MODE_SESSION,
1027
            'mode' => cache_store::MODE_SESSION,
1028
            'component' => 'phpunit',
1028
            'component' => 'phpunit',
Línea 1058... Línea 1058...
1058
    }
1058
    }
Línea 1059... Línea 1059...
1059
 
1059
 
1060
    /**
1060
    /**
1061
     * Tests application cache event invalidation over a distributed setup.
1061
     * Tests application cache event invalidation over a distributed setup.
1062
     */
1062
     */
1063
    public function test_distributed_application_event_invalidation() {
1063
    public function test_distributed_application_event_invalidation(): void {
1064
        global $CFG;
1064
        global $CFG;
1065
        // This is going to be an intense wee test.
1065
        // This is going to be an intense wee test.
1066
        // We need to add data the to cache, invalidate it by event, manually force it back without MUC knowing to simulate a
1066
        // We need to add data the to cache, invalidate it by event, manually force it back without MUC knowing to simulate a
1067
        // disconnected/distributed setup (think load balanced server using local cache), instantiate the cache again and finally
1067
        // disconnected/distributed setup (think load balanced server using local cache), instantiate the cache again and finally
Línea 1184... Línea 1184...
1184
    }
1184
    }
Línea 1185... Línea 1185...
1185
 
1185
 
1186
    /**
1186
    /**
1187
     * Tests application cache event purge
1187
     * Tests application cache event purge
1188
     */
1188
     */
1189
    public function test_application_event_purge() {
1189
    public function test_application_event_purge(): void {
1190
        $instance = cache_config_testing::instance();
1190
        $instance = cache_config_testing::instance();
1191
        $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
1191
        $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
1192
            'mode' => cache_store::MODE_APPLICATION,
1192
            'mode' => cache_store::MODE_APPLICATION,
1193
            'component' => 'phpunit',
1193
            'component' => 'phpunit',
Línea 1235... Línea 1235...
1235
    }
1235
    }
Línea 1236... Línea 1236...
1236
 
1236
 
1237
    /**
1237
    /**
1238
     * Tests session cache event purge
1238
     * Tests session cache event purge
1239
     */
1239
     */
1240
    public function test_session_event_purge() {
1240
    public function test_session_event_purge(): void {
1241
        $instance = cache_config_testing::instance();
1241
        $instance = cache_config_testing::instance();
1242
        $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
1242
        $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
1243
            'mode' => cache_store::MODE_SESSION,
1243
            'mode' => cache_store::MODE_SESSION,
1244
            'component' => 'phpunit',
1244
            'component' => 'phpunit',
Línea 1286... Línea 1286...
1286
    }
1286
    }
Línea 1287... Línea 1287...
1287
 
1287
 
1288
    /**
1288
    /**
1289
     * Tests application cache definition purge
1289
     * Tests application cache definition purge
1290
     */
1290
     */
1291
    public function test_application_definition_purge() {
1291
    public function test_application_definition_purge(): void {
1292
        $instance = cache_config_testing::instance();
1292
        $instance = cache_config_testing::instance();
1293
        $instance->phpunit_add_definition('phpunit/definitionpurgetest', array(
1293
        $instance->phpunit_add_definition('phpunit/definitionpurgetest', array(
1294
            'mode' => cache_store::MODE_APPLICATION,
1294
            'mode' => cache_store::MODE_APPLICATION,
1295
            'component' => 'phpunit',
1295
            'component' => 'phpunit',
Línea 1315... Línea 1315...
1315
 
1315
 
1316
    /**
1316
    /**
1317
     * Test the use of an alt path.
1317
     * Test the use of an alt path.
1318
     * If we can generate a config instance we are done :)
1318
     * If we can generate a config instance we are done :)
1319
     */
1319
     */
1320
    public function test_alt_cache_path() {
1320
    public function test_alt_cache_path(): void {
1321
        global $CFG;
1321
        global $CFG;
1322
        if ((defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) || !empty($CFG->altcacheconfigpath)) {
1322
        if ((defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) || !empty($CFG->altcacheconfigpath)) {
1323
            $this->markTestSkipped('Skipped testing alt cache path as it is already being used.');
1323
            $this->markTestSkipped('Skipped testing alt cache path as it is already being used.');
1324
        }
1324
        }
Línea 1329... Línea 1329...
1329
    }
1329
    }
Línea 1330... Línea 1330...
1330
 
1330
 
1331
    /**
1331
    /**
1332
     * Test disabling the cache stores.
1332
     * Test disabling the cache stores.
1333
     */
1333
     */
1334
    public function test_disable_stores() {
1334
    public function test_disable_stores(): void {
1335
        $instance = cache_config_testing::instance();
1335
        $instance = cache_config_testing::instance();
1336
        $instance->phpunit_add_definition('phpunit/disabletest1', array(
1336
        $instance->phpunit_add_definition('phpunit/disabletest1', array(
1337
            'mode' => cache_store::MODE_APPLICATION,
1337
            'mode' => cache_store::MODE_APPLICATION,
1338
            'component' => 'phpunit',
1338
            'component' => 'phpunit',
Línea 1393... Línea 1393...
1393
    }
1393
    }
Línea 1394... Línea 1394...
1394
 
1394
 
1395
    /**
1395
    /**
1396
     * Test disabling the cache.
1396
     * Test disabling the cache.
1397
     */
1397
     */
1398
    public function test_disable() {
1398
    public function test_disable(): void {
Línea 1399... Línea 1399...
1399
        global $CFG;
1399
        global $CFG;
1400
 
1400
 
1401
        if ((defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) || !empty($CFG->altcacheconfigpath)) {
1401
        if ((defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) || !empty($CFG->altcacheconfigpath)) {
Línea 1476... Línea 1476...
1476
    }
1476
    }
Línea 1477... Línea 1477...
1477
 
1477
 
1478
    /**
1478
    /**
1479
     * Test that multiple application loaders work ok.
1479
     * Test that multiple application loaders work ok.
1480
     */
1480
     */
1481
    public function test_multiple_application_loaders() {
1481
    public function test_multiple_application_loaders(): void {
1482
        $instance = cache_config_testing::instance(true);
1482
        $instance = cache_config_testing::instance(true);
1483
        $instance->phpunit_add_file_store('phpunittest1');
1483
        $instance->phpunit_add_file_store('phpunittest1');
1484
        $instance->phpunit_add_file_store('phpunittest2');
1484
        $instance->phpunit_add_file_store('phpunittest2');
1485
        $instance->phpunit_add_definition('phpunit/multi_loader', array(
1485
        $instance->phpunit_add_definition('phpunit/multi_loader', array(
Línea 1907... Línea 1907...
1907
    }
1907
    }
Línea 1908... Línea 1908...
1908
 
1908
 
1909
    /**
1909
    /**
1910
     * Test that multiple application loaders work ok.
1910
     * Test that multiple application loaders work ok.
1911
     */
1911
     */
1912
    public function test_multiple_session_loaders() {
1912
    public function test_multiple_session_loaders(): void {
1913
        /* @var cache_config_testing $instance */
1913
        /* @var cache_config_testing $instance */
1914
        $instance = cache_config_testing::instance(true);
1914
        $instance = cache_config_testing::instance(true);
1915
        $instance->phpunit_add_session_store('phpunittest1');
1915
        $instance->phpunit_add_session_store('phpunittest1');
1916
        $instance->phpunit_add_session_store('phpunittest2');
1916
        $instance->phpunit_add_session_store('phpunittest2');
Línea 1976... Línea 1976...
1976
    }
1976
    }
Línea 1977... Línea 1977...
1977
 
1977
 
1978
    /**
1978
    /**
1979
     * Test switching users with session caches.
1979
     * Test switching users with session caches.
1980
     */
1980
     */
1981
    public function test_session_cache_switch_user() {
1981
    public function test_session_cache_switch_user(): void {
1982
        $this->resetAfterTest(true);
1982
        $this->resetAfterTest(true);
1983
        $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache');
1983
        $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache');
1984
        $user1 = $this->getDataGenerator()->create_user();
1984
        $user1 = $this->getDataGenerator()->create_user();
Línea 2004... Línea 2004...
2004
    }
2004
    }
Línea 2005... Línea 2005...
2005
 
2005
 
2006
    /**
2006
    /**
2007
     * Test switching users with session caches.
2007
     * Test switching users with session caches.
2008
     */
2008
     */
2009
    public function test_session_cache_switch_user_application_mapping() {
2009
    public function test_session_cache_switch_user_application_mapping(): void {
2010
        $this->resetAfterTest(true);
2010
        $this->resetAfterTest(true);
2011
        $instance = cache_config_testing::instance(true);
2011
        $instance = cache_config_testing::instance(true);
2012
        $instance->phpunit_add_file_store('testfilestore');
2012
        $instance->phpunit_add_file_store('testfilestore');
2013
        $instance->phpunit_add_definition('phpunit/testappsession', array(
2013
        $instance->phpunit_add_definition('phpunit/testappsession', array(
Línea 2040... Línea 2040...
2040
    }
2040
    }
Línea 2041... Línea 2041...
2041
 
2041
 
2042
    /**
2042
    /**
2043
     * Test two session caches being used at once to confirm collisions don't occur.
2043
     * Test two session caches being used at once to confirm collisions don't occur.
2044
     */
2044
     */
2045
    public function test_dual_session_caches() {
2045
    public function test_dual_session_caches(): void {
2046
        $instance = cache_config_testing::instance(true);
2046
        $instance = cache_config_testing::instance(true);
2047
        $instance->phpunit_add_definition('phpunit/testsess1', array(
2047
        $instance->phpunit_add_definition('phpunit/testsess1', array(
2048
            'mode' => cache_store::MODE_SESSION,
2048
            'mode' => cache_store::MODE_SESSION,
2049
            'component' => 'phpunit',
2049
            'component' => 'phpunit',
Línea 2074... Línea 2074...
2074
    }
2074
    }
Línea 2075... Línea 2075...
2075
 
2075
 
2076
    /**
2076
    /**
2077
     * Test multiple session caches when switching user.
2077
     * Test multiple session caches when switching user.
2078
     */
2078
     */
2079
    public function test_session_cache_switch_user_multiple() {
2079
    public function test_session_cache_switch_user_multiple(): void {
2080
        $this->resetAfterTest(true);
2080
        $this->resetAfterTest(true);
2081
        $cache1 = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache1');
2081
        $cache1 = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache1');
2082
        $cache2 = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache2');
2082
        $cache2 = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache2');
2083
        $user1 = $this->getDataGenerator()->create_user();
2083
        $user1 = $this->getDataGenerator()->create_user();
Línea 2108... Línea 2108...
2108
     * The application locking feature should work with caches that support multiple identifiers
2108
     * The application locking feature should work with caches that support multiple identifiers
2109
     * (static cache and MongoDB with a specific setting).
2109
     * (static cache and MongoDB with a specific setting).
2110
     *
2110
     *
2111
     * @covers \cache_application
2111
     * @covers \cache_application
2112
     */
2112
     */
2113
    public function test_application_locking_multiple_identifier_cache() {
2113
    public function test_application_locking_multiple_identifier_cache(): void {
2114
        // Get an arbitrary definition (modinfo).
2114
        // Get an arbitrary definition (modinfo).
2115
        $instance = cache_config_testing::instance(true);
2115
        $instance = cache_config_testing::instance(true);
2116
        $definitions = $instance->get_definitions();
2116
        $definitions = $instance->get_definitions();
2117
        $definition = \cache_definition::load('phpunit', $definitions['core/coursemodinfo']);
2117
        $definition = \cache_definition::load('phpunit', $definitions['core/coursemodinfo']);
Línea 2131... Línea 2131...
2131
    /**
2131
    /**
2132
     * Test requiring a lock before attempting to set a key.
2132
     * Test requiring a lock before attempting to set a key.
2133
     *
2133
     *
2134
     * @covers ::set_implementation
2134
     * @covers ::set_implementation
2135
     */
2135
     */
2136
    public function test_application_locking_before_write() {
2136
    public function test_application_locking_before_write(): void {
2137
        $instance = cache_config_testing::instance(true);
2137
        $instance = cache_config_testing::instance(true);
2138
        $instance->phpunit_add_definition('phpunit/test_application_locking', array(
2138
        $instance->phpunit_add_definition('phpunit/test_application_locking', array(
2139
            'mode' => cache_store::MODE_APPLICATION,
2139
            'mode' => cache_store::MODE_APPLICATION,
2140
            'component' => 'phpunit',
2140
            'component' => 'phpunit',
2141
            'area' => 'test_application_locking',
2141
            'area' => 'test_application_locking',
Línea 2230... Línea 2230...
2230
     * Test that locking before write works when writing across multiple layers.
2230
     * Test that locking before write works when writing across multiple layers.
2231
     *
2231
     *
2232
     * @covers \cache_loader
2232
     * @covers \cache_loader
2233
     * @return void
2233
     * @return void
2234
     */
2234
     */
2235
    public function test_application_locking_multiple_layers() {
2235
    public function test_application_locking_multiple_layers(): void {
Línea 2236... Línea 2236...
2236
 
2236
 
2237
        $instance = cache_config_testing::instance(true);
2237
        $instance = cache_config_testing::instance(true);
2238
        $instance->phpunit_add_definition('phpunit/test_application_locking', array(
2238
        $instance->phpunit_add_definition('phpunit/test_application_locking', array(
2239
            'mode' => cache_store::MODE_APPLICATION,
2239
            'mode' => cache_store::MODE_APPLICATION,
Línea 2398... Línea 2398...
2398
    }
2398
    }
Línea 2399... Línea 2399...
2399
 
2399
 
2400
    /**
2400
    /**
2401
     * Test the static cache_helper method purge_stores_used_by_definition.
2401
     * Test the static cache_helper method purge_stores_used_by_definition.
2402
     */
2402
     */
2403
    public function test_purge_stores_used_by_definition() {
2403
    public function test_purge_stores_used_by_definition(): void {
2404
        $instance = cache_config_testing::instance(true);
2404
        $instance = cache_config_testing::instance(true);
2405
        $instance->phpunit_add_definition('phpunit/test_purge_stores_used_by_definition', array(
2405
        $instance->phpunit_add_definition('phpunit/test_purge_stores_used_by_definition', array(
2406
            'mode' => cache_store::MODE_APPLICATION,
2406
            'mode' => cache_store::MODE_APPLICATION,
2407
            'component' => 'phpunit',
2407
            'component' => 'phpunit',
Línea 2420... Línea 2420...
2420
    }
2420
    }
Línea 2421... Línea 2421...
2421
 
2421
 
2422
    /**
2422
    /**
2423
     * Test purge routines.
2423
     * Test purge routines.
2424
     */
2424
     */
2425
    public function test_purge_routines() {
2425
    public function test_purge_routines(): void {
2426
        $instance = cache_config_testing::instance(true);
2426
        $instance = cache_config_testing::instance(true);
2427
        $instance->phpunit_add_definition('phpunit/purge1', array(
2427
        $instance->phpunit_add_definition('phpunit/purge1', array(
2428
            'mode' => cache_store::MODE_APPLICATION,
2428
            'mode' => cache_store::MODE_APPLICATION,
2429
            'component' => 'phpunit',
2429
            'component' => 'phpunit',
Línea 2467... Línea 2467...
2467
    }
2467
    }
Línea 2468... Línea 2468...
2468
 
2468
 
2469
    /**
2469
    /**
2470
     * Tests that ad-hoc caches are correctly purged with a purge_all call.
2470
     * Tests that ad-hoc caches are correctly purged with a purge_all call.
2471
     */
2471
     */
2472
    public function test_purge_all_with_adhoc_caches() {
2472
    public function test_purge_all_with_adhoc_caches(): void {
2473
        $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_cache', 'test');
2473
        $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_cache', 'test');
2474
        $cache->set('test', 123);
2474
        $cache->set('test', 123);
2475
        cache_helper::purge_all();
2475
        cache_helper::purge_all();
2476
        $this->assertFalse($cache->get('test'));
2476
        $this->assertFalse($cache->get('test'));
Línea 2477... Línea 2477...
2477
    }
2477
    }
2478
 
2478
 
2479
    /**
2479
    /**
2480
     * Test that the default stores all support searching.
2480
     * Test that the default stores all support searching.
2481
     */
2481
     */
2482
    public function test_defaults_support_searching() {
2482
    public function test_defaults_support_searching(): void {
2483
        $instance = cache_config_testing::instance(true);
2483
        $instance = cache_config_testing::instance(true);
2484
        $instance->phpunit_add_definition('phpunit/search1', array(
2484
        $instance->phpunit_add_definition('phpunit/search1', array(
2485
            'mode' => cache_store::MODE_APPLICATION,
2485
            'mode' => cache_store::MODE_APPLICATION,
Línea 2530... Línea 2530...
2530
     * Test static acceleration
2530
     * Test static acceleration
2531
     *
2531
     *
2532
     * Note: All the assertGreaterThanOrEqual() in this test should be assertGreaterThan() be because of some microtime()
2532
     * Note: All the assertGreaterThanOrEqual() in this test should be assertGreaterThan() be because of some microtime()
2533
     * resolution problems under some OSs / PHP versions, we are accepting equal as valid outcome. For more info see MDL-57147.
2533
     * resolution problems under some OSs / PHP versions, we are accepting equal as valid outcome. For more info see MDL-57147.
2534
     */
2534
     */
2535
    public function test_static_acceleration() {
2535
    public function test_static_acceleration(): void {
2536
        $instance = cache_config_testing::instance();
2536
        $instance = cache_config_testing::instance();
2537
        $instance->phpunit_add_definition('phpunit/accelerated', array(
2537
        $instance->phpunit_add_definition('phpunit/accelerated', array(
2538
            'mode' => cache_store::MODE_APPLICATION,
2538
            'mode' => cache_store::MODE_APPLICATION,
2539
            'component' => 'phpunit',
2539
            'component' => 'phpunit',
2540
            'area' => 'accelerated',
2540
            'area' => 'accelerated',
Línea 2760... Línea 2760...
2760
        $returnedinstance2 = $cache->get('a');
2760
        $returnedinstance2 = $cache->get('a');
2761
        $returnedinstance1->name = 'b';
2761
        $returnedinstance1->name = 'b';
2762
        $this->assertEquals('b', $returnedinstance2->name);
2762
        $this->assertEquals('b', $returnedinstance2->name);
2763
    }
2763
    }
Línea 2764... Línea 2764...
2764
 
2764
 
2765
    public function test_identifiers_have_separate_caches() {
2765
    public function test_identifiers_have_separate_caches(): void {
2766
        $cachepg = cache::make('core', 'databasemeta', array('dbfamily' => 'pgsql'));
2766
        $cachepg = cache::make('core', 'databasemeta', array('dbfamily' => 'pgsql'));
2767
        $cachepg->set(1, 'here');
2767
        $cachepg->set(1, 'here');
2768
        $cachemy = cache::make('core', 'databasemeta', array('dbfamily' => 'mysql'));
2768
        $cachemy = cache::make('core', 'databasemeta', array('dbfamily' => 'mysql'));
2769
        $cachemy->set(2, 'there');
2769
        $cachemy->set(2, 'there');
2770
        $this->assertEquals('here', $cachepg->get(1));
2770
        $this->assertEquals('here', $cachepg->get(1));
2771
        $this->assertEquals('there', $cachemy->get(2));
2771
        $this->assertEquals('there', $cachemy->get(2));
2772
        $this->assertFalse($cachemy->get(1));
2772
        $this->assertFalse($cachemy->get(1));
Línea 2773... Línea 2773...
2773
    }
2773
    }
2774
 
2774
 
2775
    public function test_performance_debug() {
2775
    public function test_performance_debug(): void {
2776
        global $CFG;
2776
        global $CFG;
Línea 2777... Línea 2777...
2777
        $this->resetAfterTest(true);
2777
        $this->resetAfterTest(true);
Línea 3105... Línea 3105...
3105
        $this->assertEquals($value, $cache->get('value'));
3105
        $this->assertEquals($value, $cache->get('value'));
3106
        $checkstats($startstats, $secondfetchstats);
3106
        $checkstats($startstats, $secondfetchstats);
3107
    }
3107
    }
Línea 3108... Línea 3108...
3108
 
3108
 
3109
 
3109
 
3110
    public function test_static_cache() {
3110
    public function test_static_cache(): void {
3111
        global $CFG;
3111
        global $CFG;
Línea 3112... Línea 3112...
3112
        $this->resetAfterTest(true);
3112
        $this->resetAfterTest(true);
Línea 3138... Línea 3138...
3138
        $endstats = cache_helper::get_stats();
3138
        $endstats = cache_helper::get_stats();
3139
        $this->assertEquals(0, $endstats[$applicationid]['stores']['** static accel. **']['misses']);
3139
        $this->assertEquals(0, $endstats[$applicationid]['stores']['** static accel. **']['misses']);
3140
        $this->assertEquals(3, $endstats[$applicationid]['stores']['** static accel. **']['hits']);
3140
        $this->assertEquals(3, $endstats[$applicationid]['stores']['** static accel. **']['hits']);
3141
    }
3141
    }
Línea 3142... Línea 3142...
3142
 
3142
 
3143
    public function test_performance_debug_off() {
3143
    public function test_performance_debug_off(): void {
3144
        global $CFG;
3144
        global $CFG;
3145
        $this->resetAfterTest(true);
3145
        $this->resetAfterTest(true);
Línea 3146... Línea 3146...
3146
        $CFG->perfdebug = 7;
3146
        $CFG->perfdebug = 7;
Línea 3199... Línea 3199...
3199
     * This test simulates a cache being created, a value being set, then the value being purged.
3199
     * This test simulates a cache being created, a value being set, then the value being purged.
3200
     * A subsequent use of the same cache is started in the same request which fills the cache.
3200
     * A subsequent use of the same cache is started in the same request which fills the cache.
3201
     * A new request is started a short time later.
3201
     * A new request is started a short time later.
3202
     * The cache should be filled.
3202
     * The cache should be filled.
3203
     */
3203
     */
3204
    public function test_session_event_purge_same_second() {
3204
    public function test_session_event_purge_same_second(): void {
3205
        $instance = cache_config_testing::instance();
3205
        $instance = cache_config_testing::instance();
3206
        $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
3206
        $instance->phpunit_add_definition('phpunit/eventpurgetest', array(
3207
            'mode' => cache_store::MODE_SESSION,
3207
            'mode' => cache_store::MODE_SESSION,
3208
            'component' => 'phpunit',
3208
            'component' => 'phpunit',
3209
            'area' => 'eventpurgetest',
3209
            'area' => 'eventpurgetest',
Línea 3239... Línea 3239...
3239
    }
3239
    }
Línea 3240... Línea 3240...
3240
 
3240
 
3241
    /**
3241
    /**
3242
     * Test that values set in different sessions are stored with different key prefixes.
3242
     * Test that values set in different sessions are stored with different key prefixes.
3243
     */
3243
     */
3244
    public function test_session_distinct_storage_key() {
3244
    public function test_session_distinct_storage_key(): void {
Línea 3245... Línea 3245...
3245
        $this->resetAfterTest();
3245
        $this->resetAfterTest();
3246
 
3246
 
3247
        // Prepare a dummy session cache configuration.
3247
        // Prepare a dummy session cache configuration.