Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 51... Línea 51...
51
        $this->userassignover = $this->getDataGenerator()->create_user();
51
        $this->userassignover = $this->getDataGenerator()->create_user();
52
        $this->roleid = create_role('Sausage Roll', 'sausageroll', 'mmmm');
52
        $this->roleid = create_role('Sausage Roll', 'sausageroll', 'mmmm');
53
        cohort_add_member($this->cohort->id, $this->userassignover->id);
53
        cohort_add_member($this->cohort->id, $this->userassignover->id);
54
    }
54
    }
Línea 55... Línea 55...
55
 
55
 
56
    public function test_create_cohort_role_assignment_without_permission() {
56
    public function test_create_cohort_role_assignment_without_permission(): void {
57
        $this->setUser($this->userassignto);
57
        $this->setUser($this->userassignto);
58
        $params = (object) array(
58
        $params = (object) array(
59
            'userid' => $this->userassignto->id,
59
            'userid' => $this->userassignto->id,
60
            'roleid' => $this->roleid,
60
            'roleid' => $this->roleid,
61
            'cohortid' => $this->cohort->id
61
            'cohortid' => $this->cohort->id
62
        );
62
        );
63
        $this->expectException(\required_capability_exception::class);
63
        $this->expectException(\required_capability_exception::class);
64
        api::create_cohort_role_assignment($params);
64
        api::create_cohort_role_assignment($params);
Línea 65... Línea 65...
65
    }
65
    }
66
 
66
 
67
    public function test_create_cohort_role_assignment_with_invalid_data() {
67
    public function test_create_cohort_role_assignment_with_invalid_data(): void {
68
        $this->setAdminUser();
68
        $this->setAdminUser();
69
        $params = (object) array(
69
        $params = (object) array(
70
            'userid' => $this->userassignto->id,
70
            'userid' => $this->userassignto->id,
71
            'roleid' => -8,
71
            'roleid' => -8,
72
            'cohortid' => $this->cohort->id
72
            'cohortid' => $this->cohort->id
73
        );
73
        );
74
        $this->expectException(\core_competency\invalid_persistent_exception::class);
74
        $this->expectException(\core_competency\invalid_persistent_exception::class);
Línea 75... Línea 75...
75
        api::create_cohort_role_assignment($params);
75
        api::create_cohort_role_assignment($params);
76
    }
76
    }
77
 
77
 
