|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Tests\Statement; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Wikibase\DataModel\Statement\StatementGuid; |
|
7
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
|
8
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers Wikibase\DataModel\Statement\StatementGuid |
|
12
|
|
|
* |
|
13
|
|
|
* @group Wikibase |
|
14
|
|
|
* @group WikibaseDataModel |
|
15
|
|
|
* @group ClaimGuidTest |
|
16
|
|
|
* |
|
17
|
|
|
* @licence GNU GPL v2+ |
|
18
|
|
|
* @author Addshore |
|
19
|
|
|
*/ |
|
20
|
|
|
class StatementGuidTest extends \PHPUnit_Framework_TestCase { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider provideConstructionData |
|
24
|
|
|
* @param EntityId $entityId |
|
25
|
|
|
* @param string $guid |
|
26
|
|
|
* @param string $expected |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testConstructor( EntityId $entityId, $guid, $expected ) { |
|
29
|
|
|
$statementGuid = new StatementGuid( $entityId, $guid ); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals( $expected, $statementGuid->getSerialization() ); |
|
32
|
|
|
$this->assertEquals( $entityId, $statementGuid->getEntityId() ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function provideConstructionData() { |
|
36
|
|
|
$argLists = array(); |
|
37
|
|
|
|
|
38
|
|
|
$argLists[] = array( |
|
39
|
|
|
new ItemId( 'q42' ), |
|
40
|
|
|
'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' , |
|
41
|
|
|
'Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0N' |
|
42
|
|
|
); |
|
43
|
|
|
$argLists[] = array( |
|
44
|
|
|
new ItemId( 'Q1234567' ), |
|
45
|
|
|
'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF', |
|
46
|
|
|
'Q1234567$D4FDE516-F20C-4154-ADCE-7C5B609DFDFF' |
|
47
|
|
|
); |
|
48
|
|
|
$argLists[] = array( |
|
49
|
|
|
new ItemId( 'Q1' ), |
|
50
|
|
|
'foo', |
|
51
|
|
|
'Q1$foo' |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
return $argLists; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @dataProvider provideBadConstruction |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testBadConstruction( $entityId, $guid ) { |
|
61
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
|
|
|
|
|
|
62
|
|
|
new StatementGuid( $entityId, $guid ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function provideBadConstruction() { |
|
66
|
|
|
$argLists = array(); |
|
67
|
|
|
|
|
68
|
|
|
$argLists[] = array( 'foobar', 'foobar' ); |
|
69
|
|
|
$argLists[] = array( 'q123', 'foo' ); |
|
70
|
|
|
$argLists[] = array( array(), 'foo' ); |
|
71
|
|
|
$argLists[] = array( new Exception(), 'foo' ); |
|
72
|
|
|
$argLists[] = array( 'bar', 12345 ); |
|
73
|
|
|
|
|
74
|
|
|
return $argLists; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function provideStatementGuids() { |
|
78
|
|
|
$constructionDatas = $this->provideConstructionData(); |
|
79
|
|
|
$argLists = array(); |
|
80
|
|
|
|
|
81
|
|
|
foreach ( $constructionDatas as $constructionData ) { |
|
82
|
|
|
$argLists[] = array( new StatementGuid( $constructionData[0], $constructionData[1] ) ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $argLists; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @dataProvider provideStatementGuids |
|
90
|
|
|
* |
|
91
|
|
|
* @param StatementGuid $statementGuid |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testEquals( StatementGuid $statementGuid ) { |
|
94
|
|
|
$statementGuidCopy = clone $statementGuid; |
|
95
|
|
|
$this->assertTrue( $statementGuid->equals( $statementGuidCopy ) ); |
|
96
|
|
|
$this->assertTrue( $statementGuidCopy->equals( $statementGuid ) ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @dataProvider provideStatementGuids |
|
101
|
|
|
* |
|
102
|
|
|
* @param StatementGuid $statementGuid |
|
103
|
|
|
*/ |
|
104
|
|
|
public function testNotEquals( StatementGuid $statementGuid ) { |
|
105
|
|
|
$notEqualStatementGuid = new StatementGuid( new ItemId( 'q9999' ), 'someguid' ); |
|
106
|
|
|
$this->assertFalse( $statementGuid->equals( $notEqualStatementGuid ) ); |
|
107
|
|
|
$this->assertFalse( $notEqualStatementGuid->equals( $statementGuid ) ); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.