|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Entity\BasicEntityIdParser; |
|
6
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
|
7
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
8
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers Wikibase\DataModel\Entity\BasicEntityIdParser |
|
12
|
|
|
* |
|
13
|
|
|
* @licence GNU GPL v2+ |
|
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
15
|
|
|
* @author Thiemo Mättig |
|
16
|
|
|
*/ |
|
17
|
|
|
class BasicEntityIdParserTest extends \PHPUnit_Framework_TestCase { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @dataProvider entityIdProvider |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testCanParseEntityId( $idString, EntityId $expected ) { |
|
23
|
|
|
$parser = new BasicEntityIdParser(); |
|
24
|
|
|
$actual = $parser->parse( $idString ); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals( $actual, $expected ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function entityIdProvider() { |
|
30
|
|
|
return array( |
|
31
|
|
|
array( 'q42', new ItemId( 'q42' ) ), |
|
32
|
|
|
array( 'Q1337', new ItemId( 'Q1337' ) ), |
|
33
|
|
|
array( 'p1', new PropertyId( 'p1' ) ), |
|
34
|
|
|
array( 'P100000', new PropertyId( 'P100000' ) ), |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @dataProvider invalidIdSerializationProvider |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testCannotParseInvalidId( $invalidIdSerialization ) { |
|
42
|
|
|
$parser = new BasicEntityIdParser(); |
|
43
|
|
|
|
|
44
|
|
|
$this->setExpectedException( 'Wikibase\DataModel\Entity\EntityIdParsingException' ); |
|
45
|
|
|
$parser->parse( $invalidIdSerialization ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function invalidIdSerializationProvider() { |
|
49
|
|
|
return array( |
|
50
|
|
|
array( 'FOO' ), |
|
51
|
|
|
array( null ), |
|
52
|
|
|
array( 42 ), |
|
53
|
|
|
array( array() ), |
|
54
|
|
|
array( '' ), |
|
55
|
|
|
array( 'q0' ), |
|
56
|
|
|
array( '1p' ), |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|