78
    public function test_create_cohort_role_assignment() {
78
    public function test_create_cohort_role_assignment(): void {
79
        $this->setAdminUser();
79
        $this->setAdminUser();
80
        $params = (object) array(
80
        $params = (object) array(
Línea 87... Línea 87...
87
        $this->assertEquals($result->get('userid'), $this->userassignto->id);
87
        $this->assertEquals($result->get('userid'), $this->userassignto->id);
88
        $this->assertEquals($result->get('roleid'), $this->roleid);
88
        $this->assertEquals($result->get('roleid'), $this->roleid);
89
        $this->assertEquals($result->get('cohortid'), $this->cohort->id);
89
        $this->assertEquals($result->get('cohortid'), $this->cohort->id);
90
    }
90
    }
Línea 91... Línea 91...
91
 
91
 
92
    public function test_delete_cohort_role_assignment_without_permission() {
92
    public function test_delete_cohort_role_assignment_without_permission(): void {
93
        $this->setAdminUser();
93
        $this->setAdminUser();
94
        $params = (object) array(
94
        $params = (object) array(
95
            'userid' => $this->userassignto->id,
95
            'userid' => $this->userassignto->id,
96
            'roleid' => $this->roleid,
96
            'roleid' => $this->roleid,
Línea 100... Línea 100...
100
        $this->setUser($this->userassignto);
100
        $this->setUser($this->userassignto);
101
        $this->expectException(\required_capability_exception::class);
101
        $this->expectException(\required_capability_exception::class);
102
        api::delete_cohort_role_assignment($result->get('id'));
102
        api::delete_cohort_role_assignment($result->get('id'));
103
    }
103
    }
Línea 104... Línea 104...
104
 
104
 
105
    public function test_delete_cohort_role_assignment_with_invalid_data() {
105
    public function test_delete_cohort_role_assignment_with_invalid_data(): void {
106
        $this->setAdminUser();
106
        $this->setAdminUser();
107
        $params = (object) array(
107
        $params = (object) array(
108
            'userid' => $this->userassignto->id,
108
            'userid' => $this->userassignto->id,
109
            'roleid' => $this->roleid,
109
            'roleid' => $this->roleid,
Línea 112... Línea 112...
112
        $result = api::create_cohort_role_assignment($params);
112
        $result = api::create_cohort_role_assignment($params);
113
        $this->expectException(\dml_missing_record_exception::class);
113
        $this->expectException(\dml_missing_record_exception::class);
114
        api::delete_cohort_role_assignment($result->get('id') + 1);
114
        api::delete_cohort_role_assignment($result->get('id') + 1);
115
    }
115
    }
Línea 116... Línea 116...
116
 
116
 
117
    public function test_delete_cohort_role_assignment() {
117
    public function test_delete_cohort_role_assignment(): void {
118
        $this->setAdminUser();
118
        $this->setAdminUser();
119
        // Create a cohort role assigment.
119
        // Create a cohort role assigment.
120
        $params = (object) [
120
        $params = (object) [
121
            'userid' => $this->userassignto->id,
121
            'userid' => $this->userassignto->id,
Línea 149... Línea 149...
149
    }
149
    }
Línea 150... Línea 150...
150
 
150
 
151
    /**
151
    /**
152
     * Test case verifying that syncing won't remove role assignments if they are valid for another cohort role assignment.
152
     * Test case verifying that syncing won't remove role assignments if they are valid for another cohort role assignment.
153
     */
153
     */
154
    public function test_delete_cohort_role_assignment_cohorts_having_same_members() {
154
    public function test_delete_cohort_role_assignment_cohorts_having_same_members(): void {
Línea 155... Línea 155...
155
        $this->setAdminUser();
155
        $this->setAdminUser();
156
 
156
 
157
        // Create 2 cohorts, with a 1 user (user1) present in both,
157
        // Create 2 cohorts, with a 1 user (user1) present in both,
Línea 201... Línea 201...
201
        $this->assertCount(1, $sync['rolesremoved']);
201
        $this->assertCount(1, $sync['rolesremoved']);
202
        $removedusers = array_column($sync['rolesremoved'], 'useridassignedover');
202
        $removedusers = array_column($sync['rolesremoved'], 'useridassignedover');
203
        $this->assertContains($user2->id, $removedusers);
203
        $this->assertContains($user2->id, $removedusers);
204
    }
204
    }
Línea 205... Línea 205...
205
 
205
 
206
    public function test_list_cohort_role_assignments() {
206
    public function test_list_cohort_role_assignments(): void {
207
        $this->setAdminUser();
207
        $this->setAdminUser();
208
        $params = (object) array(
208
        $params = (object) array(
209
            'userid' => $this->userassignto->id,
209
            'userid' => $this->userassignto->id,
210
            'roleid' => $this->roleid,
210
            'roleid' => $this->roleid,
Línea 215... Línea 215...
215
        $list = api::list_cohort_role_assignments();
215
        $list = api::list_cohort_role_assignments();
216
        $list[0]->is_valid();
216
        $list[0]->is_valid();
217
        $this->assertEquals($list[0], $result);
217
        $this->assertEquals($list[0], $result);
218
    }
218
    }
Línea 219... Línea 219...
219
 
219
 
220
    public function test_count_cohort_role_assignments() {
220
    public function test_count_cohort_role_assignments(): void {
221
        $this->setAdminUser();
221
        $this->setAdminUser();
222
        $params = (object) array(
222
        $params = (object) array(
223
            'userid' => $this->userassignto->id,
223
            'userid' => $this->userassignto->id,
224
            'roleid' => $this->roleid,
224
            'roleid' => $this->roleid,
Línea 228... Línea 228...
228
 
228
 
229
        $count = api::count_cohort_role_assignments();
229
        $count = api::count_cohort_role_assignments();
230
        $this->assertEquals($count, 1);
230
        $this->assertEquals($count, 1);
Línea 231... Línea 231...
231
    }
231
    }
232
 
232
 
233
    public function test_sync_all_cohort_roles() {
233
    public function test_sync_all_cohort_roles(): void {
234
        $this->setAdminUser();
234
        $this->setAdminUser();
235
        $params = (object) array(
235
        $params = (object) array(
236
            'userid' => $this->userassignto->id,
236
            'userid' => $this->userassignto->id,