@@ -60,7 +60,7 @@ public function test_simple(): void {
6060
6161 $ course = $ this ->getDataGenerator ()->create_course ();
6262
63- $ teacher = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course , true );
63+ $ teacher = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course , true );
6464 $ this ->setUser ($ teacher );
6565
6666 // There should not be any module for that course first.
@@ -71,27 +71,27 @@ public function test_simple(): void {
7171 );
7272
7373 // Set default data for category.
74- $ moduledata = \ mod_ratingallocate_generator::get_default_values ();
74+ $ moduledata = mod_ratingallocate_generator::get_default_values ();
7575 $ moduledata ['course ' ] = $ course ;
7676
77- $ choicedata = \ mod_ratingallocate_generator::get_default_choice_data ();
77+ $ choicedata = mod_ratingallocate_generator::get_default_choice_data ();
7878 foreach ($ choicedata as $ id => $ choice ) {
7979 $ choice ['maxsize ' ] = 2 ;
8080 $ choice ['active ' ] = true ;
8181 $ choicedata [$ id ] = $ choice ;
8282 }
8383
8484 // Create activity.
85- $ mod = \ mod_ratingallocate_generator::create_instance_with_choices ($ this , $ moduledata , $ choicedata );
85+ $ mod = mod_ratingallocate_generator::create_instance_with_choices ($ this , $ moduledata , $ choicedata );
8686 $ this ->assertEquals (2 , $ DB ->count_records (this_db \ratingallocate_choices::TABLE ),
8787 "Failure, debug info: " . implode (", " , [this_db \ratingallocate_choices::ID => $ mod ->id ]));
8888
89- $ student1 = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
90- $ student2 = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
91- $ student3 = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
92- $ student4 = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
89+ $ student1 = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
90+ $ student2 = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
91+ $ student3 = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
92+ $ student4 = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
9393
94- $ ratingallocate = \ mod_ratingallocate_generator::get_ratingallocate_for_user ($ this , $ mod , $ teacher );
94+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user ($ this , $ mod , $ teacher );
9595 $ choices = $ ratingallocate ->get_rateable_choices ();
9696
9797 $ choice1 = reset ($ choices );
@@ -110,12 +110,13 @@ public function test_simple(): void {
110110 $ preferssecond [$ choice2 ->{this_db \ratingallocate_choices::ID }][this_db \ratingallocate_ratings::RATING ] = true ;
111111
112112 // Assign preferences.
113- \ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student1 , $ prefersfirst );
114- \ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student2 , $ prefersfirst );
115- \ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student3 , $ preferssecond );
116- \ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student4 , $ preferssecond );
113+ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student1 , $ prefersfirst );
114+ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student2 , $ prefersfirst );
115+ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student3 , $ preferssecond );
116+ mod_ratingallocate_generator::save_rating_for_user ($ this , $ mod , $ student4 , $ preferssecond );
117117
118118 // Allocate choices.
119+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user ($ this , $ mod , $ teacher );
119120 $ timeneeded = $ ratingallocate ->distribute_choices ();
120121 $ this ->assertGreaterThan (0 , $ timeneeded );
121122 $ this ->assertLessThan (0.1 , $ timeneeded , 'Allocation is very slow ' );
@@ -178,25 +179,29 @@ private static function filter_allocations_by_choice($allocations, $choiceid) {
178179 /**
179180 * Default data has two choices but only one is active.
180181 * Test if count of rateable choices is 1.
182+ *
183+ * @covers \mod_ratingallocate\ratingallocate::get_rateable_choices
181184 */
182185 public function test_get_ratable_choices (): void {
183- $ record = \ mod_ratingallocate_generator::get_default_values ();
186+ $ record = mod_ratingallocate_generator::get_default_values ();
184187 $ testmodule = new \mod_ratingallocate_generated_module ($ this , $ record );
185188 $ ratingallocate =
186- \ mod_ratingallocate_generator::get_ratingallocate_for_user ($ this , $ testmodule ->moddb , $ testmodule ->teacher );
189+ mod_ratingallocate_generator::get_ratingallocate_for_user ($ this , $ testmodule ->moddb , $ testmodule ->teacher );
187190 $ this ->assertCount (1 , $ ratingallocate ->get_rateable_choices ());
188191 }
189192
190193 /**
191194 * Test if option titles are returned according to the default values
195+ *
196+ * @covers \mod_ratingallocate\ratingallocate::get_options_titles
192197 */
193198 public function test_get_option_titles_default (): void {
194199 $ expectedresult = [1 => 'Accept ' , 0 => 'Deny ' ]; // Depends on language file.
195200 $ ratings = [0 , 1 , 1 , 1 , 0 ];
196201
197- $ record = \ mod_ratingallocate_generator::get_default_values ();
202+ $ record = mod_ratingallocate_generator::get_default_values ();
198203 $ testmodule = new \mod_ratingallocate_generated_module ($ this , $ record );
199- $ ratingallocate = \ mod_ratingallocate_generator::get_ratingallocate_for_user (
204+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user (
200205 $ this , $ testmodule ->moddb , $ testmodule ->teacher );
201206
202207 $ result = $ ratingallocate ->get_options_titles ($ ratings );
@@ -205,15 +210,17 @@ public function test_get_option_titles_default(): void {
205210
206211 /**
207212 * Test if option titles are returned according to defined custom values
213+ *
214+ * @covers \mod_ratingallocate\ratingallocate::get_options_titles
208215 */
209216 public function test_get_option_titles_custom (): void {
210217 $ expectedresult = [1 => 'Ja1234 ' , 0 => 'Nein1234 ' ]; // Test data.
211218 $ ratings = [1 , 1 , 1 , 0 , 1 , 1 ];
212219
213- $ record = \ mod_ratingallocate_generator::get_default_values ();
220+ $ record = mod_ratingallocate_generator::get_default_values ();
214221 $ record ['strategyopt ' ]['strategy_yesno ' ] = $ expectedresult ;
215222 $ testmodule = new \mod_ratingallocate_generated_module ($ this , $ record );
216- $ ratingallocate = \ mod_ratingallocate_generator::get_ratingallocate_for_user (
223+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user (
217224 $ this , $ testmodule ->moddb , $ testmodule ->teacher );
218225
219226 $ result = $ ratingallocate ->get_options_titles ($ ratings );
@@ -222,15 +229,17 @@ public function test_get_option_titles_custom(): void {
222229
223230 /**
224231 * Test if option titles are returned according to defined custom values, if ratings consist of just one rating
232+ *
233+ * @covers \mod_ratingallocate\ratingallocate::get_options_titles
225234 */
226235 public function test_get_option_titles_custom1 (): void {
227236 $ expectedresult = [1 => 'Ja1234 ' ]; // Test data.
228237 $ ratings = [1 , 1 , 1 , 1 , 1 ];
229238
230- $ record = \ mod_ratingallocate_generator::get_default_values ();
239+ $ record = mod_ratingallocate_generator::get_default_values ();
231240 $ record ['strategyopt ' ]['strategy_yesno ' ] = $ expectedresult ;
232241 $ testmodule = new \mod_ratingallocate_generated_module ($ this , $ record );
233- $ ratingallocate = \ mod_ratingallocate_generator::get_ratingallocate_for_user (
242+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user (
234243 $ this , $ testmodule ->moddb , $ testmodule ->teacher );
235244
236245 $ result = $ ratingallocate ->get_options_titles ($ ratings );
@@ -248,10 +257,10 @@ public function test_get_option_titles_mixed(): void {
248257 $ expectedresult = $ settings ;
249258 $ expectedresult [0 ] = 'Deny ' ; // Depends on language file.
250259
251- $ record = \ mod_ratingallocate_generator::get_default_values ();
260+ $ record = mod_ratingallocate_generator::get_default_values ();
252261 $ record ['strategyopt ' ]['strategy_yesno ' ] = $ settings ;
253262 $ testmodule = new \mod_ratingallocate_generated_module ($ this , $ record );
254- $ ratingallocate = \ mod_ratingallocate_generator::get_ratingallocate_for_user (
263+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user (
255264 $ this , $ testmodule ->moddb , $ testmodule ->teacher );
256265
257266 $ result = $ ratingallocate ->get_options_titles ($ ratings );
@@ -269,49 +278,20 @@ public function test_reset_userdata(): void {
269278 $ this ->resetAfterTest ();
270279
271280 $ course = $ this ->getDataGenerator ()->create_course ();
272- $ teacher = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course , true );
273- $ student1 = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
274- $ student2 = \ mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
281+ $ teacher = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course , true );
282+ $ student1 = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
283+ $ student2 = mod_ratingallocate_generator::create_user_and_enrol ($ this , $ course );
275284
276285 $ this ->setUser ($ teacher );
277286
278- $ choices = [
279- [
280- 'title ' => 'C1 ' ,
281- 'maxsize ' => '1 ' ,
282- 'active ' => '1 ' ,
283- ],
284- [
285- 'title ' => 'C2 ' ,
286- 'maxsize ' => '1 ' ,
287- 'active ' => '1 ' ,
288- ],
289- ];
287+ $ choices = [['title ' => 'C1 ' , 'maxsize ' => '1 ' , 'active ' => '1 ' ], ['title ' => 'C2 ' , 'maxsize ' => '1 ' , 'active ' => '1 ' ]];
290288 $ ratings = [
291- $ student1 ->id => [
292- [
293- 'choice ' => 'C1 ' ,
294- 'rating ' => 1 ,
295- ],
296- [
297- 'choice ' => 'C2 ' ,
298- 'rating ' => 0 ,
299- ],
300- ],
301- $ student2 ->id => [
302- [
303- 'choice ' => 'C1 ' ,
304- 'rating ' => 0 ,
305- ],
306- [
307- 'choice ' => 'C2 ' ,
308- 'rating ' => 1 ,
309- ],
310- ],
289+ $ student1 ->id => [['choice ' => 'C1 ' , 'rating ' => 1 ], ['choice ' => 'C2 ' , 'rating ' => 0 ]],
290+ $ student2 ->id => [['choice ' => 'C1 ' , 'rating ' => 0 ], ['choice ' => 'C2 ' , 'rating ' => 1 ]],
311291 ];
312292
313293 // Create ratingallocate instance.
314- $ ratingallocate = \ mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher ($ this , $ choices ,
294+ $ ratingallocate = mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher ($ this , $ choices ,
315295 $ course , $ ratings );
316296
317297 // Simulate Allocation.
@@ -343,7 +323,7 @@ public function test_reset_userdata(): void {
343323
344324 // Reload the instance data.
345325 $ ra = $ DB ->get_record ('ratingallocate ' , ['id ' => $ ratingallocate ->get_ratingallocateid ()]);
346- $ ratingallocate = \ mod_ratingallocate_generator::get_ratingallocate ($ ra );
326+ $ ratingallocate = mod_ratingallocate_generator::get_ratingallocate ($ ra );
347327
348328 // There should be no ratings and allocations anymore.
349329 $ this ->assertEquals (0 , count ($ ratingallocate ->get_allocations ()));
0 commit comments