-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPrefixedEntityIdParserTest.php
More file actions
57 lines (48 loc) · 2.09 KB
/
PrefixedEntityIdParserTest.php
File metadata and controls
57 lines (48 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Wikibase\DataModel\Services\Tests\EntityId;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\DataModel\Entity\EntityIdParsingException;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Services\EntityId\PrefixedEntityIdParser;
/**
* @covers Wikibase\DataModel\Services\EntityId\PrefixedEntityIdParser
*
* @license GPL-2.0+
* @author Daniel Kinzler
*/
class PrefixedEntityIdParserTest extends \PHPUnit_Framework_TestCase {
public function validInputProvider() {
return [
'base URI' => [ 'http://acme.test/entity/', 'http://acme.test/entity/Q14', new ItemId( 'Q14' ) ],
'interwiki prefix' => [ 'wikidata:', 'wikidata:P14', new PropertyId( 'P14' ) ],
];
}
/**
* @dataProvider validInputProvider
*/
public function testParse( $prefix, $input, $expected ) {
$parser = new PrefixedEntityIdParser( $prefix, new BasicEntityIdParser() );
$this->assertEquals( $expected, $parser->parse( $input ) );
}
public function invalidInputProvider() {
return [
'mismatching prefix' => [ 'http://acme.test/entity/', 'http://www.wikidata.org/entity/Q14' ],
'incomplete prefix' => [ 'http://acme.test/entity/', 'http://acme.test/Q14' ],
'bad ID after prefix' => [ 'http://acme.test/entity/', 'http://acme.test/entity/XYYZ' ],
'extra stuff after ID' => [ 'http://acme.test/entity/', 'http://acme.test/entity/Q14#foo' ],
'input is shorter than prefix' => [ 'http://acme.test/entity/', 'http://acme.test/' ],
'input is same as prefix' => [ 'http://acme.test/entity/', 'http://acme.test/entity/' ],
'input is lexicographically smaller than prefix' => [ 'http://acme.test/entity/', 'http://aaaa.test/entity/Q14' ],
'input is lexicographically greater than prefix' => [ 'http://acme.test/entity/', 'http://cccc.test/entity/Q14' ],
];
}
/**
* @dataProvider invalidInputProvider
*/
public function testParse_invalid( $prefix, $input ) {
$parser = new PrefixedEntityIdParser( $prefix, new BasicEntityIdParser() );
$this->setExpectedException( EntityIdParsingException::class );
$parser->parse( $input );
}
}