@@ -109,7 +109,7 @@ public function test_sort_answer_by_ratings() {
109
109
// Create helpful, solved, up and downvotes ratings.
110
110
$ this ->create_everygroup ();
111
111
112
- // Test with every group if rating
112
+ // Test with every group of rating
113
113
114
114
// Create a array of the posts, save the sorted post and compare them to the order that they should have.
115
115
$ posts = array ($ this ->post , $ this ->answer1 , $ this ->answer2 , $ this ->answer3 , $ this ->answer4 , $ this ->answer5 , $ this ->answer6 );
@@ -167,6 +167,8 @@ public function test_sort_answer_by_ratings() {
167
167
$ rightorderposts = array ($ this ->post , $ this ->answer2 , $ this ->answer3 , $ this ->answer4 , $ this ->answer6 , $ this ->answer5 );
168
168
$ result = $ this ->postsorderequal ($ sortedposts , $ rightorderposts );
169
169
$ this ->assertEquals (1 , $ result );
170
+
171
+ // Now test every rating group alone
170
172
}
171
173
172
174
// Helper functions
@@ -304,6 +306,76 @@ private function create_everygroup() {
304
306
$ this ->answer6 ->markedsolution = 0 ;
305
307
}
306
308
307
- // private function create_groupswithoutsolution
309
+ /**
310
+ * Creates a rating of one group for every post in the discussion
311
+ * Creates up and downvotes
312
+ * @param string $group
313
+ * A Group can be:
314
+ * - both as solution and helpful marked posts (sh)
315
+ * - only solution posts (s)
316
+ * - only helpful (h)
317
+ * - no mark (o)
318
+ */
319
+ private function create_onegroup ($ group ) {
320
+
321
+ $ answers = array ($ this ->answer1 , $ this ->answer2 , $ this ->answer3 , $ this ->answer4 , $ this ->answer5 , $ this ->answer6 );
322
+ foreach ($ answers as $ answer ) {
323
+ switch ($ group ) {
324
+ case 'sh ' :
325
+ $ answer ->markedhelpful = 1 ;
326
+ $ answer ->markedsolution = 1 ;
327
+ break ;
328
+ case 's ' :
329
+ $ answer ->markedhelpful = 0 ;
330
+ $ answer ->markedsolution = 1 ;
331
+ break ;
332
+ case 'h ' :
333
+ $ answer ->markedhelpful = 1 ;
334
+ $ answer ->markedsolution = 0 ;
335
+ break ;
336
+ case 'o ' :
337
+ $ answer ->markedhelpful = 0 ;
338
+ $ answer ->markedsolution = 0 ;
339
+ break ;
340
+ default :
341
+ $ answer ->markedhelpful = 0 ;
342
+ $ answer ->markedsolution = 0 ;
343
+ break ;
344
+ }
345
+ }
346
+
347
+ // Votes for the answerposts
348
+ // Answer1.
349
+ $ this ->answer1 ->upvotes = 4 ;
350
+ $ this ->answer1 ->downvotes = -4 ;
351
+ $ this ->answer1 ->votesdifference = $ this ->answer1 ->upvotes - $ this ->answer1 ->downvotes ; // Vd = 0.
352
+
353
+ // Answer2.
354
+ $ this ->answer1 ->upvotes = 1 ;
355
+ $ this ->answer1 ->downvotes = 2 ;
356
+ $ this ->answer1 ->votesdifference = $ this ->answer1 ->upvotes - $ this ->answer1 ->downvotes ; // Vd = -1.
357
+
358
+ // Answer3.
359
+ $ this ->answer1 ->upvotes = 3 ;
360
+ $ this ->answer1 ->downvotes = 2 ;
361
+ $ this ->answer1 ->votesdifference = $ this ->answer1 ->upvotes - $ this ->answer1 ->downvotes ; // Vd = 1.
362
+
363
+ // Answer4.
364
+ $ this ->answer1 ->upvotes = 5 ;
365
+ $ this ->answer1 ->downvotes = 0 ;
366
+ $ this ->answer1 ->votesdifference = $ this ->answer1 ->upvotes - $ this ->answer1 ->downvotes ; // Vd = 5
367
+
368
+ // Answer5.
369
+ $ this ->answer1 ->upvotes = 0 ;
370
+ $ this ->answer1 ->downvotes = 2 ;
371
+ $ this ->answer1 ->votesdifference = $ this ->answer1 ->upvotes - $ this ->answer1 ->downvotes ; // Vd = -2.
372
+
373
+ // Answer6.
374
+ $ this ->answer1 ->upvotes = 4 ;
375
+ $ this ->answer1 ->downvotes = 2 ;
376
+ $ this ->answer1 ->votesdifference = $ this ->answer1 ->upvotes - $ this ->answer1 ->downvotes ; // Vd = 2.
377
+
378
+ // Rightorder = answer4 , answer6, answer3, answer1, answer2, answer5.
379
+ }
308
380
309
381
}
0 commit comments