Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 26... Línea 26...
26
 * @author     Andrew Nicols
26
 * @author     Andrew Nicols
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
28
 */
29
class grouplib_test extends \advanced_testcase {
29
class grouplib_test extends \advanced_testcase {
Línea 30... Línea 30...
30
 
30
 
31
    public function test_groups_get_group_by_idnumber() {
31
    public function test_groups_get_group_by_idnumber(): void {
Línea 32... Línea 32...
32
        $this->resetAfterTest(true);
32
        $this->resetAfterTest(true);
Línea 33... Línea 33...
33
 
33
 
Línea 98... Línea 98...
98
 
98
 
99
        $group = $generator->create_group(array('courseid' => $course->id, 'idnumber' => $idnumber2));
99
        $group = $generator->create_group(array('courseid' => $course->id, 'idnumber' => $idnumber2));
100
        $this->assertEquals($group, groups_get_group_by_idnumber($course->id, $idnumber2));
100
        $this->assertEquals($group, groups_get_group_by_idnumber($course->id, $idnumber2));
Línea 101... Línea 101...
101
    }
101
    }
102
 
102
 
Línea 103... Línea 103...
103
    public function test_groups_get_grouping_by_idnumber() {
103
    public function test_groups_get_grouping_by_idnumber(): void {
Línea 104... Línea 104...
104
        $this->resetAfterTest(true);
104
        $this->resetAfterTest(true);
Línea 170... Línea 170...
170
 
170
 
171
        $grouping = $generator->create_grouping(array('courseid' => $course->id, 'idnumber' => $idnumber2));
171
        $grouping = $generator->create_grouping(array('courseid' => $course->id, 'idnumber' => $idnumber2));
172
        $this->assertEquals($grouping, groups_get_grouping_by_idnumber($course->id, $idnumber2));
172
        $this->assertEquals($grouping, groups_get_grouping_by_idnumber($course->id, $idnumber2));
Línea 173... Línea 173...
173
    }
173
    }
174
 
174
 
Línea 175... Línea 175...
175
    public function test_groups_get_members_ids_sql() {
175
    public function test_groups_get_members_ids_sql(): void {
Línea 176... Línea 176...
176
        global $DB;
176
        global $DB;
Línea 207... Línea 207...
207
        groups_add_member($group->id, $student1->id);
207
        groups_add_member($group->id, $student1->id);
208
        $users = $DB->get_records_sql($sql, $params);
208
        $users = $DB->get_records_sql($sql, $params);
209
        $this->assertTrue(array_key_exists($student1->id, $users));
209
        $this->assertTrue(array_key_exists($student1->id, $users));
210
    }
210
    }
Línea 211... Línea 211...
211
 
211
 
212
    public function test_groups_get_members_ids_sql_multiple_groups() {
212
    public function test_groups_get_members_ids_sql_multiple_groups(): void {
Línea 213... Línea 213...
213
        global $DB;
213
        global $DB;
Línea 214... Línea 214...
214
 
214
 
Línea 254... Línea 254...
254
        $users = $DB->get_records_sql($sql, $params);
254
        $users = $DB->get_records_sql($sql, $params);
255
        $this->assertTrue(array_key_exists($student1->id, $users));
255
        $this->assertTrue(array_key_exists($student1->id, $users));
256
        $this->assertTrue(array_key_exists($student2->id, $users));
256
        $this->assertTrue(array_key_exists($student2->id, $users));
257
    }
257
    }
Línea 258... Línea 258...
258
 
258
 
259
    public function test_groups_get_members_ids_sql_multiple_groups_join_types() {
259
    public function test_groups_get_members_ids_sql_multiple_groups_join_types(): void {
Línea 260... Línea 260...
260
        global $DB;
260
        global $DB;
Línea 261... Línea 261...
261
 
261
 
Línea 362... Línea 362...
362
        $this->assertFalse(array_key_exists($student2->id, $users));
362
        $this->assertFalse(array_key_exists($student2->id, $users));
363
        $this->assertFalse(array_key_exists($student3->id, $users));
363
        $this->assertFalse(array_key_exists($student3->id, $users));
364
        $this->assertFalse(array_key_exists($student4->id, $users));
364
        $this->assertFalse(array_key_exists($student4->id, $users));
365
    }
365
    }
Línea 366... Línea 366...
366
 
366
 
367
    public function test_groups_get_members_ids_sql_valid_context() {
367
    public function test_groups_get_members_ids_sql_valid_context(): void {
Línea 368... Línea 368...
368
        global $DB;
368
        global $DB;
Línea 369... Línea 369...
369
 
369
 
Línea 397... Línea 397...
397
        $users = $DB->get_records_sql($sql, $params);
397
        $users = $DB->get_records_sql($sql, $params);
398
        $this->assertFalse(array_key_exists($student1->id, $users));
398
        $this->assertFalse(array_key_exists($student1->id, $users));
399
        $this->assertTrue(array_key_exists($student2->id, $users));
399
        $this->assertTrue(array_key_exists($student2->id, $users));
400
    }
400
    }
Línea 401... Línea 401...
401
 
401
 
402
    public function test_groups_get_members_ids_sql_empty_context() {
402
    public function test_groups_get_members_ids_sql_empty_context(): void {
Línea 403... Línea 403...
403
        global $DB;
403
        global $DB;
Línea 404... Línea 404...
404
 
404
 
Línea 430... Línea 430...
430
        // Test with members at any group and without the $context.
430
        // Test with members at any group and without the $context.
431
        $this->expectException('coding_exception');
431
        $this->expectException('coding_exception');
432
        list($sql, $params) = groups_get_members_ids_sql(USERSWITHOUTGROUP);
432
        list($sql, $params) = groups_get_members_ids_sql(USERSWITHOUTGROUP);
433
    }
433
    }
Línea 434... Línea 434...
434
 
434
 
435
    public function test_groups_get_members_ids_sql_invalid_context() {
435
    public function test_groups_get_members_ids_sql_invalid_context(): void {
Línea 436... Línea 436...
436
        global $DB;
436
        global $DB;
Línea 437... Línea 437...
437
 
437
 
Línea 502... Línea 502...
502
                'groupnames' => $group1->name,
502
                'groupnames' => $group1->name,
503
            ],
503
            ],
504
        ], $records);
