1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Tests\Entity; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
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
|
|
|
* @license GPL-2.0-or-later |
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->expectException( InvalidArgumentException::class ); |
33
|
|
|
|
34
|
|
|
$entityId = new ItemId( 'Q123' ); |
35
|
|
|
$targetId = new PropertyId( 'P345' ); |
36
|
|
|
|
37
|
|
|
new EntityRedirect( $entityId, $targetId ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testConstruction_sameEntity() { |
41
|
|
|
$this->expectException( InvalidArgumentException::class ); |
42
|
|
|
|
43
|
|
|
$entityId = new ItemId( 'Q123' ); |
44
|
|
|
$targetId = new ItemId( 'Q123' ); |
45
|
|
|
|
46
|
|
|
new EntityRedirect( $entityId, $targetId ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function equalsProvider() { |
50
|
|
|
$q123 = new ItemId( 'Q123' ); |
51
|
|
|
$q345 = new ItemId( 'Q345' ); |
52
|
|
|
$q567 = new ItemId( 'Q567' ); |
53
|
|
|
$q123_345 = new EntityRedirect( $q123, $q345 ); |
54
|
|
|
|
55
|
|
|
$p123 = new PropertyId( 'P123' ); |
56
|
|
|
$p345 = new PropertyId( 'P345' ); |
57
|
|
|
$p123_345 = new EntityRedirect( $p123, $p345 ); |
58
|
|
|
|
59
|
|
|
return [ |
60
|
|
|
'same' => [ $q123_345, $q123_345, true ], |
61
|
|
|
'equal' => [ $q123_345, new EntityRedirect( $q123, $q345 ), true ], |
62
|
|
|
|
63
|
|
|
'different base' => [ $q123_345, new EntityRedirect( $q567, $q345 ), false ], |
64
|
|
|
'different target' => [ $q123_345, new EntityRedirect( $q123, $q567 ), false ], |
65
|
|
|
|
66
|
|
|
'different entity type' => [ $q123_345, $p123_345, false ], |
67
|
|
|
'different number' => [ $q123_345, new EntityRedirect( $q345, $q123 ), false ], |
68
|
|
|
|
69
|
|
|
'null' => [ $q123_345, null, false ], |
70
|
|
|
'string' => [ $q123_345, 'foo', false ], |
71
|
|
|
'id' => [ $q123_345, $q123, false ], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @dataProvider equalsProvider |
77
|
|
|
* |
78
|
|
|
* @param EntityRedirect $a |
79
|
|
|
* @param mixed $b |
80
|
|
|
* @param bool $expected |
81
|
|
|
*/ |
82
|
|
|
public function testEquals( EntityRedirect $a, $b, $expected ) { |
83
|
|
|
$this->assertEquals( $expected, $a->equals( $b ), '$a->equals( $b )' ); |
84
|
|
|
|
85
|
|
|
if ( $b instanceof EntityRedirect ) { |
86
|
|
|
$this->assertEquals( $expected, $b->equals( $a ), '$b->equals( $a )' ); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testToString() { |
91
|
|
|
$redirect = new EntityRedirect( new ItemId( 'Q1' ), new ItemId( 'Q2' ) ); |
92
|
|
|
$this->assertSame( 'Q1->Q2', $redirect->__toString() ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|