Skip to content

Commit 0a2b5e7

Browse files
committed
Merge pull request #12 from brianjmiller/master
Fixes for Group and ContextActivities
2 parents f82f2ab + bceec14 commit 0a2b5e7

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"tincan",
99
"xapi",
1010
"experience api",
11-
"e-learning"
11+
"e-learning",
12+
"scorm"
1213
],
1314
"license": "Apache-2.0",
1415
"authors": [

src/ContextActivities.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ContextActivities implements VersionableInterface
2121
{
2222
use ArraySetterTrait, FromJSONTrait;
2323

24-
protected $category;
25-
protected $parent;
26-
protected $grouping;
27-
protected $other;
24+
protected $category = array();
25+
protected $parent = array();
26+
protected $grouping = array();
27+
protected $other = array();
2828

2929
private static $directProps = array(
3030
'category',
@@ -39,21 +39,6 @@ public function __construct() {
3939

4040
$this->_fromArray($arg);
4141
}
42-
43-
foreach (
44-
[
45-
'category',
46-
'parent',
47-
'grouping',
48-
'other',
49-
] as $k
50-
) {
51-
$method = 'set' . ucfirst($k);
52-
53-
if (! isset($this->$k)) {
54-
$this->$method(array());
55-
}
56-
}
5742
}
5843

5944
public function asVersion($version) {

src/Group.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function asVersion($version) {
4646
}
4747

4848
public function setMember($value) {
49-
foreach ($value as $k) {
50-
if (! $value[$k] instanceof Agent) {
51-
$value[$k] = new Agent($value[$k]);
49+
foreach ($value as $k => $v) {
50+
if (! $v instanceof Agent) {
51+
$value[$k] = new Agent($v);
5252
}
5353
}
5454

tests/ContextActivitiesTest.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,31 @@ public function testInstantiation() {
3131
}
3232
}
3333

34-
/*
35-
// TODO: need to loop possible configs
3634
public function testFromJSONInstantiations() {
37-
$obj = ContextActivities::fromJSON('{"mbox":"' . COMMON_GROUP_MBOX . '", "member":[{"mbox":"' . COMMON_MBOX . '"}]}');
35+
$common_activity = new TinCan\Activity(self::$common_activity_cfg);
36+
37+
$all_json = array();
38+
foreach (self::$listProps as $k) {
39+
$getMethod = 'get' . ucfirst($k);
40+
41+
$prop_json = '"' . $k . '":[' . json_encode($common_activity->asVersion('1.0.0')) . ']';
42+
43+
array_push($all_json, $prop_json);
44+
45+
$obj = ContextActivities::fromJSON('{' . $prop_json . '}');
46+
47+
$this->assertInstanceOf('TinCan\ContextActivities', $obj);
48+
$this->assertEquals([$common_activity], $obj->$getMethod(), "$k list");
49+
}
50+
51+
$obj = ContextActivities::fromJSON('{' . join(",", $all_json) . "}");
52+
3853
$this->assertInstanceOf('TinCan\ContextActivities', $obj);
39-
$this->assertSame(COMMON_GROUP_MBOX, $obj->getMbox(), 'mbox value');
40-
$this->assertEquals([['mbox' => COMMON_MBOX]], $obj->getMember(), 'member list');
54+
$this->assertEquals([$common_activity], $obj->getCategory(), "all props: category list");
55+
$this->assertEquals([$common_activity], $obj->getParent(), "all props: parent list");
56+
$this->assertEquals([$common_activity], $obj->getGrouping(), "all props: grouping list");
57+
$this->assertEquals([$common_activity], $obj->getOther(), "all props: other list");
4158
}
42-
*/
4359

4460
// TODO: need to loop versions
4561
public function testAsVersion() {

tests/RemoteLRSTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ public function testRetrieveActivityProfile() {
199199
);
200200

201201
$this->assertInstanceOf('TinCan\LRSResponse', $response);
202-
print_r($response->httpResponse['headers']);
203-
print "\n\n";
204-
print_r($response->content);
205202
}
206203

207204
public function testSaveActivityProfile() {

tests/StatementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,6 @@ public function testAsVersion() {
150150

151151
$versioned = $obj->asVersion('1.0.0');
152152

153-
print json_encode($versioned, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
153+
//print json_encode($versioned, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
154154
}
155155
}

0 commit comments

Comments
 (0)