504
        ], $records);
505
    }
505
    }
Línea 506... Línea 506...
506
 
506
 
507
    public function test_groups_get_group_by_name() {
507
    public function test_groups_get_group_by_name(): void {
Línea 508... Línea 508...
508
        $this->resetAfterTest(true);
508
        $this->resetAfterTest(true);
Línea 509... Línea 509...
509
 
509
 
Línea 566... Línea 566...
566
 
566
 
567
        $group2 = $generator->create_group(array('courseid' => $course->id, 'name' => $name2));
567
        $group2 = $generator->create_group(array('courseid' => $course->id, 'name' => $name2));
568
        $this->assertEquals($group2->id, groups_get_group_by_name($course->id, $name2));
568
        $this->assertEquals($group2->id, groups_get_group_by_name($course->id, $name2));
Línea 569... Línea 569...
569
    }
569
    }
570
 
570
 
Línea 571... Línea 571...
571
    public function test_groups_get_grouping() {
571
    public function test_groups_get_grouping(): void {
Línea 572... Línea 572...
572
        $this->resetAfterTest(true);
572
        $this->resetAfterTest(true);
Línea 630... Línea 630...
630
 
630
 
631
        $group2 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name2));
631
        $group2 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name2));
632
        $this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
632
        $this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
Línea 633... Línea 633...
633
    }
633
    }
634
 
634
 
Línea 635... Línea 635...
635
    public function test_groups_get_course_data() {
635
    public function test_groups_get_course_data(): void {
Línea 636... Línea 636...
636
        $this->resetAfterTest(true);
636
        $this->resetAfterTest(true);
Línea 743... Línea 743...
743
    }
743
    }
Línea 744... Línea 744...
744
 
