Skip to content

Commit efe3030

Browse files
committed
Merge pull request #4 from LearningLocker/issue/voids
Fixes void validation.
2 parents b364e7f + 5a4b819 commit efe3030

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

src/StatementBase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php namespace Locker\XApi;
2+
use Locker\XApi\Errors\Error as Error;
23

34
class StatementBase extends Element {
45
protected $props = [
@@ -11,4 +12,20 @@ class StatementBase extends Element {
1112
'attachments' => 'Locker\XApi\Attachments'
1213
];
1314
protected $required_props = ['actor', 'verb', 'object'];
15+
16+
public function validate() {
17+
$errors = [];
18+
$verb_id = $this->getPropValue('verb.id');
19+
$object_type = $this->getPropValue('object.objectType');
20+
21+
// Validates voider.
22+
if (
23+
$verb_id === 'http://adlnet.gov/expapi/verbs/voided' &&
24+
$object_type !== 'StatementRef'
25+
) {
26+
$errors[] = new Error("`object.objectType` must be `StatementRef` not `$object_type` when voiding");
27+
}
28+
29+
return array_merge($errors, parent::validate());
30+
}
1431
}

tests/assets/test.json

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,11 @@
11
{
2-
"id": "710cc790-9d8d-11e4-bd06-0800200c9a66",
3-
"actor": {
4-
"objectType": "Agent",
5-
"mbox": "mailto:[email protected]",
6-
"name": "quanvm"
2+
"actor":{
3+
"mbox":"mailto:[email protected]"
74
},
8-
"verb": {
9-
"id": "http://adlnet.gov/expapi/verbs/experienced",
10-
"display": {"en-us": "experienced"}
5+
"verb":{
6+
"id":"http://adlnet.gov/expapi/verbs/voided"
117
},
12-
"context": {
13-
"contextActivities": {
14-
"parent": {
15-
"id": "http://tincanapi.com/GolfExample_TCAPI",
16-
"objectType": "Activity"
17-
},
18-
"grouping": [{
19-
"id": "http://tincanapi.com/GolfExample_TCAPI",
20-
"objectType": "Activity"
21-
}]
22-
}
23-
},
24-
"object": {
25-
"id": "http://tincanapi.com/GolfExample_TCAPI/Playing/Scoring.html",
26-
"objectType": "Activity",
27-
"definition": {
28-
"name": {
29-
"en-US": "Scoring"
30-
},
31-
"description": {
32-
"en-US": "An overview of how to score a round of golf."
33-
},
34-
"type": "http:///activitystrea.ms/schema/1.0/badge"
35-
}
36-
},
37-
"authority": {
38-
"name": "",
39-
"mbox": "mailto:[email protected]",
40-
"objectType": "Agent"
8+
"object":{
9+
"id":"http://kiem.curatr3.com/courses/mentoropleiding"
4110
}
4211
}

tests/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use Locker\XApi as XApi;
55

6-
6+
header('Content-Type: application/json');
77
try {
88
// Code.
99
$file_location = 'assets/test.json';

0 commit comments

Comments
 (0)