1 | <?php |
||
51 | class ItemTest extends \PHPUnit_Framework_TestCase |
||
52 | { |
||
53 | /** |
||
54 | * Public function test the item creation |
||
55 | * |
||
56 | * @param string|\stdClass|\stdClass[] $type Item type(s) |
||
57 | * @param array $properties Item properties |
||
58 | * @param $itemId Item id |
||
59 | * @param $itemLanguage Item language |
||
60 | * @param array $expectedTypes Expected item types |
||
61 | * @param array $expectedProperties Expected item properties |
||
62 | * @param string $expectedId Expected item id |
||
63 | * @param string $expectedLanguage Expected language |
||
64 | * @dataProvider creationArgumentProvider |
||
65 | */ |
||
66 | public function testItemCreation( |
||
83 | |||
84 | /** |
||
85 | * Convert a property list to a plain array |
||
86 | * |
||
87 | * @param PropertyListInterface $propertyList Property list |
||
88 | * @return array Property list array |
||
89 | */ |
||
90 | protected function convertPropertyListToArray(PropertyListInterface $propertyList) |
||
98 | |||
99 | /** |
||
100 | * Data provider for item creation tests |
||
101 | * |
||
102 | * @return array Item creation arguments |
||
103 | */ |
||
104 | public function creationArgumentProvider() |
||
151 | |||
152 | /** |
||
153 | * Create a type object |
||
154 | * |
||
155 | * @param string $name Type name |
||
156 | * @param string $profile Type profile |
||
157 | * @return object Type object |
||
158 | */ |
||
159 | protected function typ($name, $profile = '') |
||
160 | { |
||
161 | return new Iri($profile, $name); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Create a property object |
||
166 | * |
||
167 | * @param string $name Property name |
||
168 | * @param mixed $str Property value(s) |
||
169 | * @param string $profile Property profile |
||
170 | * @return \stdClass Property object |
||
171 | */ |
||
172 | protected function prp($name, $str, $profile = '') |
||
173 | { |
||
174 | $values = array_map([$this, 'str'], (array)$str); |
||
175 | return (object)['profile' => $profile, 'name' => $name, 'values' => $values]; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Create a string value |
||
180 | * |
||
181 | * @param string $str Value |
||
182 | * @return ValueInterface String value |
||
183 | */ |
||
184 | protected function str($str) |
||
185 | { |
||
186 | return ($str instanceof ValueInterface) ? $str : new StringValue($str); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Test the item creation with an empty types list |
||
191 | * |
||
192 | * @expectedException \Jkphl\Micrometa\Domain\Exceptions\InvalidArgumentException |
||
193 | * @expectedExceptionCode 1490814631 |
||
194 | */ |
||
195 | public function testEmptyTypesList() |
||
199 | |||
200 | /** |
||
201 | * Test the item creation with an empty types list |
||
202 | * |
||
203 | * @expectedException \Jkphl\Micrometa\Domain\Exceptions\InvalidArgumentException |
||
204 | * @expectedExceptionCode 1488314667 |
||
205 | */ |
||
206 | public function testEmptyTypeName() |
||
210 | |||
211 | /** |
||
212 | * Test the item creation with an empty property name |
||
213 | * |
||
214 | * @expectedException \Jkphl\Micrometa\Domain\Exceptions\InvalidArgumentException |
||
215 | * @expectedExceptionCode 1488314921 |
||
216 | */ |
||
217 | public function testEmptyPropertyName() |
||
221 | |||
222 | /** |
||
223 | * Test empty property value list |
||
224 | * |
||
225 | * @expectedException \Jkphl\Micrometa\Domain\Exceptions\InvalidArgumentException |
||
226 | * @expectedExceptionCode 1490814554 |
||
227 | */ |
||
228 | public function testInvalidPropertyStructure() |
||
232 | |||
233 | /** |
||
234 | * Test the item creation with an invalid property value |
||
235 | * |
||
236 | * @expectedException \Jkphl\Micrometa\Domain\Exceptions\InvalidArgumentException |
||
237 | * @expectedExceptionCode 1488315339 |
||
238 | */ |
||
239 | public function testInvalidPropertyValue() |
||
243 | |||
244 | /** |
||
245 | * Test the item creation with an invalid property value |
||
246 | * |
||
247 | * @expectedException \Jkphl\Micrometa\Domain\Exceptions\OutOfBoundsException |
||
248 | * @expectedExceptionCode 1488315604 |
||
249 | */ |
||
250 | public function testUnknownPropertyName() |
||
255 | |||
256 | /** |
||
257 | * Test the item property getter with an unprofiled property |
||
258 | */ |
||
259 | public function testItemUnprofiledProperty() |
||
264 | |||
265 | /** |
||
266 | * Test the item property getter with a profiled property |
||
267 | */ |
||
268 | public function testItemProfiledProperty() |
||
277 | } |
||
278 |