From 1d7ca1eb031cc8114a31ba66687f87bbd6b2a30a Mon Sep 17 00:00:00 2001 From: "Brian J. Miller" Date: Tue, 22 Jul 2014 07:09:39 -0500 Subject: [PATCH 1/4] Add "scorm" as composer keyword --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b4ad770..c038db1 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "tincan", "xapi", "experience api", - "e-learning" + "e-learning", + "scorm" ], "license": "Apache-2.0", "authors": [ From 0704e48e229722c34577dfda0de454bab34bfd2c Mon Sep 17 00:00:00 2001 From: "Brian J. Miller" Date: Tue, 22 Jul 2014 08:48:08 -0500 Subject: [PATCH 2/4] Correct 'member' handling in Group --- src/Group.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Group.php b/src/Group.php index 828a151..b127f4c 100644 --- a/src/Group.php +++ b/src/Group.php @@ -46,9 +46,9 @@ public function asVersion($version) { } public function setMember($value) { - foreach ($value as $k) { - if (! $value[$k] instanceof Agent) { - $value[$k] = new Agent($value[$k]); + foreach ($value as $k => $v) { + if (! $v instanceof Agent) { + $value[$k] = new Agent($v); } } From a445f95b348e8befebcb4cf7f2de8efc64521184 Mon Sep 17 00:00:00 2001 From: "Brian J. Miller" Date: Tue, 22 Jul 2014 09:03:46 -0500 Subject: [PATCH 3/4] Turn off noise in test suite --- tests/RemoteLRSTest.php | 3 --- tests/StatementTest.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/RemoteLRSTest.php b/tests/RemoteLRSTest.php index d81c060..d03a53c 100644 --- a/tests/RemoteLRSTest.php +++ b/tests/RemoteLRSTest.php @@ -199,9 +199,6 @@ public function testRetrieveActivityProfile() { ); $this->assertInstanceOf('TinCan\LRSResponse', $response); - print_r($response->httpResponse['headers']); - print "\n\n"; - print_r($response->content); } public function testSaveActivityProfile() { diff --git a/tests/StatementTest.php b/tests/StatementTest.php index 1f664aa..be7cb6c 100644 --- a/tests/StatementTest.php +++ b/tests/StatementTest.php @@ -150,6 +150,6 @@ public function testAsVersion() { $versioned = $obj->asVersion('1.0.0'); - print json_encode($versioned, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + //print json_encode($versioned, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } } From bceec147620835647ffe9deaa9e4878e4de0a2e9 Mon Sep 17 00:00:00 2001 From: "Brian J. Miller" Date: Tue, 22 Jul 2014 10:48:30 -0500 Subject: [PATCH 4/4] Default ContextActivities properties to arrays * The check to make sure the properties were set was not happening soon enough so that the set methods through the _listSetter were trying to push to arrays that were not defined yet * Improve tests for fromJSON instantiation in ContextActivities --- src/ContextActivities.php | 23 ++++------------------- tests/ContextActivitiesTest.php | 28 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/ContextActivities.php b/src/ContextActivities.php index 1b618a9..5472701 100644 --- a/src/ContextActivities.php +++ b/src/ContextActivities.php @@ -21,10 +21,10 @@ class ContextActivities implements VersionableInterface { use ArraySetterTrait, FromJSONTrait; - protected $category; - protected $parent; - protected $grouping; - protected $other; + protected $category = array(); + protected $parent = array(); + protected $grouping = array(); + protected $other = array(); private static $directProps = array( 'category', @@ -39,21 +39,6 @@ public function __construct() { $this->_fromArray($arg); } - - foreach ( - [ - 'category', - 'parent', - 'grouping', - 'other', - ] as $k - ) { - $method = 'set' . ucfirst($k); - - if (! isset($this->$k)) { - $this->$method(array()); - } - } } public function asVersion($version) { diff --git a/tests/ContextActivitiesTest.php b/tests/ContextActivitiesTest.php index 95cb981..42a9b63 100644 --- a/tests/ContextActivitiesTest.php +++ b/tests/ContextActivitiesTest.php @@ -31,15 +31,31 @@ public function testInstantiation() { } } - /* - // TODO: need to loop possible configs public function testFromJSONInstantiations() { - $obj = ContextActivities::fromJSON('{"mbox":"' . COMMON_GROUP_MBOX . '", "member":[{"mbox":"' . COMMON_MBOX . '"}]}'); + $common_activity = new TinCan\Activity(self::$common_activity_cfg); + + $all_json = array(); + foreach (self::$listProps as $k) { + $getMethod = 'get' . ucfirst($k); + + $prop_json = '"' . $k . '":[' . json_encode($common_activity->asVersion('1.0.0')) . ']'; + + array_push($all_json, $prop_json); + + $obj = ContextActivities::fromJSON('{' . $prop_json . '}'); + + $this->assertInstanceOf('TinCan\ContextActivities', $obj); + $this->assertEquals([$common_activity], $obj->$getMethod(), "$k list"); + } + + $obj = ContextActivities::fromJSON('{' . join(",", $all_json) . "}"); + $this->assertInstanceOf('TinCan\ContextActivities', $obj); - $this->assertSame(COMMON_GROUP_MBOX, $obj->getMbox(), 'mbox value'); - $this->assertEquals([['mbox' => COMMON_MBOX]], $obj->getMember(), 'member list'); + $this->assertEquals([$common_activity], $obj->getCategory(), "all props: category list"); + $this->assertEquals([$common_activity], $obj->getParent(), "all props: parent list"); + $this->assertEquals([$common_activity], $obj->getGrouping(), "all props: grouping list"); + $this->assertEquals([$common_activity], $obj->getOther(), "all props: other list"); } - */ // TODO: need to loop versions public function testAsVersion() {