diff --git a/composer.json b/composer.json index 7786424..0dae765 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "phpdocumentor/phpdocumentor": "2.*", - "phpunit/phpunit": "@stable" + "phpunit/phpunit": "^5.7" }, "autoload": { "psr-4": { diff --git a/src/Agent.php b/src/Agent.php index 8bed2bd..dbf6e78 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -54,14 +54,11 @@ public function asVersion($version) { if (! empty($versioned_acct)) { $result['account'] = $versioned_acct; } - } - elseif (isset($this->mbox_sha1sum)) { + } else if (isset($this->mbox_sha1sum)) { $result['mbox_sha1sum'] = $this->mbox_sha1sum; - } - elseif (isset($this->mbox)) { + } else if (isset($this->mbox)) { $result['mbox'] = $this->mbox; - } - elseif (isset($this->openid)) { + } else if (isset($this->openid)) { $result['openid'] = $this->openid; } @@ -149,6 +146,8 @@ public function getMbox_sha1sum() { if (isset($this->mbox)) { return sha1($this->mbox); } + + return false; } public function setOpenid($value) { $this->openid = $value; return $this; } public function getOpenid() { return $this->openid; } diff --git a/tests/AgentTest.php b/tests/AgentTest.php index a027de8..4e3a680 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -69,6 +69,20 @@ public function testAsVersionMbox() { $this->assertEquals($versioned, $args, "serialized version matches corrected"); } + // TODO: need to loop versions + public function testAsVersionOpenid() { + $args = [ + 'openid' => COMMON_OPENID + ]; + + $obj = Agent::fromJSON(json_encode($args, JSON_UNESCAPED_SLASHES)); + $versioned = $obj->asVersion('1.0.0'); + + $args['objectType'] = 'Agent'; + + $this->assertEquals($versioned, $args, "serialized version matches corrected"); + } + public function testAsVersionMboxSha1() { $args = [ 'mbox_sha1sum' => COMMON_MBOX_SHA1 @@ -201,6 +215,9 @@ public function testGetMbox_sha1sum() { $obj = new Agent(['mbox' => COMMON_MBOX]); $this->assertSame($obj->getMbox_sha1sum(), COMMON_MBOX_SHA1, 'sha1 from mbox'); + + $obj = new Agent(); + $this->assertSame($obj->getMbox_sha1sum(), false, 'no mbox at all'); } public function testCompareWithSignature() { @@ -299,6 +316,18 @@ public function testCompareWithSignature() { 'sigArgs' => ['account' => $acct2 ], 'reason' => 'Comparison of account failed: Comparison of name failed: value is not the same' ], + [ + 'description' => 'missing object account', + 'objArgs' => [], + 'sigArgs' => ['account' => $acct2 ], + 'reason' => 'Comparison of account failed: value not in this' + ], + [ + 'description' => 'missing signature account', + 'objArgs' => ['account' => $acct1 ], + 'sigArgs' => [], + 'reason' => 'Comparison of account failed: value not in signature' + ], // // special cases where we can try to equate an mbox and an mbox SHA1 sum diff --git a/tests/PersonTest.php b/tests/PersonTest.php index bceb7e8..9b458b2 100644 --- a/tests/PersonTest.php +++ b/tests/PersonTest.php @@ -59,6 +59,9 @@ public function testAsVersion() { $obj = new Person( [ 'mbox' => array(COMMON_MBOX), + 'name' => COMMON_NAME, + 'openid' => COMMON_OPENID, + 'mbox_sha1sum' => COMMON_MBOX_SHA1, 'account' => array( array( 'name' => COMMON_ACCT_NAME, @@ -73,6 +76,9 @@ public function testAsVersion() { [ 'objectType' => 'Person', 'mbox' => array(COMMON_MBOX), + 'name' => COMMON_NAME, + 'openid' => COMMON_OPENID, + 'mbox_sha1sum' => COMMON_MBOX_SHA1, 'account' => array( array( 'name' => COMMON_ACCT_NAME,