Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace core;
17
namespace core;
Línea 18... Línea 18...
18
 
18
 
19
use lang_string;
19
use core\tests\fake_plugins_test_trait;
20
 
20
 
21
/**
21
/**
Línea 27... Línea 27...
27
 * @author     T.J.Hunt@open.ac.uk
27
 * @author     T.J.Hunt@open.ac.uk
28
 * @author     nicolas@moodle.com
28
 * @author     nicolas@moodle.com
29
 */
29
 */
30
final class moodlelib_test extends \advanced_testcase {
30
final class moodlelib_test extends \advanced_testcase {
Línea -... Línea 31...
-
 
31
 
-
 
32
    use fake_plugins_test_trait;
31
 
33
 
32
    /**
34
    /**
33
     * Define a local decimal separator.
35
     * Define a local decimal separator.
34
     *
36
     *
35
     * It is not possible to directly change the result of get_string in
37
     * It is not possible to directly change the result of get_string in
Línea 1104... Línea 1106...
1104
    /**
1106
    /**
1105
     * Provider for long filenames and its expected result, with and without hash.
1107
     * Provider for long filenames and its expected result, with and without hash.
1106
     *
1108
     *
1107
     * @return array of ($filename, $length, $expected, $includehash)
1109
     * @return array of ($filename, $length, $expected, $includehash)
1108
     */
1110
     */
1109
    public function shorten_filename_provider() {
1111
    public static function shorten_filename_provider(): array {
1110
        $filename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem';
1112
        $filename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem';
1111
        $shortfilename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque';
1113
        $shortfilename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque';
Línea 1112... Línea 1114...
1112
 
1114
 
1113
        return [
1115
        return [
Línea 1207... Línea 1209...
1207
    /**
1209
    /**
1208
     * Provider for long filenames and its expected result, with and without hash.
1210
     * Provider for long filenames and its expected result, with and without hash.
1209
     *
1211
     *
1210
     * @return array of ($filename, $length, $expected, $includehash)
1212
     * @return array of ($filename, $length, $expected, $includehash)
1211
     */
1213
     */
1212
    public function shorten_filenames_provider() {
1214
    public static function shorten_filenames_provider(): array {
1213
        $shortfilename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque';
1215
        $shortfilename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque';
1214
        $longfilename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem';
1216
        $longfilename = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem';
1215
        $extfilename = $longfilename.'.zip';
1217
        $extfilename = $longfilename.'.zip';
1216
        $expected = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium tot';
1218
        $expected = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium tot';
1217
        $expectedwithhash = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque l - 3bec1da8b8';
1219
        $expectedwithhash = 'sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque l - 3bec1da8b8';
Línea 1495... Línea 1497...
1495
        set_user_preference('_test_long_user_preference', $longvalue);
1497
        set_user_preference('_test_long_user_preference', $longvalue);
1496
        $this->assertEquals($longvalue, get_user_preferences('_test_long_user_preference'));
1498
        $this->assertEquals($longvalue, get_user_preferences('_test_long_user_preference'));
1497
        $this->assertEquals($longvalue,
1499
        $this->assertEquals($longvalue,
1498
            $DB->get_field('user_preferences', 'value', array('userid' => $USER->id, 'name' => '_test_long_user_preference')));
1500
            $DB->get_field('user_preferences', 'value', array('userid' => $USER->id, 'name' => '_test_long_user_preference')));
Línea 1499... Línea 1501...
1499
 
1501
 
1500
        // Test > 1333 char values, coding_exception expected.
1502
        // Larger preference values are allowed as of MDL-46739.
1501
        $longvalue = str_repeat('a', 1334);
-
 
1502
        try {
1503
        $longervalue = str_repeat('a', 1334);
1503
            set_user_preference('_test_long_user_preference', $longvalue);
1504
        set_user_preference('_test_long_user_preference', $longervalue);
1504
            $this->fail('Exception expected - longer than 1333 chars not allowed as preference value');
1505
        $this->assertEquals($longervalue, get_user_preferences('_test_long_user_preference'));
-
 
1506
        $this->assertEquals(
1505
        } catch (\moodle_exception $ex) {
1507
            $longervalue,
1506
            $this->assertInstanceOf('coding_exception', $ex);
1508
            $DB->get_field('user_preferences', 'value', ['userid' => $USER->id, 'name' => '_test_long_user_preference'])
Línea 1507... Línea 1509...
1507
        }
1509
        );
1508
 
1510
 
1509
        // Test invalid params.
1511
        // Test invalid params.
1510
        try {
1512
        try {
Línea 2115... Línea 2117...
2115
        // In PHP 8.2 exported class names are now fully qualified;
2117
        // In PHP 8.2 exported class names are now fully qualified;
2116
        // previously, the leading backslash was omitted.
2118
        // previously, the leading backslash was omitted.
2117
        $leadingbackslash = (version_compare(PHP_VERSION, '8.2.0', '>=')) ? '\\' : '';
2119
        $leadingbackslash = (version_compare(PHP_VERSION, '8.2.0', '>=')) ? '\\' : '';
Línea 2118... Línea 2120...
2118
 
2120
 
2119
        $expected1 = <<<EOF
2121
        $expected1 = <<<EOF
2120
{$leadingbackslash}lang_string::__set_state(array(
-
 
2121
   'identifier' => 'no',
2122
{$leadingbackslash}core\lang_string::__set_state(array(
2122
   'component' => 'moodle',
2123
   'component' => 'moodle',
2123
   'a' => NULL,
-
 
2124
   'lang' => NULL,
2124
   'a' => NULL,
2125
   'string' => NULL,
2125
   'string' => NULL,
-
 
2126
   'forcedstring' => false,
-
 
2127
   'identifier' => 'no',
2126
   'forcedstring' => false,
2128
   'lang' => NULL,
2127
))
2129
))
Línea 2128... Línea 2130...
2128
EOF;
2130
EOF;
2129
 
2131
 
Línea 2951... Línea 2953...
2951
     *
2953
     *
2952
     * @return array
2954
     * @return array
2953
     */
2955
     */
2954
    public static function update_internal_user_password_no_cache_provider(): array {
2956
    public static function update_internal_user_password_no_cache_provider(): array {
2955
        return [
2957
        return [
2956
            'Password is not empty' => ['cas', 'wonkawonka'],
2958
            'Password is not empty' => ['db', 'wonkawonka'],
2957
            'Password is an empty string' => ['oauth2', ''],
2959
            'Password is an empty string' => ['oauth2', ''],
2958
            'Password is null' => ['oauth2', null],
2960
            'Password is null' => ['oauth2', null],
2959
        ];
2961
        ];
2960
    }
2962
    }
Línea 2966... Línea 2968...
2966
    public function test_update_internal_user_password_update_no_cache(): void {
2968
    public function test_update_internal_user_password_update_no_cache(): void {
2967
        $this->resetAfterTest();
2969
        $this->resetAfterTest();
Línea 2968... Línea 2970...
2968
 
2970
 
2969
        $user = $this->getDataGenerator()->create_user(array('password' => 'test'));
2971
        $user = $this->getDataGenerator()->create_user(array('password' => 'test'));
2970
        $this->assertNotEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
2972
        $this->assertNotEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
Línea 2971... Línea 2973...
2971
        $user->auth = 'cas'; // Change to a auth that does not store passwords.
2973
        $user->auth = 'db'; // Change to a auth that does not store passwords.
2972
 
2974
 
2973
        $sink = $this->redirectEvents();
2975
        $sink = $this->redirectEvents();
Línea 3211... Línea 3213...
3211
    }
3213
    }
Línea 3212... Línea 3214...
3212
 
3214
 
3213
    /**
3215
    /**
3214
     * A data provider for testing email messageid
3216
     * A data provider for testing email messageid
3215
     */
3217
     */
3216
    public function generate_email_messageid_provider() {
3218
    public static function generate_email_messageid_provider(): array {
3217
        return array(
3219
        return array(
3218
            'nopath' => array(
3220
            'nopath' => array(
3219
                'wwwroot' => 'http://www.example.com',
3221
                'wwwroot' => 'http://www.example.com',
3220
                'ids' => array(
3222
                'msgids' => array(
3221
                    'a-custom-id' => '<a-custom-id@www.example.com>',
3223
                    'a-custom-id' => '<a-custom-id@www.example.com>',
3222
                    'an-id-with-/-a-slash' => '<an-id-with-%2F-a-slash@www.example.com>',
3224
                    'an-id-with-/-a-slash' => '<an-id-with-%2F-a-slash@www.example.com>',
3223
                ),
3225
                ),
3224
            ),
3226
            ),
3225
            'path' => array(
3227
            'path' => array(
3226
                'wwwroot' => 'http://www.example.com/path/subdir',
3228
                'wwwroot' => 'http://www.example.com/path/subdir',
3227
                'ids' => array(
3229
                'msgids' => array(
3228
                    'a-custom-id' => '<a-custom-id/path/subdir@www.example.com>',
3230
                    'a-custom-id' => '<a-custom-id/path/subdir@www.example.com>',
3229
                    'an-id-with-/-a-slash' => '<an-id-with-%2F-a-slash/path/subdir@www.example.com>',
3231
                    'an-id-with-/-a-slash' => '<an-id-with-%2F-a-slash/path/subdir@www.example.com>',
3230
                ),
3232
                ),
3231
            ),
3233
            ),
Línea 3278... Línea 3280...
3278
    }
3280
    }
Línea 3279... Línea 3281...
3279
 
3281
 
3280
    /**
3282
    /**
3281
     * A data provider for testing email diversion
3283
     * A data provider for testing email diversion
3282
     */
3284
     */
3283
    public function diverted_emails_provider() {
3285
    public static function diverted_emails_provider(): array {
3284
        return array(
3286
        return array(
3285
            'nodiverts' => array(
3287
            'nodiverts' => array(
3286
                'divertallemailsto' => null,
3288
                'divertallemailsto' => null,
3287
                'divertallemailsexcept' => null,
3289
                'divertallemailsexcept' => null,
3288
                array(
3290
                'addresses' => array(
3289
                    'foo@example.com',
3291
                    'foo@example.com',
3290
                    'test@real.com',
3292
                    'test@real.com',
3291
                    'fred.jones@example.com',
3293
                    'fred.jones@example.com',
3292
                    'dev1@dev.com',
3294
                    'dev1@dev.com',
3293
                    'fred@example.com',
3295
                    'fred@example.com',
3294
                    'fred+verp@example.com',
3296
                    'fred+verp@example.com',
3295
                ),
3297
                ),
3296
                false,
3298
                'expected' => false,
3297
            ),
3299
            ),
3298
            'alldiverts' => array(
3300
            'alldiverts' => array(
3299
                'divertallemailsto' => 'somewhere@elsewhere.com',
3301
                'divertallemailsto' => 'somewhere@elsewhere.com',
3300
                'divertallemailsexcept' => null,
3302
                'divertallemailsexcept' => null,
3301
                array(
3303
                'addresses' => array(
3302
                    'foo@example.com',
3304
                    'foo@example.com',
3303
                    'test@real.com',
3305
                    'test@real.com',
3304
                    'fred.jones@example.com',
3306
                    'fred.jones@example.com',
3305
                    'dev1@dev.com',
3307
                    'dev1@dev.com',
3306
                    'fred@example.com',
3308
                    'fred@example.com',
3307
                    'fred+verp@example.com',
3309
                    'fred+verp@example.com',
3308
                ),
3310
                ),
3309
                true,
3311
                'expected' => true,
3310
            ),
3312
            ),
3311
            'alsodiverts' => array(
3313
            'alsodiverts' => array(
3312
                'divertallemailsto' => 'somewhere@elsewhere.com',
3314
                'divertallemailsto' => 'somewhere@elsewhere.com',
3313
                'divertallemailsexcept' => '@dev.com, fred(\+.*)?@example.com',
3315
                'divertallemailsexcept' => '@dev.com, fred(\+.*)?@example.com',
3314
                array(
3316
                'addresses' => array(
3315
                    'foo@example.com',
3317
                    'foo@example.com',
3316
                    'test@real.com',
3318
                    'test@real.com',
3317
                    'fred.jones@example.com',
3319
                    'fred.jones@example.com',
3318
                    'Fred.Jones@Example.com',
3320
                    'Fred.Jones@Example.com',
3319
                ),
3321
                ),
3320
                true,
3322
                'expected' => true,
3321
            ),
3323
            ),
3322
            'divertsexceptions' => array(
3324
            'divertsexceptions' => array(
3323
                'divertallemailsto' => 'somewhere@elsewhere.com',
3325
                'divertallemailsto' => 'somewhere@elsewhere.com',
3324
                'divertallemailsexcept' => '@dev.com, fred(\+.*)?@example.com',
3326
                'divertallemailsexcept' => '@dev.com, fred(\+.*)?@example.com',
3325
                array(
3327
                'addresses' => array(
3326
                    'dev1@dev.com',
3328
                    'dev1@dev.com',
3327
                    'fred@example.com',
3329
                    'fred@example.com',
3328
                    'Fred@Example.com',
3330
                    'Fred@Example.com',
3329
                    'fred+verp@example.com',
3331
                    'fred+verp@example.com',
3330
                ),
3332
                ),
3331
                false,
3333
                'expected' => false,
3332
            ),
3334
            ),
3333
            'divertsexceptionsnewline' => array(
3335
            'divertsexceptionsnewline' => array(
3334
                'divertallemailsto' => 'somewhere@elsewhere.com',
3336
                'divertallemailsto' => 'somewhere@elsewhere.com',
3335
                'divertallemailsexcept' => "@dev.com\nfred(\+.*)?@example.com",
3337
                'divertallemailsexcept' => "@dev.com\nfred(\+.*)?@example.com",
3336
                array(
3338
                'addresses' => array(
3337
                    'dev1@dev.com',
3339
                    'dev1@dev.com',
3338
                    'fred@example.com',
3340
                    'fred@example.com',
3339
                    'fred+verp@example.com',
3341
                    'fred+verp@example.com',
3340
                ),
3342
                ),
3341
                false,
3343
                'expected' => false,
3342
            ),
3344
            ),
3343
            'alsodivertsnewline' => array(
3345
            'alsodivertsnewline' => array(
3344
                'divertallemailsto' => 'somewhere@elsewhere.com',
3346
                'divertallemailsto' => 'somewhere@elsewhere.com',
3345
                'divertallemailsexcept' => "@dev.com\nfred(\+.*)?@example.com",
3347
                'divertallemailsexcept' => "@dev.com\nfred(\+.*)?@example.com",
3346
                array(
3348
                'addresses' => array(
3347
                    'foo@example.com',
3349
                    'foo@example.com',
3348
                    'test@real.com',
3350
                    'test@real.com',
3349
                    'fred.jones@example.com',
3351
                    'fred.jones@example.com',
3350
                ),
3352
                ),
3351
                true,
3353
                'expected' => true,
3352
            ),
3354
            ),
3353
            'alsodivertsblankline' => array(
3355
            'alsodivertsblankline' => array(
3354
                'divertallemailsto' => 'somewhere@elsewhere.com',
3356
                'divertallemailsto' => 'somewhere@elsewhere.com',
3355
                'divertallemailsexcept' => "@dev.com\n",
3357
                'divertallemailsexcept' => "@dev.com\n",
3356
                [
3358
                'addresses' => [
3357
                    'lionel@example.com',
3359
                    'lionel@example.com',
3358
                ],
3360
                ],
3359
                true,
3361
                'expected' => true,
3360
            ),
3362
            ),
3361
            'divertsexceptionblankline' => array(
3363
            'divertsexceptionblankline' => array(
3362
                'divertallemailsto' => 'somewhere@elsewhere.com',
3364
                'divertallemailsto' => 'somewhere@elsewhere.com',
3363
                'divertallemailsexcept' => "@example.com\n",
3365
                'divertallemailsexcept' => "@example.com\n",
3364
                [
3366
                'addresses' => [
3365
                    'lionel@example.com',
3367
                    'lionel@example.com',
3366
                ],
3368
                ],
3367
                false,
3369
                'expected' => false,
3368
            ),
3370
            ),
3369
        );
3371
        );
Línea 3370... Línea 3372...
3370
    }
3372
    }
Línea 3485... Línea 3487...
3485
    /**
3487
    /**
3486
     * Data provider for {@see test_email_to_user_attachment}
3488
     * Data provider for {@see test_email_to_user_attachment}
3487
     *
3489
     *
3488
     * @return array
3490
     * @return array
3489
     */
3491
     */
3490
    public function email_to_user_attachment_provider(): array {
3492
    public static function email_to_user_attachment_provider(): array {
3491
        global $CFG;
3493
        global $CFG;
Línea 3492... Línea 3494...
3492
 
3494
 
3493
        // Return all paths that can be used to send attachments from.
3495
        // Return all paths that can be used to send attachments from.
3494
        return [
3496
        return [
Línea 3858... Línea 3860...
3858
    /**
3860
    /**
3859
     * Data provider for {@see test_count_words}.
3861
     * Data provider for {@see test_count_words}.
3860
     *
3862
     *
3861
     * @return array of test cases.
3863
     * @return array of test cases.
3862
     */
3864
     */
3863
    public function count_words_testcases(): array {
3865
    public static function count_words_testcases(): array {
3864
        // Copy-pasting example from MDL-64240.
3866
        // Copy-pasting example from MDL-64240.
3865
        $copypasted = <<<EOT
3867
        $copypasted = <<<EOT
3866
<p onclick="alert('boop');">Snoot is booped</p>
3868
<p onclick="alert('boop');">Snoot is booped</p>
3867
 <script>alert('Boop the snoot');</script>
3869
 <script>alert('Boop the snoot');</script>
3868
 <img alt="Boop the Snoot." src="https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.geekfill.com%2Fwp-content%2Fuploads%2F2015%2F08%2FBoop-the-Snoot.jpg&f=1">
3870
 <img alt="Boop the Snoot." src="https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.geekfill.com%2Fwp-content%2Fuploads%2F2015%2F08%2FBoop-the-Snoot.jpg&f=1">
Línea 3933... Línea 3935...
3933
    /**
3935
    /**
3934
     * Data provider for {@see count_letters_testcases}.
3936
     * Data provider for {@see count_letters_testcases}.
3935
     *
3937
     *
3936
     * @return array of test cases.
3938
     * @return array of test cases.
3937
     */
3939
     */
3938
    public function count_letters_testcases(): array {
3940
    public static function count_letters_testcases(): array {
3939
        return [
3941
        return [
3940
            [0, ''],
3942
            [0, ''],
3941
            [1, 'x'],
3943
            [1, 'x'],
3942
            [1, '&amp;'],
3944
            [1, '&amp;'],
3943
            [4, '<p>frog</p>'],
3945
            [4, '<p>frog</p>'],
Línea 4098... Línea 4100...
4098
    }
4100
    }
Línea 4099... Línea 4101...
4099
 
4101
 
4100
    /**
4102
    /**
4101
     * Data provider for private ips.
4103
     * Data provider for private ips.
4102
     */
4104
     */
4103
    public function data_private_ips() {
4105
    public static function data_private_ips(): array {
4104
        return array(
4106
        return array(
4105
            array('10.0.0.0'),
4107
            array('10.0.0.0'),
4106
            array('172.16.0.0'),
4108
            array('172.16.0.0'),
4107
            array('192.168.1.0'),
4109
            array('192.168.1.0'),
Línea 4123... Línea 4125...
4123
    }
4125
    }
Línea 4124... Línea 4126...
4124
 
4126
 
4125
    /**
4127
    /**
4126
     * Data provider for public ips.
4128
     * Data provider for public ips.
4127
     */
4129
     */
4128
    public function data_public_ips() {
4130
    public static function data_public_ips(): array {
4129
        return array(
4131
        return array(
4130
            array('2400:cb00:2048:1::8d65:71b3'),
4132
            array('2400:cb00:2048:1::8d65:71b3'),
4131
            array('2400:6180:0:d0::1b:2001'),
4133
            array('2400:6180:0:d0::1b:2001'),
4132
            array('141.101.113.179'),
4134
            array('141.101.113.179'),
Línea 4176... Línea 4178...
4176
    /**
4178
    /**
4177
     * Data provider for test_can_send_from_real_email_address.
4179
     * Data provider for test_can_send_from_real_email_address.
4178
     *
4180
     *
4179
     * @return array Returns an array of test data for the above function.
4181
     * @return array Returns an array of test data for the above function.
4180
     */
4182
     */
4181
    public function data_can_send_from_real_email_address() {
4183
    public static function data_can_send_from_real_email_address(): array {
4182
        return [
4184
        return [
4183
            // Test from email is in allowed domain.
4185
            // Test from email is in allowed domain.
4184
            // Test that from display is set to show no one.
4186
            // Test that from display is set to show no one.
4185
            [
4187
            [
4186
                'email' => 'fromuser@example.com',
4188
                'email' => 'fromuser@example.com',
Línea 4322... Línea 4324...
4322
    /**
4324
    /**
4323
     * Data provider for data_email_is_not_allowed_for_allowemailaddresses.
4325
     * Data provider for data_email_is_not_allowed_for_allowemailaddresses.
4324
     *
4326
     *
4325
     * @return array Returns an array of test data for the above function.
4327
     * @return array Returns an array of test data for the above function.
4326
     */
4328
     */
4327
    public function data_email_is_not_allowed_for_allowemailaddresses() {
4329
    public static function data_email_is_not_allowed_for_allowemailaddresses(): array {
4328
        return [
4330
        return [
4329
            // Test allowed domain empty list.
4331
            // Test allowed domain empty list.
4330
            [
4332
            [
4331
                'email' => 'fromuser@example.com',
4333
                'email' => 'fromuser@example.com',
4332
                'config' => '',
4334
                'config' => '',
Línea 4401... Línea 4403...
4401
    /**
4403
    /**
4402
     * Data provider for test_email_is_not_allowed_for_denyemailaddresses.
4404
     * Data provider for test_email_is_not_allowed_for_denyemailaddresses.
4403
     *
4405
     *
4404
     * @return array Returns an array of test data for the above function.
4406
     * @return array Returns an array of test data for the above function.
4405
     */
4407
     */
4406
    public function data_email_is_not_allowed_for_denyemailaddresses() {
4408
    public static function data_email_is_not_allowed_for_denyemailaddresses(): array {
4407
        return [
4409
        return [
4408
            // Test denied domain empty list.
4410
            // Test denied domain empty list.
4409
            [
4411
            [
4410
                'email' => 'fromuser@example.com',
4412
                'email' => 'fromuser@example.com',
4411
                'config' => '',
4413
                'config' => '',
Línea 4579... Línea 4581...
4579
    /**
4581
    /**
4580
     * Data provider with list of default values for user in component_class_callback tests.
4582
     * Data provider with list of default values for user in component_class_callback tests.
4581
     *
4583
     *
4582
     * @return array
4584
     * @return array
4583
     */
4585
     */
4584
    public function component_class_callback_default_provider() {
4586
    public static function component_class_callback_default_provider(): array {
4585
        return [
4587
        return [
4586
            'null' => [null],
4588
            'null' => [null],
4587
            'empty string' => [''],
4589
            'empty string' => [''],
4588
            'string' => ['This is a string'],
4590
            'string' => ['This is a string'],
4589
            'int' => [12345],
4591
            'int' => [12345],
Línea 4595... Línea 4597...
4595
    /**
4597
    /**
4596
     * Data provider with list of default values for user in component_class_callback tests.
4598
     * Data provider with list of default values for user in component_class_callback tests.
4597
     *
4599
     *
4598
     * @return array
4600
     * @return array
4599
     */
4601
     */
4600
    public function component_class_callback_data_provider() {
4602
    public static function component_class_callback_data_provider(): array {
4601
        return [
4603
        return [
4602
            'empty string' => [''],
4604
            'empty string' => [''],
4603
            'string' => ['This is a string'],
4605
            'string' => ['This is a string'],
4604
            'int' => [12345],
4606
            'int' => [12345],
4605
            'stdClass' => [(object) ['this is my content']],
4607
            'stdClass' => [(object) ['this is my content']],
Línea 4610... Línea 4612...
4610
    /**
4612
    /**
4611
     * Data provider with list of default values for user in component_class_callback tests.
4613
     * Data provider with list of default values for user in component_class_callback tests.
4612
     *
4614
     *
4613
     * @return array
4615
     * @return array
4614
     */
4616
     */
4615
    public function component_class_callback_multiple_params_provider() {
4617
    public static function component_class_callback_multiple_params_provider(): array {
4616
        return [
4618
        return [
4617
            'empty array' => [
4619
            'empty array' => [
4618
                [],
4620
                [],
4619
                0,
4621
                0,
4620
            ],
4622
            ],
Línea 4655... Línea 4657...
4655
    /**
4657
    /**
4656
     * Provides a set of callables and their human readable names.
4658
     * Provides a set of callables and their human readable names.
4657
     *
4659
     *
4658
     * @return array of (string)case => [(mixed)callable, (string|bool)expected description]
4660
     * @return array of (string)case => [(mixed)callable, (string|bool)expected description]
4659
     */
4661
     */
4660
    public function callable_names_provider() {
4662
    public static function callable_names_provider(): array {
4661
        return [
4663
        return [
4662
            'integer' => [
4664
            'integer' => [
4663
                386,
4665
                386,
4664
                false,
4666
                false,
4665
            ],
4667
            ],
Línea 4673... Línea 4675...
4673
            ],
4675
            ],
4674
            'static_method_of_literal_class' => [
4676
            'static_method_of_literal_class' => [
4675
                ['my_foobar_class', 'my_foobar_method'],
4677
                ['my_foobar_class', 'my_foobar_method'],
4676
                'my_foobar_class::my_foobar_method',
4678
                'my_foobar_class::my_foobar_method',
4677
            ],
4679
            ],
4678
            'static_method_of_object' => [
-
 
4679
                [$this, 'my_foobar_method'],
-
 
4680
                'core\moodlelib_test::my_foobar_method',
-
 
4681
            ],
-
 
4682
            'method_of_object' => [
4680
            'method_of_object' => [
4683
                [new lang_string('parentlanguage', 'core_langconfig'), 'my_foobar_method'],
4681
                [new lang_string('parentlanguage', 'core_langconfig'), 'my_foobar_method'],
4684
                'lang_string::my_foobar_method',
4682
                'core\lang_string::my_foobar_method',
4685
            ],
4683
            ],
4686
            'function_as_literal' => [
4684
            'function_as_literal' => [
4687
                'my_foobar_callback',
4685
                'my_foobar_callback',
4688
                'my_foobar_callback',
4686
                'my_foobar_callback',
4689
            ],
4687
            ],
Línea 4693... Línea 4691...
4693
            ],
4691
            ],
4694
        ];
4692
        ];
4695
    }
4693
    }
Línea 4696... Línea 4694...
4696
 
4694
 
-
 
4695
    /**
-
 
4696
     * Test that get_callable_name works with a static method on an instance.
-
 
4697
     */
-
 
4698
    public function test_get_callable_name_this(): void {
-
 
4699
        $this->assertSame('core\moodlelib_test::foo', get_callable_name([$this, 'foo']));
-
 
4700
    }
-
 
4701
 
4697
    /**
4702
    /**
4698
     * Data provider for \core_moodlelib_testcase::test_get_complete_user_data().
4703
     * Data provider for \core_moodlelib_testcase::test_get_complete_user_data().
4699
     *
4704
     *
4700
     * @return array
4705
     * @return array
4701
     */
4706
     */
4702
    public function user_data_provider() {
4707
    public static function user_data_provider(): array {
4703
        return [
4708
        return [
4704
            'Fetch data using a valid username' => [
4709
            'Fetch data using a valid username' => [
4705
                'username', 's1', true
4710
                'username', 's1', true
4706
            ],
4711
            ],
Línea 4832... Línea 4837...
4832
    }
4837
    }
Línea 4833... Línea 4838...
4833
 
4838
 
4834
    /**
4839
    /**
4835
     * Data provider for the test_get_time_interval_string() method.
4840
     * Data provider for the test_get_time_interval_string() method.
4836
     */
4841
     */
4837
    public function get_time_interval_string_provider() {
4842
    public static function get_time_interval_string_provider(): array {
4838
        return [
4843
        return [
4839
            'Time is after the reference time by 1 minute, omitted format' => [
4844
            'Time is after the reference time by 1 minute, omitted format' => [
4840
                'time1' => 12345660,
4845
                'time1' => 12345660,
4841
                'time2' => 12345600,
4846
                'time2' => 12345600,
Línea 4990... Línea 4995...
4990
    /**
4995
    /**
4991
     * Provider for display_size
4996
     * Provider for display_size
4992
     *
4997
     *
4993
     * @return array of ($size, $expected)
4998
     * @return array of ($size, $expected)
4994
     */
4999
     */
4995
    public function display_size_provider() {
5000
    public static function display_size_provider(): array {
Línea 4996... Línea 5001...
4996
 
5001
 
4997
        return [
5002
        return [
4998
            [0, '0 bytes'],
5003
            [0, '0 bytes'],
4999
            [1, '1 bytes'],
5004
            [1, '1 bytes'],
Línea 5032... Línea 5037...
5032
    /**
5037
    /**
5033
     * Provider for display_size using fixed units.
5038
     * Provider for display_size using fixed units.
5034
     *
5039
     *
5035
     * @return array of ($size, $units, $expected)
5040
     * @return array of ($size, $units, $expected)
5036
     */
5041
     */
5037
    public function display_size_fixed_provider(): array {
5042
    public static function display_size_fixed_provider(): array {
5038
        return [
5043
        return [
5039
            [0, 'KB', '0.0 KB'],
5044
            [0, 'KB', '0.0 KB'],
5040
            [1, 'MB', '0.0 MB'],
5045
            [1, 'MB', '0.0 MB'],
5041
            [777777777, 'GB', '0.7 GB'],
5046
            [777777777, 'GB', '0.7 GB'],
5042
            [8888888888, 'PB', '0.0 PB'],
5047
            [8888888888, 'PB', '0.0 PB'],
Línea 5062... Línea 5067...
5062
    /**
5067
    /**
5063
     * Provider for display_size using specified decimal places.
5068
     * Provider for display_size using specified decimal places.
5064
     *
5069
     *
5065
     * @return array of ($size, $decimalplaces, $units, $expected)
5070
     * @return array of ($size, $decimalplaces, $units, $expected)
5066
     */
5071
     */
5067
    public function display_size_dp_provider(): array {
5072
    public static function display_size_dp_provider(): array {
5068
        return [
5073
        return [
5069
            [0, 1, 'KB', '0.0 KB'],
5074
            [0, 1, 'KB', '0.0 KB'],
5070
            [1, 6, 'MB', '0.000001 MB'],
5075
            [1, 6, 'MB', '0.000001 MB'],
5071
            [777777777, 0, 'GB', '1 GB'],
5076
            [777777777, 0, 'GB', '1 GB'],
5072
            [777777777, 0, '', '742 MB'],
5077
            [777777777, 0, '', '742 MB'],
Línea 5108... Línea 5113...
5108
    /**
5113
    /**
5109
     * Data provider for get_list_of_plugins checks.
5114
     * Data provider for get_list_of_plugins checks.
5110
     *
5115
     *
5111
     * @return  array
5116
     * @return  array
5112
     */
5117
     */
5113
    public function get_list_of_plugins_provider(): array {
5118
    public static function get_list_of_plugins_provider(): array {
5114
        return [
5119
        return [
5115
            'Standard excludes' => [
5120
            'Standard excludes' => [
5116
                ['amdd', 'class', 'local', 'test'],
5121
                ['amdd', 'class', 'local', 'test'],
5117
                [
5122
                [
5118
                    '.' => [],
5123
                    '.' => [],
Línea 5187... Línea 5192...
5187
     * Test get_home_page() method.
5192
     * Test get_home_page() method.
5188
     *
5193
     *
5189
     * @dataProvider get_home_page_provider
5194
     * @dataProvider get_home_page_provider
5190
     * @param string $user Whether the user is logged, guest or not logged.
5195
     * @param string $user Whether the user is logged, guest or not logged.
5191
     * @param int $expected Expected value after calling the get_home_page method.
5196
     * @param int $expected Expected value after calling the get_home_page method.
5192
     * @param int $defaulthomepage The $CFG->defaulthomepage setting value.
5197
     * @param int|string|null $defaulthomepage The $CFG->defaulthomepage setting value.
5193
     * @param int $enabledashboard Whether the dashboard should be enabled or not.
5198
     * @param int|null $enabledashboard Whether the dashboard should be enabled or not.
5194
     * @param int $userpreference User preference for the home page setting.
5199
     * @param int|string|null $userpreference User preference for the home page setting.
-
 
5200
     * $param int|null $allowguestmymoodle The $CFG->allowguestmymoodle setting value.
5195
     * @covers ::get_home_page
5201
     * @covers ::get_home_page
5196
     */
5202
     */
-
 
5203
    public function test_get_home_page(
-
 
5204
        string $user,
-
 
5205
        int $expected,
5197
    public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null,
5206
        int|string|null $defaulthomepage = null,
-
 
5207
        ?int $enabledashboard = null,
5198
            ?int $userpreference = null): void {
5208
        int|string|null $userpreference = null,
-
 
5209
        ?int $allowguestmymoodle = null,
-
 
5210
    ): void {
5199
        global $CFG, $USER;
5211
        global $CFG, $USER;
Línea 5200... Línea 5212...
5200
 
5212
 
Línea 5201... Línea 5213...
5201
        $this->resetAfterTest();
5213
        $this->resetAfterTest();
Línea 5210... Línea 5222...
5210
            $CFG->defaulthomepage = $defaulthomepage;
5222
            $CFG->defaulthomepage = $defaulthomepage;
5211
        }
5223
        }
5212
        if (isset($enabledashboard)) {
5224
        if (isset($enabledashboard)) {
5213
            $CFG->enabledashboard = $enabledashboard;
5225
            $CFG->enabledashboard = $enabledashboard;
5214
        }
5226
        }
-
 
5227
        if (isset($allowguestmymoodle)) {
-
 
5228
            $CFG->allowguestmymoodle = $allowguestmymoodle;
-
 
5229
        }
Línea 5215... Línea 5230...
5215
 
5230
 
5216
        if ($USER) {
5231
        if ($USER) {
5217
            set_user_preferences(['user_home_page_preference' => $userpreference], $USER->id);
5232
            set_user_preferences(['user_home_page_preference' => $userpreference], $USER->id);
Línea 5224... Línea 5239...
5224
    /**
5239
    /**
5225
     * Data provider for get_home_page checks.
5240
     * Data provider for get_home_page checks.
5226
     *
5241
     *
5227
     * @return array
5242
     * @return array
5228
     */
5243
     */
5229
    public function get_home_page_provider(): array {
5244
    public static function get_home_page_provider(): array {
-
 
5245
        global $CFG;
-
 
5246
 
5230
        return [
5247
        return [
5231
            'No logged user' => [
5248
            'No logged user' => [
5232
                'user' => 'nologged',
5249
                'user' => 'nologged',
5233
                'expected' => HOMEPAGE_SITE,
5250
                'expected' => HOMEPAGE_SITE,
5234
            ],
5251
            ],
-
 
5252
            'Guest user. Dashboard set as default home page and enabled for guests' => [
5235
            'Guest user' => [
5253
                'user' => 'guest',
-
 
5254
                'expected' => HOMEPAGE_MY,
-
 
5255
            ],
-
 
5256
            'Guest user. Dashboard set as default home page but disabled for guests' => [
5236
                'user' => 'guest',
5257
                'user' => 'guest',
5237
                'expected' => HOMEPAGE_SITE,
5258
                'expected' => HOMEPAGE_SITE,
-
 
5259
                'defaulthomepage' => HOMEPAGE_MY,
-
 
5260
                'enabledashboard' => 1,
-
 
5261
                'userpreference' => null,
-
 
5262
                'allowguestmymoodle' => 0,
-
 
5263
            ],
-
 
5264
            'Guest user. My courses set as default home page' => [
-
 
5265
                'user' => 'guest',
-
 
5266
                'expected' => HOMEPAGE_SITE,
-
 
5267
                'defaulthomepage' => HOMEPAGE_MYCOURSES,
-
 
5268
            ],
-
 
5269
            'Guest user. User preference set as default page' => [
-
 
5270
                'user' => 'guest',
-
 
5271
                'expected' => HOMEPAGE_SITE,
-
 
5272
                'defaulthomepage' => HOMEPAGE_USER,
5238
            ],
5273
            ],
5239
            'Logged user. Dashboard set as default home page and enabled' => [
5274
            'Logged user. Dashboard set as default home page and enabled' => [
5240
                'user' => 'logged',
5275
                'user' => 'logged',
5241
                'expected' => HOMEPAGE_MY,
5276
                'expected' => HOMEPAGE_MY,
5242
                'defaulthomepage' => HOMEPAGE_MY,
-
 
5243
                'enabledashboard' => 1,
-
 
5244
            ],
5277
            ],
5245
            'Logged user. Dashboard set as default home page but disabled' => [
5278
            'Logged user. Dashboard set as default home page but disabled' => [
5246
                'user' => 'logged',
5279
                'user' => 'logged',
5247
                'expected' => HOMEPAGE_MYCOURSES,
5280
                'expected' => HOMEPAGE_MYCOURSES,
5248
                'defaulthomepage' => HOMEPAGE_MY,
5281
                'defaulthomepage' => HOMEPAGE_MY,
Línea 5270... Línea 5303...
5270
                'user' => 'logged',
5303
                'user' => 'logged',
5271
                'expected' => HOMEPAGE_SITE,
5304
                'expected' => HOMEPAGE_SITE,
5272
                'defaulthomepage' => HOMEPAGE_SITE,
5305
                'defaulthomepage' => HOMEPAGE_SITE,
5273
                'enabledashboard' => 0,
5306
                'enabledashboard' => 0,
5274
            ],
5307
            ],
-
 
5308
            'Logged user. URL set as default home page.' => [
-
 
5309
                'user' => 'logged',
-
 
5310
                'expected' => HOMEPAGE_URL,
-
 
5311
                'defaulthomepage' => "/home",
-
 
5312
            ],
5275
            'Logged user. User preference set as default page with dashboard enabled and user preference set to dashboard' => [
5313
            'Logged user. User preference set as default page with dashboard enabled and user preference set to dashboard' => [
5276
                'user' => 'logged',
5314
                'user' => 'logged',
5277
                'expected' => HOMEPAGE_MY,
5315
                'expected' => HOMEPAGE_MY,
5278
                'defaulthomepage' => HOMEPAGE_USER,
5316
                'defaulthomepage' => HOMEPAGE_USER,
5279
                'enabledashboard' => 1,
5317
                'enabledashboard' => 1,
Línea 5298... Línea 5336...
5298
                'expected' => HOMEPAGE_MYCOURSES,
5336
                'expected' => HOMEPAGE_MYCOURSES,
5299
                'defaulthomepage' => HOMEPAGE_USER,
5337
                'defaulthomepage' => HOMEPAGE_USER,
5300
                'enabledashboard' => 0,
5338
                'enabledashboard' => 0,
5301
                'userpreference' => HOMEPAGE_MYCOURSES,
5339
                'userpreference' => HOMEPAGE_MYCOURSES,
5302
            ],
5340
            ],
-
 
5341
            'Logged user. User preference set as default page with user preference set to URL.' => [
-
 
5342
                'user' => 'logged',
-
 
5343
                'expected' => HOMEPAGE_URL,
-
 
5344
                'defaulthomepage' => HOMEPAGE_USER,
-
 
5345
                'enabledashboard' => null,
-
 
5346
                'userpreference' => "/home",
-
 
5347
            ],
5303
        ];
5348
        ];
5304
    }
5349
    }
Línea 5305... Línea 5350...
5305
 
5350
 
5306
    /**
5351
    /**
Línea 5321... Línea 5366...
5321
        $default = get_default_home_page();
5366
        $default = get_default_home_page();
5322
        $this->assertEquals(HOMEPAGE_MYCOURSES, $default);
5367
        $this->assertEquals(HOMEPAGE_MYCOURSES, $default);
5323
    }
5368
    }
Línea 5324... Línea 5369...
5324
 
5369
 
-
 
5370
    /**
-
 
5371
     * Test getting default home page for {@see HOMEPAGE_URL}
-
 
5372
     *
-
 
5373
     * @covers ::get_default_home_page_url
-
 
5374
     */
-
 
5375
    public function test_get_default_home_page_url(): void {
-
 
5376
        global $CFG;
-
 
5377
 
-
 
5378
        $this->resetAfterTest();
-
 
5379
        $this->setAdminUser();
-
 
5380
 
-
 
5381
        $this->assertNull(get_default_home_page_url());
-
 
5382
 
-
 
5383
        // Site configuration.
-
 
5384
        $CFG->defaulthomepage = "/home";
-
 
5385
        $this->assertEquals("{$CFG->wwwroot}/home", get_default_home_page_url());
-
 
5386
 
-
 
5387
        // Site configuration with invalid value.
-
 
5388
        $CFG->defaulthomepage = "home";
-
 
5389
        $this->assertNull(get_default_home_page_url());
-
 
5390
 
-
 
5391
        // User preference.
-
 
5392
        $CFG->defaulthomepage = HOMEPAGE_USER;
-
 
5393
 
-
 
5394
        $userpreference = "/about";
-
 
5395
        set_user_preference('user_home_page_preference', $userpreference);
-
 
5396
        $this->assertEquals("{$CFG->wwwroot}/about", get_default_home_page_url());
-
 
5397
 
-
 
5398
        // User preference with invalid value.
-
 
5399
        set_user_preference('user_home_page_preference', "about");
-
 
5400
        $this->assertNull(get_default_home_page_url());
-
 
5401
    }
-
 
5402
 
5325
    /**
5403
    /**
5326
     * Tests the get_performance_info function with regard to locks.
5404
     * Tests the get_performance_info function with regard to locks.
5327
     *
5405
     *
5328
     * @covers ::get_performance_info
5406
     * @covers ::get_performance_info
5329
     */
5407
     */
Línea 5408... Línea 5486...
5408
    /**
5486
    /**
5409
     * Provider for is_proxybypass
5487
     * Provider for is_proxybypass
5410
     *
5488
     *
5411
     * @return array of test cases.
5489
     * @return array of test cases.
5412
     */
5490
     */
5413
    public function is_proxybypass_provider(): array {
5491
    public static function is_proxybypass_provider(): array {
Línea 5414... Línea 5492...
5414
 
5492
 
5415
        return [
5493
        return [
5416
            'Proxybypass contains the same IP as the beginning of the URL' => [
5494
            'Proxybypass contains the same IP as the beginning of the URL' => [
5417
                'http://192.168.5.5-fake-app-7f000101.nip.io',
5495
                'http://192.168.5.5-fake-app-7f000101.nip.io',
-
 
5496
                '192.168.5.5,127.0.0.1',
-
 
5497
                false,
-
 
5498
            ],
-
 
5499
            'Proxybypass contains some extra whitespaces (test with hostname)' => [
-
 
5500
                'store.mydomain.com',
-
 
5501
                'store.mydomain.com , 192.168.5.5',
-
 
5502
                false,
-
 
5503
            ],
-
 
5504
            'Proxybypass contains some extra whitespaces (test with IP)' => [
-
 
5505
                '192.168.5.5',
5418
                '192.168.5.5, 127.0.0.1',
5506
                'store.mydomain.com , 192.168.5.5',
5419
                false
5507
                false,
5420
            ],
5508
            ],
5421
            'Proxybypass contains the last part of the URL' => [
5509
            'Proxybypass contains the last part of the URL' => [
5422
                'http://192.168.5.5-fake-app-7f000101.nip.io',
5510
                'http://192.168.5.5-fake-app-7f000101.nip.io',
5423
                'app-7f000101.nip.io',
5511
                'app-7f000101.nip.io',
5424
                false
5512
                false,
5425
            ],
5513
            ],
5426
            'Proxybypass contains the last part of the URL 2' => [
5514
            'Proxybypass contains the last part of the URL 2' => [
5427
                'http://store.mydomain.com',
5515
                'http://store.mydomain.com',
5428
                'mydomain.com',
5516
                'mydomain.com',
5429
                false
5517
                false,
5430
            ],
5518
            ],
5431
            'Proxybypass contains part of the url' => [
5519
            'Proxybypass contains part of the url' => [
5432
                'http://myweb.com',
5520
                'http://myweb.com',
5433
                'store.myweb.com',
5521
                'store.myweb.com',
-
 
5522
                false,
-
 
5523
            ],
-
 
5524
            'Proxybypass with a wildcard contains part of the url' => [
-
 
5525
                'http://myweb.com',
-
 
5526
                '*.myweb.com',
5434
                false
5527
                false,
5435
            ],
5528
            ],
5436
            'Different IPs used in proxybypass' => [
5529
            'Different IPs used in proxybypass' => [
5437
                'http://192.168.5.5',
5530
                'http://192.168.5.5',
5438
                '192.168.5.3',
5531
                '192.168.5.3',
-
 
5532
                false,
-
 
5533
            ],
-
 
5534
            'Different partial IPs used in proxybypass' => [
-
 
5535
                'http://192.168.5.5',
-
 
5536
                '192.16',
-
 
5537
                false,
-
 
5538
            ],
-
 
5539
            'Different partial IPs used in proxybypass with ending dot' => [
-
 
5540
                'http://192.168.5.5',
-
 
5541
                '192.16.',
5439
                false
5542
                false,
5440
            ],
5543
            ],
5441
            'Proxybypass and URL matchs' => [
5544
            'Proxybypass and URL matchs' => [
5442
                'http://store.mydomain.com',
5545
                'http://store.mydomain.com',
5443
                'store.mydomain.com',
5546
                'store.mydomain.com',
-
 
5547
                true,
-
 
5548
            ],
-
 
5549
            'Proxybypass with a wildcard value covers any subdomain' => [
-
 
5550
                'http://store.mydomain.com',
-
 
5551
                '*.mydomain.com',
-
 
5552
                true,
-
 
5553
            ],
-
 
5554
            'Proxybypass with a wildcard value covers any higher level subdomain' => [
-
 
5555
                'http://another.store.mydomain.com',
-
 
5556
                '*.mydomain.com',
-
 
5557
                true,
-
 
5558
            ],
-
 
5559
            'Proxybypass with multiple domains' => [
-
 
5560
                'http://store.mydomain.com',
-
 
5561
                '127.0.0.1,*.mydomain.com',
5444
                true
5562
                true,
5445
            ],
5563
            ],
5446
            'IP used in proxybypass' => [
5564
            'IP used in proxybypass' => [
5447
                'http://192.168.5.5',
5565
                'http://192.168.5.5',
5448
                '192.168.5.5',
5566
                '192.168.5.5',
-
 
5567
                true,
-
 
5568
            ],
-
 
5569
            'Partial IP used in proxybypass' => [
-
 
5570
                'http://192.168.5.5',
-
 
5571
                '192.168.',
5449
                true
5572
                true,
5450
            ],
5573
            ],
5451
        ];
5574
        ];
Línea 5452... Línea 5575...
5452
    }
5575
    }
Línea 5551... Línea 5674...
5551
                true,
5674
                true,
5552
                ['one'],
5675
                ['one'],
5553
            ],
5676
            ],
5554
        ];
5677
        ];
5555
    }
5678
    }
-
 
5679
 
-
 
5680
    /**
-
 
5681
     * Test case for checking the email greetings in various user notification emails.
-
 
5682
     *
-
 
5683
     * @dataProvider email_greetings_provider
-
 
5684
     * @param string $funcname The name of the function to call for sending the email.
-
 
5685
     * @param mixed $extra Any extra parameter required by the function.
-
 
5686
     * @covers ::send_password_change_info()
-
 
5687
     * @covers ::send_confirmation_email()
-
 
5688
     * @covers ::setnew_password_and_mail()
-
 
5689
     * @covers ::send_password_change_confirmation_email()
-
 
5690
     */
-
 
5691
    public function test_email_greetings($funcname, $extra): void {
-
 
5692
        $this->resetAfterTest();
-
 
5693
 
-
 
5694
        $user = $this->getDataGenerator()->create_user();
-
 
5695
 
-
 
5696
        $sink = $this->redirectEmails(); // Make sure we are redirecting emails.
-
 
5697
        $funcname($user, $extra);
-
 
5698
        $result = $sink->get_messages();
-
 
5699
        $sink->close();
-
 
5700
        // Test greetings.
-
 
5701
        $this->assertStringContainsString('Hi ' . $user->firstname, quoted_printable_decode($result[0]->body));
-
 
5702
    }
-
 
5703
 
-
 
5704
    /**
-
 
5705
     * Data provider for test_email_greetings tests.
-
 
5706
     *
-
 
5707
     * @return array
-
 
5708
     */
-
 
5709
    public static function email_greetings_provider(): array {
-
 
5710
        $extrasendpasswordchangeconfirmationemail = new \stdClass();
-
 
5711
        $extrasendpasswordchangeconfirmationemail->token = '123';
-
 
5712
 
-
 
5713
        return [
-
 
5714
            ['send_password_change_info', null],
-
 
5715
            ['send_confirmation_email', null],
-
 
5716
            ['setnew_password_and_mail', false],
-
 
5717
            ['send_password_change_confirmation_email', $extrasendpasswordchangeconfirmationemail],
-
 
5718
        ];
-
 
5719
    }
-
 
5720
 
-
 
5721
    /**
-
 
5722
     * Test various moodlelib functions when dealing with a deprecated plugin type.
-
 
5723
     *
-
 
5724
     * @runInSeparateProcess
-
 
5725
     *
-
 
5726
     * @covers ::get_string_manager
-
 
5727
     * @covers ::component_callback_exists
-
 
5728
     * @covers ::component_callback
-
 
5729
     * @covers ::component_class_callback
-
 
5730
     * @covers ::get_plugins_with_function
-
 
5731
     * @covers ::get_plugin_list_with_function
-
 
5732
     * @return void
-
 
5733
     */
-
 
5734
    public function test_moodlelib_deprecated_plugintype(): void {
-
 
5735
        $this->resetAfterTest();
-
 
5736
        global $CFG;
-
 
5737
 
-
 
5738
        // Inject the 'fake' plugin type and deprecate it.
-
 
5739
        // Note: this method of injection is required to ensure core_component fully builds all caches from the ground up,
-
 
5740
        // which is necessary to test things like class autoloading, required for class callbacks checks.
-
 
5741
        $this->add_full_mocked_plugintype(
-
 
5742
            plugintype: 'fake',
-
 
5743
            path: 'lib/tests/fixtures/fakeplugins/fake',
-
 
5744
        );
-
 
5745
        $this->deprecate_full_mocked_plugintype('fake');
-
 
5746
 
-
 
5747
        // Verify strings can be fetched for deprecated plugins.
-
 
5748
        $stringman = get_string_manager();
-
 
5749
        $this->assertEquals('Fake full featured plugin', $stringman->get_string('pluginname', 'fake_fullfeatured'));
-
 
5750
 
-
 
5751
        // Verify callbacks are NOT supported for deprecated plugins (falling back to using the default return).
-
 
5752
        $this->assertFalse(component_callback_exists('fake_fullfeatured', 'test_callback'));
-
 
5753
        $this->assertEquals('default', component_callback('fake_fullfeatured', 'test_callback', [], 'default'));
-
 
5754
        $this->assertEquals('cat', component_class_callback(\fake_fullfeatured\dummy::class, 'class_callback_test', [], 'cat'));
-
 
5755
 
-
 
5756
        // Unset allversionshash to trigger a plugin functions rebuild, forcing it to pick up the injected mock plugin functions.
-
 
5757
        unset($CFG->allversionshash);
-
 
5758
        $plugins = get_plugins_with_function('test_callback');
-
 
5759
        $this->assertArrayNotHasKey('fake', $plugins);
-
 
5760
        $pluginlist = get_plugin_list_with_function('fake', 'test_callback');
-
 
5761
        $this->assertArrayNotHasKey('fake_fullfeatured', $pluginlist);
-
 
5762
    }
-
 
5763
 
-
 
5764
    /**
-
 
5765
     * Test various moodlelib functions when dealing with a deleted plugin type.
-
 
5766
     *
-
 
5767
     * @runInSeparateProcess
-
 
5768
     *
-
 
5769
     * @covers ::get_string_manager
-
 
5770
     * @covers ::component_callback_exists
-
 
5771
     * @covers ::component_callback
-
 
5772
     * @covers ::component_class_callback
-
 
5773
     * @covers ::get_plugins_with_function
-
 
5774
     * @covers ::get_plugin_list_with_function
-
 
5775
     * @return void
-
 
5776
     */
-
 
5777
    public function test_moodlelib_deleted_plugintype(): void {
-
 
5778
        $this->resetAfterTest();
-
 
5779
        global $CFG;
-
 
5780
 
-
 
5781
        // Inject the 'fake' plugin type and flag it as deleted.
-
 
5782
        // Note: this deep method of injection is required to ensure core_component fully builds all caches from the ground up,
-
 
5783
        // which is necessary to test things like class autoloading, required for class callbacks checks.
-
 
5784
        $this->add_full_mocked_plugintype(
-
 
5785
            plugintype: 'fake',
-
 
5786
            path: 'lib/tests/fixtures/fakeplugins/fake',
-
 
5787
        );
-
 
5788
        $this->delete_full_mocked_plugintype('fake');
-
 
5789
 
-
 
5790
        // Verify no string support for deleted plugins.
-
 
5791
        $stringman = get_string_manager();
-
 
5792
        $this->assertEquals('[[pluginname]]', $stringman->get_string('pluginname', 'fake_fullfeatured'));
-
 
5793
        $this->assertDebuggingCalled();
-
 
5794
 
-
 
5795
        // Verify callbacks are NOT supported for deleted plugins (falling back to using the default return).
-
 
5796
        $this->assertFalse(component_callback_exists('fake_fullfeatured', 'test_callback'));
-
 
5797
        $this->assertEquals('default', component_callback('fake_fullfeatured', 'test_callback', [], 'default'));
-
 
5798
        $this->assertEquals('default',
-
 
5799
            component_class_callback(\fake_fullfeatured\dummy::class, 'class_callback_test', [], 'default'));
-
 
5800
 
-
 
5801
        // Unset allversionshash to trigger a plugin functions rebuild, forcing it to pick up the injected mock plugin functions.
-
 
5802
        unset($CFG->allversionshash);
-
 
5803
        $plugins = get_plugins_with_function('test_callback');
-
 
5804
        $this->assertArrayNotHasKey('fake', $plugins);
-
 
5805
        $pluginlist = get_plugin_list_with_function('fake', 'test_callback');
-
 
5806
        $this->assertArrayNotHasKey('fake_fullfeatured', $pluginlist);
-
 
5807
    }
5556
}
5808
}