744
 
745
    /**
745
    /**
746
     * Tests for groups_group_visible.
746
     * Tests for groups_group_visible.
747
     */
747
     */
748
    public function test_groups_group_visible() {
748
    public function test_groups_group_visible(): void {
Línea 749... Línea 749...
749
        global $CFG, $DB;
749
        global $CFG, $DB;
750
 
750
 
751
        $generator = $this->getDataGenerator();
751
        $generator = $this->getDataGenerator();
Línea 927... Línea 927...
927
        $cm->groupmode = VISIBLEGROUPS;
927
        $cm->groupmode = VISIBLEGROUPS;
928
        $result = groups_group_visible($group1->id, $course, $cm, $user1->id);
928
        $result = groups_group_visible($group1->id, $course, $cm, $user1->id);
929
        $this->assertTrue($result); // Cm with visible groups.
929
        $this->assertTrue($result); // Cm with visible groups.
930
    }
930
    }
Línea 931... Línea 931...
931
 
931
 
932
    function test_groups_get_groupmode() {
932
    function test_groups_get_groupmode(): void {
933
        global $DB;
933
        global $DB;
934
        $generator = $this->getDataGenerator();
934
        $generator = $this->getDataGenerator();
935
        $this->resetAfterTest();
935
        $this->resetAfterTest();
Línea 998... Línea 998...
998
    }
998
    }
Línea 999... Línea 999...
999
 
999
 
1000
    /**
1000
    /**
1001
     * Tests for groups_allgroups_course_menu() .
1001
     * Tests for groups_allgroups_course_menu() .
1002
     */
1002
     */
1003
    public function test_groups_allgroups_course_menu() {
1003
    public function test_groups_allgroups_course_menu(): void {
Línea 1004... Línea 1004...
1004
        global $SESSION;
1004
        global $SESSION;
Línea 1005... Línea 1005...
1005
 
1005
 
Línea 1062... Línea 1062...
1062
 
1062
 
1063
    /**
1063
    /**
1064
     * This unit test checks that groups_get_all_groups returns groups in
1064
     * This unit test checks that groups_get_all_groups returns groups in
1065
     * alphabetical order even if they are in a grouping.
1065
     * alphabetical order even if they are in a grouping.
1066
     */
1066
     */
1067
    public function test_groups_ordering() {
1067
    public function test_groups_ordering(): void {
1068
        $generator = $this->getDataGenerator();
1068
        $generator = $this->getDataGenerator();
Línea 1069... Línea 1069...
1069
        $this->resetAfterTest();
1069
        $this->resetAfterTest();
1070
 
1070
 
Línea 1093... Línea 1093...
1093
    }
1093
    }
Línea 1094... Línea 1094...
1094
 
1094
 
1095
    /**
1095
    /**
1096
     * Tests for groups_get_all_groups when grouping is set and we want members as well.
1096
     * Tests for groups_get_all_groups when grouping is set and we want members as well.
1097
     */
1097
     */
1098
    public function test_groups_get_all_groups_in_grouping_with_members() {
1098
    public function test_groups_get_all_groups_in_grouping_with_members(): void {
1099
        $generator = $this->getDataGenerator();
1099
        $generator = $this->getDataGenerator();
Línea 1100... Línea 1100...
1100
        $this->resetAfterTest();
1100
        $this->resetAfterTest();
1101
 
1101
 
Línea 1163... Línea 1163...
1163
    }
1163
    }
Línea 1164... Línea 1164...
1164
 
1164
 
1165
    /**
1165
    /**
1166
     * Tests for groups_get_user_groups() method.
1166
     * Tests for groups_get_user_groups() method.
1167
     */
1167
     */
1168
    public function test_groups_get_user_groups() {
1168
    public function test_groups_get_user_groups(): void {
1169
        $this->resetAfterTest(true);
1169
        $this->resetAfterTest(true);
Línea 1170... Línea 1170...
1170
        $generator = $this->getDataGenerator();
1170
        $generator = $this->getDataGenerator();
1171
 
1171
 
Línea 1247... Línea 1247...
1247
            $testgroups[$grp->id] = $grp;
1247
            $testgroups[$grp->id] = $grp;
1248
        }
1248
        }
1249
        return $testgroups;
1249
        return $testgroups;
1250
    }
1250
    }
