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