1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Statement; |
4
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Entity\BasicEntityIdParser; |
6
|
|
|
use Wikibase\DataModel\Statement\StatementGuid; |
7
|
|
|
use Wikibase\DataModel\Services\Statement\StatementGuidParser; |
8
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers Wikibase\DataModel\Services\Statement\StatementGuidParser |
12
|
|
|
* |
13
|
|
|
* @licence GNU GPL v2+ |
14
|
|
|
* @author Adam Shorland |
15
|
|
|
*/ |
16
|
|
|
class StatementGuidParserTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @dataProvider guidProvider |
20
|
|
|
*/ |
21
|
|
|
public function testCanParseStatementGuid( StatementGuid $expected ) { |
22
|
|
|
$actual = $this->newParser()->parse( $expected->getSerialization() ); |
23
|
|
|
|
24
|
|
|
$this->assertEquals( $actual, $expected ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function newParser() { |
28
|
|
|
return new StatementGuidParser( new BasicEntityIdParser() ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function guidProvider() { |
32
|
|
|
return array( |
33
|
|
|
array( new StatementGuid( new ItemId( 'q42' ), 'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ) ), |
34
|
|
|
array( new StatementGuid( new ItemId( 'Q1234567' ), 'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF' ) ), |
35
|
|
|
array( new StatementGuid( new ItemId( 'Q1' ), 'foo' ) ), |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider invalidIdSerializationProvider |
41
|
|
|
*/ |
42
|
|
|
public function testCannotParserInvalidId( $invalidIdSerialization ) { |
43
|
|
|
$this->setExpectedException( 'Wikibase\DataModel\Services\Statement\StatementGuidParsingException' ); |
44
|
|
|
$this->newParser()->parse( $invalidIdSerialization ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function invalidIdSerializationProvider() { |
48
|
|
|
return array( |
49
|
|
|
array( 'FOO' ), |
50
|
|
|
array( null ), |
51
|
|
|
array( 42 ), |
52
|
|
|
array( array() ), |
53
|
|
|
array( '' ), |
54
|
|
|
array( 'q0' ), |
55
|
|
|
array( '1p' ), |
56
|
|
|
array( 'Q0$5627445f-43cb-ed6d-3adb-760e85bd17ee' ), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|