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 fields_test extends \advanced_testcase {
27
class fields_test extends \advanced_testcase {
Línea 28... Línea 28...
28
 
28
 
29
    /**
29
    /**
30
     * Tests getting the user picture fields.
30
     * Tests getting the user picture fields.
31
     */
31
     */
32
    public function test_get_picture_fields() {
32
    public function test_get_picture_fields(): void {
33
        $this->assertEquals(['id', 'picture', 'firstname', 'lastname', 'firstnamephonetic',
33
        $this->assertEquals(['id', 'picture', 'firstname', 'lastname', 'firstnamephonetic',
34
                'lastnamephonetic', 'middlename', 'alternatename', 'imagealt', 'email'],
34
                'lastnamephonetic', 'middlename', 'alternatename', 'imagealt', 'email'],
35
                fields::get_picture_fields());
35
                fields::get_picture_fields());
Línea 36... Línea 36...
36
    }
36
    }
37
 
37
 
38
    /**
38
    /**
39
     * Tests getting the user name fields.
39
     * Tests getting the user name fields.
40
     */
40
     */
41
    public function test_get_name_fields() {
41
    public function test_get_name_fields(): void {
42
        $this->assertEquals(['firstnamephonetic', 'lastnamephonetic', 'middlename', 'alternatename',
42
        $this->assertEquals(['firstnamephonetic', 'lastnamephonetic', 'middlename', 'alternatename',
Línea 43... Línea 43...
43
                'firstname', 'lastname'],
43
                'firstname', 'lastname'],
Línea 49... Línea 49...
49
    }
49
    }
Línea 50... Línea 50...
50
 
50
 
51
    /**
51
    /**
52
     * Tests getting the identity fields.
52
     * Tests getting the identity fields.
53
     */
53
     */
54
    public function test_get_identity_fields() {
54
    public function test_get_identity_fields(): void {
Línea 55... Línea 55...
55
        global $DB, $CFG, $COURSE;
55
        global $DB, $CFG, $COURSE;
Línea 56... Línea 56...
56
 
56
 
Línea 180... Línea 180...
180
     *
180
     *
181
     * This function composes the results of get_identity/name/picture_fields, so we are not going
181
     * This function composes the results of get_identity/name/picture_fields, so we are not going
182
     * to test the details of the identity permissions as that was already covered. Just how they
182
     * to test the details of the identity permissions as that was already covered. Just how they
183
     * are included/combined.
183
     * are included/combined.
184
     */
184
     */
185
    public function test_get_required_fields() {
185
    public function test_get_required_fields(): void {
186
        $this->resetAfterTest();
186
        $this->resetAfterTest();
Línea 187... Línea 187...
187
 
187
 
188
        // Set up some profile fields.
188
        // Set up some profile fields.
189
        $generator = self::getDataGenerator();
189
        $generator = self::getDataGenerator();
Línea 230... Línea 230...
230
    }
230
    }
Línea 231... Línea 231...
231
 
231
 
232
    /**
232
    /**
233
     * Tests the get_required_fields function when you use the $limitpurposes parameter.
233
     * Tests the get_required_fields function when you use the $limitpurposes parameter.
234
     */
234
     */
235
    public function test_get_required_fields_limitpurposes() {
235
    public function test_get_required_fields_limitpurposes(): void {
Línea 236... Línea 236...
236
        $this->resetAfterTest();
236
        $this->resetAfterTest();
237
 
237
 
238
        // Set up some profile fields.
238
        // Set up some profile fields.
Línea 262... Línea 262...
262
    }
262
    }
Línea 263... Línea 263...
263
 
263
 
264
    /**
264
    /**
265
     * There should be an exception if you try to 'limit' purposes to one that wasn't even included.
265
     * There should be an exception if you try to 'limit' purposes to one that wasn't even included.
266
     */
266
     */
267
    public function test_get_required_fields_limitpurposes_not_in_constructor() {
267
    public function test_get_required_fields_limitpurposes_not_in_constructor(): void {
268
        $fields = fields::for_identity(null);
268
        $fields = fields::for_identity(null);
269
        $this->expectExceptionMessage('$limitpurposes can only include purposes defined in object');
269
        $this->expectExceptionMessage('$limitpurposes can only include purposes defined in object');
270
        $fields->get_required_fields([fields::PURPOSE_USERPIC]);
270
        $fields->get_required_fields([fields::PURPOSE_USERPIC]);
Línea 294... Línea 294...
294
    }
294
    }
Línea 295... Línea 295...
295
 
295
 
296
    /**
296
    /**
297
     * Tests getting SQL (and actually using it).
297
     * Tests getting SQL (and actually using it).
298
     */
298
     */
299
    public function test_get_sql_variations() {
299
    public function test_get_sql_variations(): void {
300
        global $DB;
300
        global $DB;
Línea 301... Línea 301...
301
        $this->resetAfterTest();
301
        $this->resetAfterTest();
302
 
302
 
Línea 444... Línea 444...
444
 
444
 
445
    /**
445
    /**
446
     * Tests what happens if you use the SQL multiple times in a query (i.e. that it correctly
446
     * Tests what happens if you use the SQL multiple times in a query (i.e. that it correctly
447
     * creates the different identifiers).
447
     * creates the different identifiers).
448
     */
448
     */
449
    public function test_get_sql_multiple() {
449
    public function test_get_sql_multiple(): void {
450
        global $DB;
450
        global $DB;
Línea 451... Línea 451...
451
        $this->resetAfterTest();
451
        $this->resetAfterTest();
Línea 484... Línea 484...
484
    }
484
    }
Línea 485... Línea 485...
485
 
485
 
486
    /**
486
    /**
487
     * Tests the get_sql function when there are no fields to retrieve.
487
     * Tests the get_sql function when there are no fields to retrieve.
488
     */
488
     */
489
    public function test_get_sql_nothing() {
489
    public function test_get_sql_nothing(): void {
490
        $fields = fields::empty();
490
        $fields = fields::empty();
491
        ['selects' => $selects, 'joins' => $joins, 'params' => $joinparams] = (array)$fields->get_sql();
491
        ['selects' => $selects, 'joins' => $joins, 'params' => $joinparams] = (array)$fields->get_sql();
492
        $this->assertEquals('', $selects);
492
        $this->assertEquals('', $selects);
493
        $this->assertEquals('', $joins);
493
        $this->assertEquals('', $joins);
Línea 496... Línea 496...
496
 
496
 
497
    /**
497
    /**
498
     * Tests get_sql when there are no custom fields; in this scenario, the joins and joinparams
498
     * Tests get_sql when there are no custom fields; in this scenario, the joins and joinparams
499
     * are always blank.
499
     * are always blank.
500
     */
500
     */
501
    public function test_get_sql_no_custom_fields() {
501
    public function test_get_sql_no_custom_fields(): void {
502
        $fields = fields::empty()->including('city', 'country');
502
        $fields = fields::empty()->including('city', 'country');
503
        ['selects' => $selects, 'joins' => $joins, 'params' => $joinparams, 'mappings' => $mappings] =
503
        ['selects' => $selects, 'joins' => $joins, 'params' => $joinparams, 'mappings' => $mappings] =
504
                (array)$fields->get_sql('u');
504
                (array)$fields->get_sql('u');
505
        $this->assertEquals(', u.city, u.country', $selects);
505
        $this->assertEquals(', u.city, u.country', $selects);
Línea 510... Línea 510...
510
 
510
 
511
    /**
511
    /**
512
     * Tests the format of the $selects string, which is important particularly for backward
512
     * Tests the format of the $selects string, which is important particularly for backward
513
     * compatibility.
513
     * compatibility.
514
     */
514
     */
515
    public function test_get_sql_selects_format() {
515
    public function test_get_sql_selects_format(): void {
Línea 516... Línea 516...
516
        global $DB;
516
        global $DB;
517
 
517