1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Tests\Entity; |
4
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
6
|
|
|
use Wikibase\DataModel\Entity\EntityRedirect; |
7
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
8
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers Wikibase\DataModel\Entity\EntityRedirect |
12
|
|
|
* |
13
|
|
|
* @group Wikibase |
14
|
|
|
* @group WikibaseDataModel |
15
|
|
|
* |
16
|
|
|
* @licence GNU GPL v2+ |
17
|
|
|
* @author Daniel Kinzler |
18
|
|
|
*/ |
19
|
|
|
class EntityRedirectTest extends \PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
public function testConstruction() { |
22
|
|
|
$entityId = new ItemId( 'Q123' ); |
23
|
|
|
$targetId = new ItemId( 'Q345' ); |
24
|
|
|
|
25
|
|
|
$redirect = new EntityRedirect( $entityId, $targetId ); |
26
|
|
|
|
27
|
|
|
$this->assertEquals( $entityId, $redirect->getEntityId(), '$redirect->getEntityId()' ); |
28
|
|
|
$this->assertEquals( $targetId, $redirect->getTargetId(), '$redirect->getTargetId()' ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testConstruction_baseType() { |
32
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
33
|
|
|
|
34
|
|
|
$entityId = new ItemId( 'Q123' ); |
35
|
|
|
$targetId = new PropertyId( 'P345' ); |
36
|
|
|
|
37
|
|
|
new EntityRedirect( $entityId, $targetId ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @dataProvider selfRedirectProvider |
42
|
|
|
*/ |
43
|
|
|
public function testConstruction_selfRedirect( EntityId $entityId, EntityId $targetId ) { |
44
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
45
|
|
|
new EntityRedirect( $entityId, $targetId ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function selfRedirectProvider() { |
49
|
|
|
$entityId = new ItemId( 'Q1' ); |
50
|
|
|
|
51
|
|
|
return array( |
52
|
|
|
'same object' => array( $entityId, $entityId ), |
53
|
|
|
'different objects' => array( $entityId, new ItemId( 'Q1' ) ), |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function equalsProvider() { |
58
|
|
|
$q123 = new ItemId( 'Q123' ); |
59
|
|
|
$q345 = new ItemId( 'Q345' ); |
60
|
|
|
$q567 = new ItemId( 'Q567' ); |
61
|
|
|
$q123_345 = new EntityRedirect( $q123, $q345 ); |
62
|
|
|
|
63
|
|
|
$p123 = new PropertyId( 'P123' ); |
64
|
|
|
$p345 = new PropertyId( 'P345' ); |
65
|
|
|
$p123_345 = new EntityRedirect( $p123, $p345 ); |
66
|
|
|
|
67
|
|
|
return array( |
68
|
|
|
'same' => array( $q123_345, $q123_345, true ), |
69
|
|
|
'equal' => array( $q123_345, new EntityRedirect( $q123, $q345 ), true ), |
70
|
|
|
|
71
|
|
|
'different base' => array( $q123_345, new EntityRedirect( $q567, $q345 ), false ), |
72
|
|
|
'different target' => array( $q123_345, new EntityRedirect( $q123, $q567 ), false ), |
73
|
|
|
|
74
|
|
|
'different entity type' => array( $q123_345, $p123_345, false ), |
75
|
|
|
'different number' => array( $q123_345, new EntityRedirect( $q345, $q123 ), false ), |
76
|
|
|
|
77
|
|
|
'null' => array( $q123_345, null, false ), |
78
|
|
|
'string' => array( $q123_345, 'foo', false ), |
79
|
|
|
'id' => array( $q123_345, $q123, false ), |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @dataProvider equalsProvider |
85
|
|
|
* |
86
|
|
|
* @param EntityRedirect $a |
87
|
|
|
* @param mixed $b |
88
|
|
|
* @param bool $expected |
89
|
|
|
*/ |
90
|
|
|
public function testEquals( $a, $b, $expected ) { |
91
|
|
|
$this->assertEquals( $expected, $a->equals( $b ), '$a->equals( $b )' ); |
92
|
|
|
|
93
|
|
|
if ( $b instanceof EntityRedirect ) { |
94
|
|
|
$this->assertEquals( $expected, $b->equals( $a ), '$b->equals( $a )' ); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|