1 | <?php |
||
20 | class LuaAskResultProcessorTest extends \PHPUnit_Framework_TestCase { |
||
21 | |||
22 | /** |
||
23 | * Holds a mock of a query result for this test |
||
24 | * |
||
25 | * @var \SMWQueryResult |
||
26 | */ |
||
27 | private $queryResult; |
||
28 | |||
29 | /** |
||
30 | * Set-up method prepares a mock {@see \SMWQueryResult} |
||
31 | */ |
||
32 | protected function setUp() { |
||
49 | |||
50 | /** |
||
51 | * Test, if the constructor works |
||
52 | * |
||
53 | * @see \SMW\Scribunto\LuaAskResultProcessor::__construct |
||
54 | * |
||
55 | * @uses $queryResult |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | public function testCanConstruct() { |
||
68 | |||
69 | /** |
||
70 | * Tests the conversion of a {@see \SMWQueryResult} in a lua table |
||
71 | * |
||
72 | * @see \SMW\Scribunto\LuaAskResultProcessor::getProcessedResult |
||
73 | * |
||
74 | * @uses $queryResult, \SMW\Scribunto\LuaAskResultProcessor::getProcessedResult |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | public function testGetProcessedResult() { |
||
79 | |||
80 | $instance = new LuaAskResultProcessor( $this->queryResult ); |
||
81 | |||
82 | $result = $instance->getProcessedResult(); |
||
83 | |||
84 | $this->assertInternalType( |
||
85 | 'array', |
||
86 | $result |
||
87 | ); |
||
88 | |||
89 | $this->assertEquals( |
||
90 | 1, |
||
91 | count( $result ) |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Tests the data extraction from a result row |
||
97 | * |
||
98 | * @see \SMW\Scribunto\LuaAskResultProcessor::getDataFromQueryResultRow |
||
99 | * |
||
100 | * @uses $queryResult, constructResultArray, \SMW\Scribunto\LuaAskResultProcessor::getDataFromQueryResultRow |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | public function testGetDataFromQueryResultRow() { |
||
116 | |||
117 | /** |
||
118 | * Tests the retrieval of a key (string label or numeric index) from |
||
119 | * a print request |
||
120 | * |
||
121 | * @see \SMW\Scribunto\LuaAskResultProcessor::getKeyFromPrintRequest |
||
122 | * |
||
123 | * @uses $queryResult |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | public function testGetKeyFromPrintRequest() { |
||
171 | |||
172 | /** |
||
173 | * Tests the extraction of data from a SMWResultArray |
||
174 | * |
||
175 | * @see \SMW\Scribunto\LuaAskResultProcessor::getDataFromResultArray |
||
176 | * |
||
177 | * @uses $queryResult, constructResultArray, \SMW\Scribunto\LuaAskResultProcessor::getDataFromResultArray |
||
178 | * |
||
179 | * @return void |
||
180 | */ |
||
181 | public function testGetDataFromResultArray() { |
||
193 | |||
194 | /** |
||
195 | * Tests data value extraction. Uses data provider {@see dataProvidergetValueFromDataValueTest} |
||
196 | * @dataProvider dataProvidergetValueFromDataValueTest |
||
197 | * |
||
198 | * @param string $class name of data value class |
||
199 | * @param string $type data value type |
||
200 | * @param string $expects return value type |
||
201 | * |
||
202 | * @see \SMW\Scribunto\LuaAskResultProcessor::getValueFromDataValue |
||
203 | * |
||
204 | * @uses $queryResult, dataProvidergetValueFromDataValueTest |
||
205 | * |
||
206 | * @return void |
||
207 | */ |
||
208 | public function testGetValueFromDataValue( $class, $type, $expects ) { |
||
209 | |||
210 | $instance = new LuaAskResultProcessor( $this->queryResult ); |
||
211 | |||
212 | $dataValue = $this->getMockBuilder( '\\' . $class ) |
||
213 | ->setConstructorArgs( [ $type ] ) |
||
214 | ->getMock(); |
||
215 | |||
216 | $dataValue->expects( $this->any() ) |
||
217 | ->method( 'getTypeID' ) |
||
218 | ->will( $this->returnValue( $type ) ); |
||
219 | |||
220 | |||
221 | /** @noinspection PhpParamsInspection */ |
||
222 | $this->assertInternalType( |
||
223 | $expects, |
||
224 | $instance->getValueFromDataValue( $dataValue ) |
||
225 | ); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Tests the conversion of a list of result values into a value, usable in lua. |
||
230 | * Uses data provider {@see dataProviderExtractLuaDataFromDVData} |
||
231 | * @dataProvider dataProviderExtractLuaDataFromDVData |
||
232 | * |
||
233 | * @param mixed $expects expected return value |
||
234 | * @param array $input input for method |
||
235 | * |
||
236 | * @see \SMW\Scribunto\LuaAskResultProcessor::extractLuaDataFromDVData |
||
237 | * |
||
238 | * @uses $queryResult |
||
239 | * |
||
240 | * @return void |
||
241 | */ |
||
242 | public function testExtractLuaDataFromDVData( $expects, $input ) { |
||
251 | |||
252 | /** |
||
253 | * Tests the generation of a numeric index key |
||
254 | * |
||
255 | * @see \SMW\Scribunto\LuaAskResultProcessor::getNumericIndex |
||
256 | * |
||
257 | * @uses $queryResult |
||
258 | * |
||
259 | * @return void |
||
260 | */ |
||
261 | public function testGetNumericIndex() { |
||
275 | |||
276 | /** |
||
277 | * Data provider for {@see testgetValueFromDataValue} |
||
278 | * |
||
279 | * @see testgetValueFromDataValue |
||
280 | * |
||
281 | * @return array |
||
282 | */ |
||
283 | public function dataProvidergetValueFromDataValueTest() { |
||
292 | |||
293 | /** |
||
294 | * Data provider for {@see testExtractLuaDataFromDVData} |
||
295 | * |
||
296 | * @see testExtractLuaDataFromDVData |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | public function dataProviderExtractLuaDataFromDVData() { |
||
307 | |||
308 | /** |
||
309 | * Constructs a mock {@see \SMWResultArray} |
||
310 | * |
||
311 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
312 | */ |
||
313 | private function constructResultArray() { |
||
334 | |||
335 | /** |
||
336 | * Constructs a mock {@see \SMW\Query\PrintRequest} |
||
337 | * |
||
338 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
339 | */ |
||
340 | private function constructPrintRequest() { |
||
348 | |||
349 | |||
350 | /** |
||
351 | * Constructs a mock {@see \SMWNumberValue} |
||
352 | * |
||
353 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
354 | */ |
||
355 | private function constructSMWNumberValue() { |
||
363 | } |
||
364 |