Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 27... Línea 27...
27
class setuplib_test extends \advanced_testcase {
27
class setuplib_test extends \advanced_testcase {
Línea 28... Línea 28...
28
 
28
 
29
    /**
29
    /**
30
     * Test get_docs_url_standard in the normal case when we should link to Moodle docs.
30
     * Test get_docs_url_standard in the normal case when we should link to Moodle docs.
31
     */
31
     */
32
    public function test_get_docs_url_standard() {
32
    public function test_get_docs_url_standard(): void {
33
        global $CFG;
33
        global $CFG;
34
        if (empty($CFG->docroot)) {
34
        if (empty($CFG->docroot)) {
35
            $docroot = 'http://docs.moodle.org/';
35
            $docroot = 'http://docs.moodle.org/';
36
        } else {
36
        } else {
Línea 43... Línea 43...
43
    }
43
    }
Línea 44... Línea 44...
44
 
44
 
45
    /**
45
    /**
46
     * Test get_docs_url_standard in the special case of an absolute HTTP URL.
46
     * Test get_docs_url_standard in the special case of an absolute HTTP URL.
47
     */
47
     */
48
    public function test_get_docs_url_http() {
48
    public function test_get_docs_url_http(): void {
49
        $url = 'http://moodle.org/';
49
        $url = 'http://moodle.org/';
50
        $this->assertEquals($url, get_docs_url($url));
50
        $this->assertEquals($url, get_docs_url($url));
Línea 51... Línea 51...
51
    }
51
    }
52
 
52
 
53
    /**
53
    /**
54
     * Test get_docs_url_standard in the special case of an absolute HTTPS URL.
54
     * Test get_docs_url_standard in the special case of an absolute HTTPS URL.
55
     */
55
     */
56
    public function test_get_docs_url_https() {
56
    public function test_get_docs_url_https(): void {
57
        $url = 'https://moodle.org/';
57
        $url = 'https://moodle.org/';
Línea 58... Línea 58...
58
        $this->assertEquals($url, get_docs_url($url));
58
        $this->assertEquals($url, get_docs_url($url));
59
    }
59
    }
60
 
60
 
61
    /**
61
    /**
62
     * Test get_docs_url_standard in the special case of a link relative to wwwroot.
62
     * Test get_docs_url_standard in the special case of a link relative to wwwroot.
63
     */
63
     */
64
    public function test_get_docs_url_wwwroot() {
64
    public function test_get_docs_url_wwwroot(): void {
65
        global $CFG;
65
        global $CFG;
Línea 66... Línea 66...
66
        $this->assertSame($CFG->wwwroot . '/lib/tests/setuplib_test.php',
66
        $this->assertSame($CFG->wwwroot . '/lib/tests/setuplib_test.php',
67
                get_docs_url('%%WWWROOT%%/lib/tests/setuplib_test.php'));
67
                get_docs_url('%%WWWROOT%%/lib/tests/setuplib_test.php'));
68
    }
68
    }
69
 
69
 
70
    /**
70
    /**
Línea 71... Línea 71...
71
     * Test if get_exception_info() removes file system paths.
71
     * Test if get_exception_info() removes file system paths.
72
     */
72
     */
Línea 91... Línea 91...
91
            'Exception message does not contain system paths');
91
            'Exception message does not contain system paths');
92
        $this->assertStringContainsString($expected, $exceptioninfo->debuginfo,
92
        $this->assertStringContainsString($expected, $exceptioninfo->debuginfo,
93
            'Exception debug info does not contain system paths');
93
            'Exception debug info does not contain system paths');
94
    }
94
    }
Línea 95... Línea 95...
95
 
95
 
96
    public function test_localcachedir() {
96
    public function test_localcachedir(): void {
Línea 97... Línea 97...
97
        global $CFG;
97
        global $CFG;
Línea 98... Línea 98...
98
 
98
 
Línea 164... Línea 164...
164
        $this->assertFileDoesNotExist(dirname($testfile));
164
        $this->assertFileDoesNotExist(dirname($testfile));
165
        $this->assertFileExists($timestampfile);
165
        $this->assertFileExists($timestampfile);
166
        $this->assertTimeCurrent(filemtime($timestampfile));
166
        $this->assertTimeCurrent(filemtime($timestampfile));
167
    }
167
    }
Línea 168... Línea 168...
168
 
168
 
169
    public function test_make_unique_directory_basedir_is_file() {
169
    public function test_make_unique_directory_basedir_is_file(): void {
Línea 170... Línea 170...
170
        global $CFG;
170
        global $CFG;
171
 
171
 
172
        // Start with a file instead of a directory.
172
        // Start with a file instead of a directory.
Línea 182... Línea 182...
182
        make_unique_writable_directory($base);
182
        make_unique_writable_directory($base);
Línea 183... Línea 183...
183
 
183
 
184
        unlink($base);
184
        unlink($base);
Línea 185... Línea 185...
185
    }
185
    }
186
 
186
 
Línea 187... Línea 187...
187
    public function test_make_unique_directory() {
187
    public function test_make_unique_directory(): void {
188
        global $CFG;
188
        global $CFG;
189
 
189
 
Línea 198... Línea 198...
198
 
198
 
199
        // Directories should be different each iteration.
199
        // Directories should be different each iteration.
200
        $this->assertNotEquals($firstdir, $seconddir);
200
        $this->assertNotEquals($firstdir, $seconddir);
Línea 201... Línea 201...
201
    }
201
    }
202
 
202
 
