Skip to content

Commit

Permalink
Merge pull request #12 from brianjmiller/master
Browse files Browse the repository at this point in the history
Fixes for Group and ContextActivities
  • Loading branch information
bscSCORM committed Jul 23, 2014
2 parents f82f2ab + bceec14 commit 0a2b5e7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"tincan",
"xapi",
"experience api",
"e-learning"
"e-learning",
"scorm"
],
"license": "Apache-2.0",
"authors": [
Expand Down
23 changes: 4 additions & 19 deletions src/ContextActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
28 changes: 22 additions & 6 deletions tests/ContextActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions tests/RemoteLRSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0a2b5e7

Please sign in to comment.