23
23
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
24
*/
25
25
26
+ namespace mod_customcert ;
27
+
28
+ use grade_item ;
29
+ use grade_grade ;
30
+ use context_module ;
31
+ use context_system ;
32
+ use advanced_testcase ;
33
+
26
34
defined ('MOODLE_INTERNAL ' ) || die ();
27
35
28
36
global $ CFG ;
35
43
* @copyright 2017 Mark Nelson <[email protected] >
36
44
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
45
*/
38
- class mod_customcert_element_helper_testcase extends advanced_testcase {
46
+ class element_helper_test extends advanced_testcase {
39
47
40
48
/**
41
49
* Test set up.
@@ -58,7 +66,7 @@ public function test_get_courseid_element_in_course_certificate() {
58
66
59
67
// Get the template to add elements to.
60
68
$ template = $ DB ->get_record ('customcert_templates ' , array ('contextid ' => context_module::instance ($ customcert ->cmid )->id ));
61
- $ template = new \ mod_customcert \ template ($ template );
69
+ $ template = new template ($ template );
62
70
63
71
// Add a page to the template.
64
72
$ pageid = $ template ->add_page ();
@@ -68,12 +76,12 @@ public function test_get_courseid_element_in_course_certificate() {
68
76
$ element ->name = 'Test element ' ;
69
77
$ element ->element = 'testelement ' ;
70
78
$ element ->pageid = $ pageid ;
71
- $ element ->sequence = \ mod_customcert \ element_helper::get_element_sequence ($ element ->pageid );
79
+ $ element ->sequence = element_helper::get_element_sequence ($ element ->pageid );
72
80
$ element ->timecreated = time ();
73
81
$ element ->id = $ DB ->insert_record ('customcert_elements ' , $ element );
74
82
75
83
// Confirm the correct course id is returned.
76
- $ this ->assertEquals ($ course ->id , \ mod_customcert \ element_helper::get_courseid ($ element ->id ));
84
+ $ this ->assertEquals ($ course ->id , element_helper::get_courseid ($ element ->id ));
77
85
}
78
86
79
87
/**
@@ -83,7 +91,7 @@ public function test_get_courseid_element_in_site_template() {
83
91
global $ DB , $ SITE ;
84
92
85
93
// Add a template to the site.
86
- $ template = \ mod_customcert \ template::create ('Site template ' , context_system::instance ()->id );
94
+ $ template = template::create ('Site template ' , context_system::instance ()->id );
87
95
88
96
// Add a page to the template.
89
97
$ pageid = $ template ->add_page ();
@@ -93,12 +101,12 @@ public function test_get_courseid_element_in_site_template() {
93
101
$ element ->name = 'Test element ' ;
94
102
$ element ->element = 'testelement ' ;
95
103
$ element ->pageid = $ pageid ;
96
- $ element ->sequence = \ mod_customcert \ element_helper::get_element_sequence ($ element ->pageid );
104
+ $ element ->sequence = element_helper::get_element_sequence ($ element ->pageid );
97
105
$ element ->timecreated = time ();
98
106
$ element ->id = $ DB ->insert_record ('customcert_elements ' , $ element );
99
107
100
108
// Confirm the correct course id is returned.
101
- $ this ->assertEquals ($ SITE ->id , \ mod_customcert \ element_helper::get_courseid ($ element ->id ));
109
+ $ this ->assertEquals ($ SITE ->id , element_helper::get_courseid ($ element ->id ));
102
110
}
103
111
104
112
/**
@@ -115,7 +123,7 @@ public function test_get_context_element_in_course_certificate() {
115
123
116
124
// Get the template to add elements to.
117
125
$ template = $ DB ->get_record ('customcert_templates ' , array ('contextid ' => context_module::instance ($ customcert ->cmid )->id ));
118
- $ template = new \ mod_customcert \ template ($ template );
126
+ $ template = new template ($ template );
119
127
120
128
// Add a page to the template.
121
129
$ pageid = $ template ->add_page ();
@@ -125,13 +133,13 @@ public function test_get_context_element_in_course_certificate() {
125
133
$ element ->name = 'Test element ' ;
126
134
$ element ->element = 'testelement ' ;
127
135
$ element ->pageid = $ pageid ;
128
- $ element ->sequence = \ mod_customcert \ element_helper::get_element_sequence ($ element ->pageid );
136
+ $ element ->sequence = element_helper::get_element_sequence ($ element ->pageid );
129
137
$ element ->timecreated = time ();
130
138
$ element ->id = $ DB ->insert_record ('customcert_elements ' , $ element );
131
139
132
140
// Confirm the correct course module id is returned.
133
141
$ this ->assertEquals (context_module::instance ($ customcert ->cmid ),
134
- \ mod_customcert \ element_helper::get_context ($ element ->id ));
142
+ element_helper::get_context ($ element ->id ));
135
143
}
136
144
137
145
/**
@@ -141,7 +149,7 @@ public function test_get_context_element_in_site_template() {
141
149
global $ DB ;
142
150
143
151
// Add a template to the site.
144
- $ template = \ mod_customcert \ template::create ('Site template ' , context_system::instance ()->id );
152
+ $ template = template::create ('Site template ' , context_system::instance ()->id );
145
153
146
154
// Add a page to the template.
147
155
$ pageid = $ template ->add_page ();
@@ -151,12 +159,12 @@ public function test_get_context_element_in_site_template() {
151
159
$ element ->name = 'Test element ' ;
152
160
$ element ->element = 'testelement ' ;
153
161
$ element ->pageid = $ pageid ;
154
- $ element ->sequence = \ mod_customcert \ element_helper::get_element_sequence ($ element ->pageid );
162
+ $ element ->sequence = element_helper::get_element_sequence ($ element ->pageid );
155
163
$ element ->timecreated = time ();
156
164
$ element ->id = $ DB ->insert_record ('customcert_elements ' , $ element );
157
165
158
166
// Confirm the correct course module id is returned.
159
- $ this ->assertEquals (context_system::instance (), \ mod_customcert \ element_helper::get_context ($ element ->id ));
167
+ $ this ->assertEquals (context_system::instance (), element_helper::get_context ($ element ->id ));
160
168
}
161
169
162
170
/**
@@ -190,7 +198,7 @@ public function test_get_grade_items() {
190
198
);
191
199
192
200
// Confirm the function returns the correct number of grade items.
193
- $ gradeitems = \ mod_customcert \ element_helper::get_grade_items ($ course );
201
+ $ gradeitems = element_helper::get_grade_items ($ course );
194
202
$ this ->assertCount (6 , $ gradeitems );
195
203
$ this ->assertArrayHasKey ($ assign1 ->cmid , $ gradeitems );
196
204
$ this ->assertArrayHasKey ($ assign2 ->cmid , $ gradeitems );
@@ -244,7 +252,7 @@ public function test_get_mod_grade_info() {
244
252
$ grade ->insert ();
245
253
246
254
// Check that the user received the grade.
247
- $ grade = \ mod_customcert \ element_helper::get_mod_grade_info (
255
+ $ grade = element_helper::get_mod_grade_info (
248
256
$ assign ->cmid ,
249
257
GRADE_DISPLAY_TYPE_PERCENTAGE ,
250
258
$ student1 ->id
@@ -256,7 +264,7 @@ public function test_get_mod_grade_info() {
256
264
$ this ->assertEquals ($ time , $ grade ->get_dategraded ());
257
265
258
266
// Check that the user we did not grade has no grade.
259
- $ grade = \ mod_customcert \ element_helper::get_mod_grade_info (
267
+ $ grade = element_helper::get_mod_grade_info (
260
268
$ assign ->cmid ,
261
269
GRADE_DISPLAY_TYPE_PERCENTAGE ,
262
270
$ student2 ->id
@@ -304,7 +312,7 @@ public function test_get_course_grade_info() {
304
312
$ grade ->insert ();
305
313
306
314
// Check that the user received the grade.
307
- $ grade = \ mod_customcert \ element_helper::get_course_grade_info (
315
+ $ grade = element_helper::get_course_grade_info (
308
316
$ course ->id ,
309
317
GRADE_DISPLAY_TYPE_PERCENTAGE ,
310
318
$ student1 ->id
@@ -316,7 +324,7 @@ public function test_get_course_grade_info() {
316
324
$ this ->assertEquals ($ time , $ grade ->get_dategraded ());
317
325
318
326
// Check that the user we did not grade has no grade.
319
- $ grade = \ mod_customcert \ element_helper::get_course_grade_info (
327
+ $ grade = element_helper::get_course_grade_info (
320
328
$ course ->id ,
321
329
GRADE_DISPLAY_TYPE_PERCENTAGE ,
322
330
$ student2 ->id
@@ -366,7 +374,7 @@ public function test_get_grade_item_info() {
366
374
$ grade ->insert ();
367
375
368
376
// Check that the user received the grade.
369
- $ grade = \ mod_customcert \ element_helper::get_grade_item_info (
377
+ $ grade = element_helper::get_grade_item_info (
370
378
$ gi ->id ,
371
379
GRADE_DISPLAY_TYPE_PERCENTAGE ,
372
380
$ student1 ->id
@@ -378,7 +386,7 @@ public function test_get_grade_item_info() {
378
386
$ this ->assertEquals ($ time , $ grade ->get_dategraded ());
379
387
380
388
// Check that the user we did not grade has no grade.
381
- $ grade = \ mod_customcert \ element_helper::get_grade_item_info (
389
+ $ grade = element_helper::get_grade_item_info (
382
390
$ gi ->id ,
383
391
GRADE_DISPLAY_TYPE_PERCENTAGE ,
384
392
$ student2 ->id
0 commit comments