Skip to content

Commit

Permalink
Merge pull request #4 from LearningLocker/issue/voids
Browse files Browse the repository at this point in the history
Fixes void validation.
  • Loading branch information
ryasmi committed Aug 17, 2015
2 parents b364e7f + 5a4b819 commit efe3030
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
17 changes: 17 additions & 0 deletions src/StatementBase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace Locker\XApi;
use Locker\XApi\Errors\Error as Error;

class StatementBase extends Element {
protected $props = [
Expand All @@ -11,4 +12,20 @@ class StatementBase extends Element {
'attachments' => 'Locker\XApi\Attachments'
];
protected $required_props = ['actor', 'verb', 'object'];

public function validate() {
$errors = [];
$verb_id = $this->getPropValue('verb.id');
$object_type = $this->getPropValue('object.objectType');

// Validates voider.
if (
$verb_id === 'http://adlnet.gov/expapi/verbs/voided' &&
$object_type !== 'StatementRef'
) {
$errors[] = new Error("`object.objectType` must be `StatementRef` not `$object_type` when voiding");
}

return array_merge($errors, parent::validate());
}
}
43 changes: 6 additions & 37 deletions tests/assets/test.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
{
"id": "710cc790-9d8d-11e4-bd06-0800200c9a66",
"actor": {
"objectType": "Agent",
"mbox": "mailto:duy.nguyen@go1.com.au",
"name": "quanvm"
"actor":{
"mbox":"mailto:test@example.com"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/experienced",
"display": {"en-us": "experienced"}
"verb":{
"id":"http://adlnet.gov/expapi/verbs/voided"
},
"context": {
"contextActivities": {
"parent": {
"id": "http://tincanapi.com/GolfExample_TCAPI",
"objectType": "Activity"
},
"grouping": [{
"id": "http://tincanapi.com/GolfExample_TCAPI",
"objectType": "Activity"
}]
}
},
"object": {
"id": "http://tincanapi.com/GolfExample_TCAPI/Playing/Scoring.html",
"objectType": "Activity",
"definition": {
"name": {
"en-US": "Scoring"
},
"description": {
"en-US": "An overview of how to score a round of golf."
},
"type": "http:///activitystrea.ms/schema/1.0/badge"
}
},
"authority": {
"name": "",
"mbox": "mailto:quan@ll.com",
"objectType": "Agent"
"object":{
"id":"http://kiem.curatr3.com/courses/mentoropleiding"
}
}
2 changes: 1 addition & 1 deletion tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Locker\XApi as XApi;


header('Content-Type: application/json');
try {
// Code.
$file_location = 'assets/test.json';
Expand Down

0 comments on commit efe3030

Please sign in to comment.