1 | <?php |
||
19 | class PropertyIdTest extends PHPUnit_Framework_TestCase { |
||
20 | |||
21 | /** |
||
22 | * @dataProvider idSerializationProvider |
||
23 | */ |
||
24 | public function testCanConstructId( $idSerialization, $normalizedIdSerialization ) { |
||
32 | |||
33 | public function idSerializationProvider() { |
||
47 | |||
48 | /** |
||
49 | * @dataProvider invalidIdSerializationProvider |
||
50 | */ |
||
51 | public function testCannotConstructWithInvalidSerialization( $invalidSerialization ) { |
||
55 | |||
56 | public function invalidIdSerializationProvider() { |
||
77 | |||
78 | public function testGetNumericId() { |
||
82 | |||
83 | public function testGetNumericId_foreignId() { |
||
84 | $id = new PropertyId( 'foo:P1' ); |
||
85 | $this->assertSame( 1, $id->getNumericId() ); |
||
86 | } |
||
87 | |||
88 | public function testGetEntityType() { |
||
89 | $id = new PropertyId( 'P1' ); |
||
90 | $this->assertSame( 'property', $id->getEntityType() ); |
||
91 | } |
||
92 | |||
93 | public function testSerialize() { |
||
94 | $id = new PropertyId( 'P1' ); |
||
95 | $this->assertSame( 'P1', $id->serialize() ); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @dataProvider serializationProvider |
||
100 | */ |
||
101 | public function testUnserialize( $json, $expected ) { |
||
102 | $id = new PropertyId( 'P1' ); |
||
103 | $id->unserialize( $json ); |
||
104 | $this->assertSame( $expected, $id->getSerialization() ); |
||
105 | } |
||
106 | |||
107 | public function serializationProvider() { |
||
108 | return [ |
||
109 | [ 'P2', 'P2' ], |
||
110 | [ '["property","P2"]', 'P2' ], |
||
111 | |||
112 | // All these cases are kind of an injection vector and allow constructing invalid ids. |
||
113 | [ '["string","P2"]', 'P2' ], |
||
114 | [ '["","string"]', 'string' ], |
||
115 | [ '["",""]', '' ], |
||
116 | [ '["",2]', 2 ], |
||
117 | [ '["",null]', null ], |
||
118 | [ '', '' ], |
||
119 | ]; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @dataProvider numericIdProvider |
||
124 | */ |
||
125 | public function testNewFromNumber( $number ) { |
||
129 | |||
130 | public function numericIdProvider() { |
||
140 | |||
141 | /** |
||
142 | * @dataProvider invalidNumericIdProvider |
||
143 | */ |
||
144 | public function testNewFromNumberWithInvalidNumericId( $number ) { |
||
148 | |||
149 | public function invalidNumericIdProvider() { |
||
158 | |||
159 | public function testNewFromRepositoryAndNumber() { |
||
160 | $id = PropertyId::newFromRepositoryAndNumber( 'foo', 1 ); |
||
161 | $this->assertSame( 'foo:P1', $id->getSerialization() ); |
||
162 | } |
||
163 | |||
164 | public function testNewFromRepositoryAndNumberWithInvalidNumericId() { |
||
168 | |||
169 | } |
||
170 |