1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model\Tests; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Model\Account; |
15
|
|
|
use Xabbuh\XApi\Model\Activity; |
16
|
|
|
use Xabbuh\XApi\Model\Agent; |
17
|
|
|
use Xabbuh\XApi\Model\Group; |
18
|
|
|
use Xabbuh\XApi\Model\Statement; |
19
|
|
|
use Xabbuh\XApi\Model\Verb; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Christian Flothmann <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class StatementTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
public function testGetStatementReference() |
27
|
|
|
{ |
28
|
|
|
$statement = new Statement( |
29
|
|
|
'e05aa883-acaf-40ad-bf54-02c8ce485fb0', |
30
|
|
|
new Agent(), |
31
|
|
|
new Verb('the-verb-id'), |
32
|
|
|
new Activity() |
33
|
|
|
); |
34
|
|
|
$statementReference = $statement->getStatementReference(); |
35
|
|
|
|
36
|
|
|
$this->assertInstanceOf('\Xabbuh\XApi\Model\StatementReference', $statementReference); |
37
|
|
|
$this->assertEquals( |
38
|
|
|
'e05aa883-acaf-40ad-bf54-02c8ce485fb0', |
39
|
|
|
$statementReference->getStatementId() |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetVoidStatement() |
44
|
|
|
{ |
45
|
|
|
$actor = new Agent('mailto:[email protected]'); |
46
|
|
|
$statement = new Statement( |
47
|
|
|
'e05aa883-acaf-40ad-bf54-02c8ce485fb0', |
48
|
|
|
$actor, |
49
|
|
|
new Verb('verb-id'), |
50
|
|
|
new Activity() |
51
|
|
|
); |
52
|
|
|
$voidStatement = $statement->getVoidStatement($actor); |
53
|
|
|
|
54
|
|
|
/** @var \Xabbuh\XApi\Model\StatementReference $statementReference */ |
55
|
|
|
$statementReference = $voidStatement->getObject(); |
56
|
|
|
|
57
|
|
|
$this->assertEquals($actor, $voidStatement->getActor()); |
58
|
|
|
$this->assertTrue($voidStatement->getVerb()->isVoidVerb()); |
59
|
|
|
$this->assertInstanceOf('\Xabbuh\XApi\Model\StatementReference', $statementReference); |
60
|
|
|
$this->assertEquals( |
61
|
|
|
'e05aa883-acaf-40ad-bf54-02c8ce485fb0', |
62
|
|
|
$statementReference->getStatementId() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testWithAuthority() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$statement = $this->createMinimalStatement(); |
69
|
|
|
$authority = $this->createAgent(); |
70
|
|
|
$statementWithAuthority = $statement->withAuthority($authority); |
71
|
|
|
|
72
|
|
|
$this->assertFalse($statement->equals($statementWithAuthority)); |
73
|
|
|
$this->assertNull($statement->getAuthority()); |
74
|
|
|
$this->assertSame($statement->getId(), $statementWithAuthority->getId()); |
75
|
|
|
$this->assertTrue($statement->getActor()->equals($statementWithAuthority->getActor())); |
76
|
|
|
$this->assertTrue($statement->getVerb()->equals($statementWithAuthority->getVerb())); |
77
|
|
|
$this->assertTrue($statement->getObject()->equals($statementWithAuthority->getObject())); |
78
|
|
|
$this->assertTrue($authority->equals($statementWithAuthority->getAuthority())); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function testWithAuthorityReplacesExistingAuthority() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$statement = $this->createStatementWithGroupAuthority(); |
84
|
|
|
$agentAuthority = $this->createAgent(); |
85
|
|
|
$statementWithAuthority = $statement->withAuthority($agentAuthority); |
86
|
|
|
|
87
|
|
|
$this->assertFalse($statement->equals($statementWithAuthority)); |
88
|
|
|
$this->assertSame($statement->getId(), $statementWithAuthority->getId()); |
89
|
|
|
$this->assertTrue($statement->getActor()->equals($statementWithAuthority->getActor())); |
90
|
|
|
$this->assertTrue($statement->getVerb()->equals($statementWithAuthority->getVerb())); |
91
|
|
|
$this->assertTrue($statement->getObject()->equals($statementWithAuthority->getObject())); |
92
|
|
|
$this->assertTrue($agentAuthority->equals($statementWithAuthority->getAuthority())); |
93
|
|
|
$this->assertFalse($statement->getAuthority()->equals($statementWithAuthority->getAuthority())); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private function createMinimalStatement() |
97
|
|
|
{ |
98
|
|
|
$actor = new Agent('mailto:[email protected]'); |
99
|
|
|
$verb = new Verb('http://adlnet.gov/expapi/verbs/created', array('en-US' => 'created')); |
100
|
|
|
$activity = new Activity('http://example.adlnet.gov/xapi/example/activity'); |
101
|
|
|
|
102
|
|
|
return new Statement('12345678-1234-5678-8234-567812345678', $actor, $verb, $activity); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
private function createStatementWithGroupAuthority() |
106
|
|
|
{ |
107
|
|
|
$actor = new Agent('mailto:[email protected]'); |
108
|
|
|
$verb = new Verb('http://adlnet.gov/expapi/verbs/created', array('en-US' => 'created')); |
109
|
|
|
$activity = new Activity('http://example.adlnet.gov/xapi/example/activity'); |
110
|
|
|
$user = new Agent(null, null, null, new Account('oauth_consumer_x75db', 'http://example.com/xAPI/OAuth/Token')); |
111
|
|
|
$application = new Agent('mailto:[email protected]'); |
112
|
|
|
$authority = new Group(null, null, null, null, null, array($user, $application)); |
113
|
|
|
|
114
|
|
|
return new Statement('12345678-1234-5678-8234-567812345678', $actor, $verb, $activity, null, $authority); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
private function createAgent() |
118
|
|
|
{ |
119
|
|
|
return new Agent('mailto:[email protected]', null, null, null, 'Christian'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.