Línea 1251... Línea 1251...
1251
 
1251
 
1252
    public function test_groups_sort_menu_options_empty() {
1252
    public function test_groups_sort_menu_options_empty(): void {
1253
        $this->assertEquals(array(), groups_sort_menu_options(array(), array()));
1253
        $this->assertEquals(array(), groups_sort_menu_options(array(), array()));
Línea 1254... Línea 1254...
1254
    }
1254
    }
1255
 
1255
 
1256
    public function test_groups_sort_menu_options_allowed_goups_only() {
1256
    public function test_groups_sort_menu_options_allowed_goups_only(): void {
1257
        $this->assertEquals(array(
1257
        $this->assertEquals(array(
1258
            100 => 'test group 100',
1258
            100 => 'test group 100',
1259
            101 => 'test group 101',
1259
            101 => 'test group 101',
Línea 1260... Línea 1260...
1260
        ), groups_sort_menu_options($this->make_group_list(2), array()));
1260
        ), groups_sort_menu_options($this->make_group_list(2), array()));
1261
    }
1261
    }
1262
 
1262
 
1263
    public function test_groups_sort_menu_options_user_goups_only() {
1263
    public function test_groups_sort_menu_options_user_goups_only(): void {
1264
        $this->assertEquals(array(
1264
        $this->assertEquals(array(
1265
            100 => 'test group 100',
1265
            100 => 'test group 100',
Línea 1266... Línea 1266...
1266
            101 => 'test group 101',
1266
            101 => 'test group 101',
1267
        ), groups_sort_menu_options(array(), $this->make_group_list(2)));
1267
        ), groups_sort_menu_options(array(), $this->make_group_list(2)));
1268
    }
1268
    }
1269
 
1269
 
1270
    public function test_groups_sort_menu_options_user_both() {
1270
    public function test_groups_sort_menu_options_user_both(): void {
1271
        $this->assertEquals(array(
1271
        $this->assertEquals(array(
Línea 1278... Línea 1278...
1278
                103 => 'test group 103',
1278
                103 => 'test group 103',
1279
            )),
1279
            )),
1280
        ), groups_sort_menu_options($this->make_group_list(4), $this->make_group_list(2)));
1280
        ), groups_sort_menu_options($this->make_group_list(4), $this->make_group_list(2)));
1281
    }
1281
    }
Línea 1282... Línea 1282...
1282
 
1282
 
