From 5a4b819a0bf57c9da4bc95912d04d4e053d84fd7 Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Fri, 15 May 2015 16:43:57 +0100 Subject: [PATCH] Fixes void validation. --- src/StatementBase.php | 17 +++++++++++++++++ tests/assets/test.json | 43 ++++++------------------------------------ tests/test.php | 2 +- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/StatementBase.php b/src/StatementBase.php index 60008c3..eee5118 100644 --- a/src/StatementBase.php +++ b/src/StatementBase.php @@ -1,4 +1,5 @@ '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()); + } } diff --git a/tests/assets/test.json b/tests/assets/test.json index 9e06028..29ad09f 100644 --- a/tests/assets/test.json +++ b/tests/assets/test.json @@ -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" } } diff --git a/tests/test.php b/tests/test.php index fd36e07..70607bc 100755 --- a/tests/test.php +++ b/tests/test.php @@ -3,7 +3,7 @@ use Locker\XApi as XApi; - +header('Content-Type: application/json'); try { // Code. $file_location = 'assets/test.json';