File tree Expand file tree Collapse file tree 5 files changed +44
-6
lines changed Expand file tree Collapse file tree 5 files changed +44
-6
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Packback \Lti1p3 \Helpers ;
4
+
5
+ class Helpers
6
+ {
7
+ /**
8
+ * @param $value
9
+ */
10
+ public static function checkIfNullValue ($ value ): bool
11
+ {
12
+ return !is_null ($ value );
13
+ }
14
+ }
Original file line number Diff line number Diff line change @@ -28,17 +28,20 @@ public function __construct(array $grade = null)
28
28
29
29
public function __toString ()
30
30
{
31
- return json_encode (array_filter ([
32
- 'scoreGiven ' => 0 + $ this ->score_given ,
33
- 'scoreMaximum ' => 0 + $ this ->score_maximum ,
31
+ // Additionally, includes the call back to filter out only NULL values
32
+ $ request = array_filter ([
33
+ 'scoreGiven ' => $ this ->score_given ,
34
+ 'scoreMaximum ' => $ this ->score_maximum ,
34
35
'comment ' => $ this ->comment ,
35
36
'activityProgress ' => $ this ->activity_progress ,
36
37
'gradingProgress ' => $ this ->grading_progress ,
37
38
'timestamp ' => $ this ->timestamp ,
38
39
'userId ' => $ this ->user_id ,
39
40
'submissionReview ' => $ this ->submission_review ,
40
41
'https://canvas.instructure.com/lti/submission ' => $ this ->canvas_extension ,
41
- ]));
42
+ ], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue ' );
43
+
44
+ return json_encode ($ request );
42
45
}
43
46
44
47
/**
Original file line number Diff line number Diff line change @@ -19,12 +19,13 @@ public function __construct(array $gradeSubmission = null)
19
19
20
20
public function __toString ()
21
21
{
22
+ // Additionally, includes the call back to filter out only NULL values
22
23
return json_encode (array_filter ([
23
24
'reviewableStatus ' => $ this ->reviewable_status ,
24
25
'label ' => $ this ->label ,
25
26
'url ' => $ this ->url ,
26
27
'custom ' => $ this ->custom ,
27
- ]));
28
+ ], ' \Packback\Lti1p3\Helpers\Helpers::checkIfNullValue ' ));
28
29
}
29
30
30
31
/**
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ public function __construct(array $lineitem = null)
27
27
28
28
public function __toString ()
29
29
{
30
+ // Additionally, includes the call back to filter out only NULL values
30
31
return json_encode (array_filter ([
31
32
'id ' => $ this ->id ,
32
33
'scoreMaximum ' => $ this ->score_maximum ,
@@ -35,7 +36,7 @@ public function __toString()
35
36
'tag ' => $ this ->tag ,
36
37
'startDateTime ' => $ this ->start_date_time ,
37
38
'endDateTime ' => $ this ->end_date_time ,
38
- ]));
39
+ ], ' \Packback\Lti1p3\Helpers\Helpers::checkIfNullValue ' ));
39
40
}
40
41
41
42
/**
Original file line number Diff line number Diff line change @@ -213,6 +213,25 @@ public function testItCastsFullObjectToString()
213
213
$ this ->assertEquals (json_encode ($ expected ), (string ) $ grade );
214
214
}
215
215
216
+ public function testItCastsFullObjectToStringWith0Grade ()
217
+ {
218
+ $ expected = [
219
+ 'scoreGiven ' => 0 ,
220
+ 'scoreMaximum ' => 10 ,
221
+ 'comment ' => 'Comment ' ,
222
+ 'activityProgress ' => 'ActivityProgress ' ,
223
+ 'gradingProgress ' => 'GradingProgress ' ,
224
+ 'timestamp ' => 'Timestamp ' ,
225
+ 'userId ' => 'UserId ' ,
226
+ 'submissionReview ' => 'SubmissionReview ' ,
227
+ 'https://canvas.instructure.com/lti/submission ' => 'CanvasExtension ' ,
228
+ ];
229
+
230
+ $ grade = new LtiGrade ($ expected );
231
+
232
+ $ this ->assertEquals (json_encode ($ expected ), (string ) $ grade );
233
+ }
234
+
216
235
public function testItCastsEmptyObjectToString ()
217
236
{
218
237
$ this ->assertEquals ('[] ' , (string ) $ this ->grade );
You can’t perform that action at this time.
0 commit comments