1283
    public function test_groups_sort_menu_options_user_both_many_groups() {
1283
    public function test_groups_sort_menu_options_user_both_many_groups(): void {
1284
        $this->assertEquals(array(
1284
        $this->assertEquals(array(
1285
            1 => array(get_string('mygroups', 'group') => array(
1285
            1 => array(get_string('mygroups', 'group') => array(
1286
                100 => 'test group 100',
1286
                100 => 'test group 100',
1287
                101 => 'test group 101',
1287
                101 => 'test group 101',
Línea 1303... Línea 1303...
1303
    }
1303
    }
Línea 1304... Línea 1304...
1304
 
1304
 
1305
    /**
1305
    /**
1306
     * Tests for groups_user_groups_visible.
1306
     * Tests for groups_user_groups_visible.
1307
     */
1307
     */
1308
    public function test_groups_user_groups_visible() {
1308
    public function test_groups_user_groups_visible(): void {
Línea 1309... Línea 1309...
1309
        global $DB;
1309
        global $DB;
1310
 
1310
 
1311
        $generator = $this->getDataGenerator();
1311
        $generator = $this->getDataGenerator();
Línea 1756... Línea 1756...
1756
    /**
1756
    /**
1757
     * Tests for groups_get_groups_members() method.
1757
     * Tests for groups_get_groups_members() method.
1758
     *
1758
     *
1759
     * @covers ::groups_get_groups_members
1759
     * @covers ::groups_get_groups_members
1760
     */
1760
     */
1761
    public function test_groups_get_groups_members() {
1761
    public function test_groups_get_groups_members(): void {
1762
        $this->resetAfterTest(true);
1762
        $this->resetAfterTest(true);
1763
        $generator = $this->getDataGenerator();
1763
        $generator = $this->getDataGenerator();
Línea 1764... Línea 1764...
1764
 
1764
 
1765
        // Create courses.
1765
        // Create courses.
Línea 1837... Línea 1837...
1837
    }
1837
    }
Línea 1838... Línea 1838...
1838
 
1838
 
1839
    /**
1839
    /**
1840
     * Tests for groups_get_activity_shared_group_members() method.
1840
     * Tests for groups_get_activity_shared_group_members() method.
1841
     */
1841
     */
1842
    public function test_groups_get_activity_shared_group_members() {
1842
    public function test_groups_get_activity_shared_group_members(): void {
1843
        $this->resetAfterTest(true);
1843
        $this->resetAfterTest(true);
Línea 1844... Línea 1844...
1844
        $generator = $this->getDataGenerator();
1844
        $generator = $this->getDataGenerator();
1845
 
1845
 
Línea 1961... Línea 1961...
1961
     *
1961
     *
1962
     * This also covers the groupdata cache, since calls without $withmembers = true use the cache.
1962
     * This also covers the groupdata cache, since calls without $withmembers = true use the cache.
1963
     *
1963
     *
1964
     * @covers \groups_get_all_groups()
1964
     * @covers \groups_get_all_groups()
1965
     */
1965
     */
1966
    public function test_get_all_groups_with_visibility() {
1966
    public function test_get_all_groups_with_visibility(): void {
1967
        list($users, $groups, $course) = $this->create_groups_with_visibilty();
1967
        list($users, $groups, $course) = $this->create_groups_with_visibilty();
Línea 1968... Línea 1968...
1968
 
1968
 
1969
        // Assign users to groups.
1969
        // Assign users to groups.
1970
        $generator = $this->getDataGenerator();
1970
        $generator = $this->getDataGenerator();
Línea 2048... Línea 2048...
2048
    /**
2048
    /**
2049
     * Tests getting groups the current user is a member of, with visibility settings applied.
2049
     * Tests getting groups the current user is a member of, with visibility settings applied.
2050
     *
2050
     *
2051
     * @covers \groups_get_my_groups()
2051
     * @covers \groups_get_my_groups()
2052
     */
2052
     */
2053
    public function test_get_my_groups_with_visibility() {
2053
    public function test_get_my_groups_with_visibility(): void {
2054
        list($users, $groups) = $this->create_groups_with_visibilty();
2054
        list($users, $groups) = $this->create_groups_with_visibilty();
Línea 2055... Línea 2055...
2055
 
2055
 
2056
        // Assign users to groups.
2056
        // Assign users to groups.
2057
        $generator = $this->getDataGenerator();
2057
        $generator = $this->getDataGenerator();
Línea 2089... Línea 2089...
2089
    /**
2089
    /**
2090
     * Tests getting groups a user is a member of, with visibility settings applied.
2090
     * Tests getting groups a user is a member of, with visibility settings applied.
2091
     *
2091
     *
2092
     * @covers \groups_get_user_groups()
2092
     * @covers \groups_get_user_groups()
2093
     */
2093
     */
2094
    public function test_get_user_groups_with_visibility() {
2094
    public function test_get_user_groups_with_visibility(): void {
2095
        list($users, $groups, $course) = $this->create_groups_with_visibilty();
2095
        list($users, $groups, $course) = $this->create_groups_with_visibilty();
Línea 2096... Línea 2096...
2096
 
2096
 
2097
        // Assign users to groups.
2097
        // Assign users to groups.
2098
        $generator = $this->getDataGenerator();
2098
        $generator = $this->getDataGenerator();