|
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\Document; |
|
15
|
|
|
use Xabbuh\XApi\Model\DocumentData; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Christian Flothmann <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class AbstractDocumentTest extends \PHPUnit_Framework_TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testReadyOnlyArrayAccessMethods() |
|
23
|
|
|
{ |
|
24
|
|
|
$data = new DocumentData(); |
|
25
|
|
|
$document = $this->createDocument($data); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertFalse(isset($document['x'])); |
|
28
|
|
|
|
|
29
|
|
|
$data = new DocumentData(array('x' => 'foo', 'y' => 'bar')); |
|
30
|
|
|
$document = $this->createDocument($data); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertTrue(isset($document['x'])); |
|
33
|
|
|
$this->assertEquals('foo', $document['x']); |
|
34
|
|
|
$this->assertTrue(isset($document['y'])); |
|
35
|
|
|
$this->assertEquals('bar', $document['y']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @expectedException \Xabbuh\XApi\Common\Exception\UnsupportedOperationException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testSettingDataThrowsException() |
|
42
|
|
|
{ |
|
43
|
|
|
$data = new DocumentData(); |
|
44
|
|
|
$document = $this->createDocument($data); |
|
45
|
|
|
$document['x'] = 'bar'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @expectedException \Xabbuh\XApi\Common\Exception\UnsupportedOperationException |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testRemovingDataThrowsException() |
|
52
|
|
|
{ |
|
53
|
|
|
$data = new DocumentData(array('x' => 'foo', 'y' => 'bar')); |
|
54
|
|
|
$document = $this->createDocument($data); |
|
55
|
|
|
unset($document['x']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testGetData() |
|
59
|
|
|
{ |
|
60
|
|
|
$data = new DocumentData(array('x' => 'foo', 'y' => 'bar')); |
|
61
|
|
|
$document = $this->createDocument($data); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertSame($data, $document->getData()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param DocumentData $data |
|
68
|
|
|
* |
|
69
|
|
|
* @return Document |
|
70
|
|
|
*/ |
|
71
|
|
|
abstract protected function createDocument(DocumentData $data); |
|
72
|
|
|
} |
|
73
|
|
|
|