Línea 203... Línea 203...
203
    public function test_get_request_storage_directory() {
203
    public function test_get_request_storage_directory(): void {
204
        $this->resetAfterTest(true);
204
        $this->resetAfterTest(true);
205
 
205
 
Línea 235... Línea 235...
235
        purge_all_caches();
235
        purge_all_caches();
236
        $this->assertTrue(is_dir($fourthdir));
236
        $this->assertTrue(is_dir($fourthdir));
237
    }
237
    }
Línea 238... Línea 238...
238
 
238
 
239
 
239
 
240
    public function test_make_request_directory() {
240
    public function test_make_request_directory(): void {
241
        // Every request directory should be unique.
241
        // Every request directory should be unique.
242
        $firstdir   = make_request_directory();
242
        $firstdir   = make_request_directory();
243
        $seconddir  = make_request_directory();
243
        $seconddir  = make_request_directory();
Línea 274... Línea 274...
274
        // And it should be within the new request directory.
274
        // And it should be within the new request directory.
275
        $newrequestdir = get_request_storage_directory();
275
        $newrequestdir = get_request_storage_directory();
276
        $this->assertEquals(0, strpos($fifthdir, $newrequestdir));
276
        $this->assertEquals(0, strpos($fifthdir, $newrequestdir));
277
    }
277
    }
Línea 278... Línea 278...
278
 
278
 
279
    public function test_merge_query_params() {
279
    public function test_merge_query_params(): void {
280
        $original = array(
280
        $original = array(
281
            'id' => '1',
281
            'id' => '1',
282
            'course' => '2',
282
            'course' => '2',
283
            'action' => 'delete',
283
            'action' => 'delete',
Línea 355... Línea 355...
355
    }
355
    }
Línea 356... Línea 356...
356
 
356
 
357
    /**
357
    /**
358
     * Test the link processed by get_exception_info().
358
     * Test the link processed by get_exception_info().
359
     */
359
     */
360
    public function test_get_exception_info_link() {
360
    public function test_get_exception_info_link(): void {
Línea 361... Línea 361...
361
        global $CFG, $SESSION;
361
        global $CFG, $SESSION;
Línea 362... Línea 362...
362
 
362
 
Línea 454... Línea 454...
454
     * @dataProvider data_for_test_get_real_size
454
     * @dataProvider data_for_test_get_real_size
455
     *
455
     *
456
     * @param string $input the input for get_real_size()
456
     * @param string $input the input for get_real_size()
457
     * @param int $expectedbytes the expected bytes
457
     * @param int $expectedbytes the expected bytes
458
     */
458
     */
459
    public function test_get_real_size($input, $expectedbytes) {
459
    public function test_get_real_size($input, $expectedbytes): void {
460
        $this->assertEquals($expectedbytes, get_real_size($input));
460
        $this->assertEquals($expectedbytes, get_real_size($input));
461
    }
461
    }
Línea 462... Línea 462...
462
 
462
 
463
    /**
463
    /**
Línea 479... Línea 479...
479
    }
479
    }
Línea 480... Línea 480...
480
 
480
 
481
    /**
481
    /**
482
     * Test the \core\uuid::generate_uuid_via_pecl_uuid_extension() function.
482
     * Test the \core\uuid::generate_uuid_via_pecl_uuid_extension() function.
483
     */
483
     */
484
    public function test_core_uuid_generate_uuid_via_pecl_uuid_extension() {
484
    public function test_core_uuid_generate_uuid_via_pecl_uuid_extension(): void {
485
        if (!extension_loaded('uuid')) {
485
        if (!extension_loaded('uuid')) {
486
            $this->markTestSkipped("PHP 'uuid' extension not loaded.");
486
            $this->markTestSkipped("PHP 'uuid' extension not loaded.");
487
        }
487
        }
488
        if (!function_exists('uuid_time')) {
488
        if (!function_exists('uuid_time')) {
Línea 496... Línea 496...
496
    }
496
    }
Línea 497... Línea 497...
497
 
497
 
498
    /**
498
    /**
499
     * Test the \core\uuid::generate_uuid_via_random_bytes() function.
499
     * Test the \core\uuid::generate_uuid_via_random_bytes() function.
500
     */
500
     */
501
    public function test_core_uuid_generate_uuid_via_random_bytes() {
501
    public function test_core_uuid_generate_uuid_via_random_bytes(): void {
502
        try {
502
        try {
503
            random_bytes(1);
503
            random_bytes(1);
504
        } catch (\Exception $e) {
504
        } catch (\Exception $e) {
505
            $this->markTestSkipped('No source of entropy for random_bytes. ' . $e->getMessage());
505
            $this->markTestSkipped('No source of entropy for random_bytes. ' . $e->getMessage());
Línea 512... Línea 512...
512
    }
512
    }
Línea 513... Línea 513...
513
 
513
 
514
    /**
514
    /**
515
     * Test the \core\uuid::generate() function.
515
     * Test the \core\uuid::generate() function.
516
     */
516
     */
517
    public function test_core_uuid_generate() {
517
    public function test_core_uuid_generate(): void {
518
        $uuid = \core\uuid::generate();
518
        $uuid = \core\uuid::generate();
519
        $this->assertTrue(self::is_valid_uuid_v4($uuid), "Invalid v4 UUID: '$uuid'");
519
        $this->assertTrue(self::is_valid_uuid_v4($uuid), "Invalid v4 UUID: '$uuid'");
Línea 520... Línea 520...
520
    }
520
    }