File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Wikibase DataModel release notes
22
3+ ## Version 4.4.0 (2015-09-03)
4+
5+ * Added ` ItemIdParser `
6+
37## Version 4.3.0 (2015-09-02)
48
59* Added ` isEmpty ` to ` EntityDocument `
Original file line number Diff line number Diff line change 1212 return 1 ;
1313}
1414
15- define ( 'WIKIBASE_DATAMODEL_VERSION ' , '4.3 .0 ' );
15+ define ( 'WIKIBASE_DATAMODEL_VERSION ' , '4.4 .0 ' );
1616
1717if ( defined ( 'MEDIAWIKI ' ) ) {
1818 call_user_func ( function () {
Original file line number Diff line number Diff line change 4040 },
4141 "extra" : {
4242 "branch-alias" : {
43- "dev-master" : " 4.3 .x-dev"
43+ "dev-master" : " 4.4 .x-dev"
4444 }
4545 },
4646 "scripts" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Wikibase \DataModel \Entity ;
4+
5+ use InvalidArgumentException ;
6+
7+ /**
8+ * A trivial EntityIdParser that only parses the serializations of ItemIds. This is particularly
9+ * useful in cases where URIs are used to refer to concepts in an external Wikibase repository,
10+ * e.g. when referencing globes in coordinate values, or units in quantity values.
11+ *
12+ * @since 4.4
13+ *
14+ * @licence GNU GPL v2+
15+ * @author Thiemo Mättig
16+ */
17+ class ItemIdParser implements EntityIdParser {
18+
19+ /**
20+ * @param string $idSerialization
21+ *
22+ * @throws EntityIdParsingException
23+ * @return ItemId
24+ */
25+ public function parse ( $ idSerialization ) {
26+ try {
27+ return new ItemId ( $ idSerialization );
28+ } catch ( InvalidArgumentException $ ex ) {
29+ throw new EntityIdParsingException ( $ ex ->getMessage () );
30+ }
31+ }
32+
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Wikibase \DataModel \Tests \Entity ;
4+
5+ use PHPUnit_Framework_TestCase ;
6+ use Wikibase \DataModel \Entity \ItemId ;
7+ use Wikibase \DataModel \Entity \ItemIdParser ;
8+
9+ /**
10+ * @covers Wikibase\DataModel\Entity\ItemIdParser
11+ *
12+ * @licence GNU GPL v2+
13+ * @author Thiemo Mättig
14+ */
15+ class ItemIdParserTest extends PHPUnit_Framework_TestCase {
16+
17+ /**
18+ * @dataProvider entityIdProvider
19+ */
20+ public function testCanParseEntityId ( $ idString , ItemId $ expected ) {
21+ $ parser = new ItemIdParser ();
22+ $ actual = $ parser ->parse ( $ idString );
23+
24+ $ this ->assertEquals ( $ actual , $ expected );
25+ }
26+
27+ public function entityIdProvider () {
28+ return array (
29+ array ( 'q42 ' , new ItemId ( 'Q42 ' ) ),
30+ array ( 'Q1337 ' , new ItemId ( 'Q1337 ' ) ),
31+ );
32+ }
33+
34+ /**
35+ * @dataProvider invalidIdSerializationProvider
36+ */
37+ public function testCannotParseInvalidId ( $ invalidIdSerialization ) {
38+ $ parser = new ItemIdParser ();
39+
40+ $ this ->setExpectedException ( 'Wikibase\DataModel\Entity\EntityIdParsingException ' );
41+ $ parser ->parse ( $ invalidIdSerialization );
42+ }
43+
44+ public function invalidIdSerializationProvider () {
45+ return array (
46+ array ( 'FOO ' ),
47+ array ( null ),
48+ array ( 42 ),
49+ array ( array () ),
50+ array ( '' ),
51+ array ( 'q0 ' ),
52+ array ( '1p ' ),
53+ array ( 'p1 ' ),
54+ array ( 'P100000 ' ),
55+ );
56+ }
57+
58+ }
You can’t perform that action at this time.
0 commit comments