1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMWDataItem; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Base class for SMW\DataItem tests. |
9
|
|
|
* |
10
|
|
|
* @group SMW |
11
|
|
|
* @group SMWExtension |
12
|
|
|
* @group SMWDataItems |
13
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
abstract class DataItemTest extends MwDBaseUnitTestCase { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Returns the name of the \SMW\DataItem deriving class this test tests. |
21
|
|
|
* |
22
|
|
|
* @since 1.8 |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public abstract function getClass(); |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @since 1.8 |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public abstract function constructorProvider(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creates and returns a new instance of the data item. |
37
|
|
|
* |
38
|
|
|
* @since 1.8 |
39
|
|
|
* |
40
|
|
|
* @return SMWDataItem |
41
|
|
|
*/ |
42
|
|
|
public function newInstance() { |
43
|
|
|
$reflector = new \ReflectionClass( $this->getClass() ); |
44
|
|
|
$args = func_get_args(); |
45
|
|
|
$instance = $reflector->newInstanceArgs( $args ); |
46
|
|
|
return $instance; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @since 1.8 |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function instanceProvider() { |
55
|
|
|
$phpFails = array( $this, 'newInstance' ); |
56
|
|
|
|
57
|
|
|
return array_map( |
58
|
|
|
function( array $args ) use ( $phpFails ) { |
59
|
|
|
return array( call_user_func_array( $phpFails, $args ) ); |
60
|
|
|
}, |
61
|
|
|
$this->constructorProvider() |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider constructorProvider |
67
|
|
|
* |
68
|
|
|
* @since 1.8 |
69
|
|
|
*/ |
70
|
|
|
public function testConstructor() { |
71
|
|
|
$dataItem = call_user_func_array( |
72
|
|
|
array( $this, 'newInstance' ), |
73
|
|
|
func_get_args() |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->assertInstanceOf( '\SMWDataItem', $dataItem ); |
77
|
|
|
$this->assertInstanceOf( $this->getClass(), $dataItem ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @dataProvider instanceProvider |
82
|
|
|
* |
83
|
|
|
* @since 1.8 |
84
|
|
|
* |
85
|
|
|
* @param \SMWDataItem $dataItem |
86
|
|
|
*/ |
87
|
|
|
public function testSerialization( \SMWDataItem $dataItem ) { |
88
|
|
|
$class = $this->getClass(); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( |
91
|
|
|
$dataItem, |
92
|
|
|
$class::doUnserialize( $dataItem->getSerialization() ) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @dataProvider instanceProvider |
98
|
|
|
*/ |
99
|
|
|
public function testInstanceEqualsItself( SMWDataItem $di ) { |
100
|
|
|
$this->assertTrue( $di->equals( $di ) ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @dataProvider instanceProvider |
105
|
|
|
*/ |
106
|
|
|
public function testInstanceDoesNotEqualNyanData( SMWDataItem $di ) { |
107
|
|
|
$this->assertFalse( $di->equals( new \SMWDIBlob( '~=[,,_,,]:3' ) ) ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|