|
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\Serializer\Tests; |
|
13
|
|
|
|
|
14
|
|
|
use Xabbuh\XApi\DataFixtures\StatementFixtures; |
|
15
|
|
|
use Xabbuh\XApi\Model\Statement; |
|
16
|
|
|
use Xabbuh\XApi\Serializer\StatementSerializer; |
|
17
|
|
|
use Xabbuh\XApi\Serializer\Tests\Fixtures\StatementJsonFixtures; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Christian Flothmann <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class StatementSerializerTest extends AbstractSerializerTest |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var StatementSerializer |
|
26
|
|
|
*/ |
|
27
|
|
|
private $statementSerializer; |
|
28
|
|
|
|
|
29
|
|
|
protected function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
parent::setUp(); |
|
32
|
|
|
$this->statementSerializer = new StatementSerializer($this->serializer); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @dataProvider statementProvider |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $serializedStatement |
|
39
|
|
|
* @param Statement $expectedStatement |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testDeserializeStatement($serializedStatement, Statement $expectedStatement) |
|
42
|
|
|
{ |
|
43
|
|
|
$statement = $this->statementSerializer->deserializeStatement($serializedStatement); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertTrue($expectedStatement->equals($statement)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @dataProvider statementProvider |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $expectedStatement |
|
52
|
|
|
* @param Statement $statement |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testSerializeStatement($expectedStatement, Statement $statement) |
|
55
|
|
|
{ |
|
56
|
|
|
$serializedStatement = $this->statementSerializer->serializeStatement($statement); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertJsonEquals($expectedStatement, $serializedStatement); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function statementProvider() |
|
62
|
|
|
{ |
|
63
|
|
|
return array( |
|
64
|
|
|
'minimal-statement' => array( |
|
65
|
|
|
StatementJsonFixtures::getMinimalStatement(), |
|
66
|
|
|
StatementFixtures::getMinimalStatement(), |
|
67
|
|
|
), |
|
68
|
|
|
'statement-reference' => array( |
|
69
|
|
|
StatementJsonFixtures::getStatementWithStatementRef(), |
|
70
|
|
|
StatementFixtures::getStatementWithStatementRef(), |
|
71
|
|
|
), |
|
72
|
|
|
'statement-with-sub-statement' => array( |
|
73
|
|
|
StatementJsonFixtures::getStatementWithSubStatement(), |
|
74
|
|
|
StatementFixtures::getStatementWithSubStatement(), |
|
75
|
|
|
), |
|
76
|
|
|
'statement-with-result' => array( |
|
77
|
|
|
StatementJsonFixtures::getStatementWithResult(), |
|
78
|
|
|
StatementFixtures::getStatementWithResult(), |
|
79
|
|
|
), |
|
80
|
|
|
'statement-with-agent-authority' => array( |
|
81
|
|
|
StatementJsonFixtures::getStatementWithAgentAuthority(), |
|
82
|
|
|
StatementFixtures::getStatementWithAgentAuthority(), |
|
83
|
|
|
), |
|
84
|
|
|
'statement-with-group-authority' => array( |
|
85
|
|
|
StatementJsonFixtures::getStatementWithGroupAuthority(), |
|
86
|
|
|
StatementFixtures::getStatementWithGroupAuthority(), |
|
87
|
|
|
), |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testDeserializeStatementCollection() |
|
92
|
|
|
{ |
|
93
|
|
|
/** @var \Xabbuh\XApi\Model\Statement[] $statements */ |
|
94
|
|
|
$statements = $this->statementSerializer->deserializeStatements( |
|
95
|
|
|
StatementJsonFixtures::getStatementCollection() |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertTrue(is_array($statements)); |
|
99
|
|
|
$this->assertCount(2, $statements); |
|
100
|
|
|
$this->assertEquals( |
|
101
|
|
|
'12345678-1234-5678-8234-567812345678', |
|
102
|
|
|
$statements[0]->getId() |
|
103
|
|
|
); |
|
104
|
|
|
$this->assertEquals( |
|
105
|
|
|
'12345678-1234-5678-8234-567812345679', |
|
106
|
|
|
$statements[1]->getId() |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|