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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php
namespace SMW\Tests\MediaWiki\Api;
use SMW\MediaWiki\Api\ApiRequestParameterFormatter;
use SMW\Tests\TestEnvironment;
/**
* @covers \SMW\MediaWiki\Api\ApiRequestParameterFormatter
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 1.9
*
* @author mwjames
*/
class ApiRequestParameterFormatterTest extends \PHPUnit_Framework_TestCase {
private $testEnvironment;
public function setUp() {
$this->testEnvironment = new TestEnvironment();
}
public function tearDown() {
$this->testEnvironment->tearDown();
}
public function testCanConstruct() {
$this->assertInstanceOf(
'\SMW\MediaWiki\Api\ApiRequestParameterFormatter',
new ApiRequestParameterFormatter( [] )
);
}
public function testGetAskArgsApiForEmptyParameter() {
$nstance = new ApiRequestParameterFormatter( [] );
$this->assertEmpty( $nstance->getAskArgsApiParameter( 'conditions' ) );
$this->assertEmpty( $nstance->getAskArgsApiParameter( 'parameters' ) );
$this->assertEmpty( $nstance->getAskArgsApiParameter( 'printouts' ) );
}
/**
* @dataProvider requestArgsApiParametersDataProvider
*/
public function testGetAskArgsApiParameter( $parameters, $type, $expected ) {
$nstance = new ApiRequestParameterFormatter( $parameters );
$this->assertEquals(
$expected,
$nstance->getAskArgsApiParameter( $type )
);
}
/**
* @dataProvider requestAskApiParametersDataProvider
*/
public function testGetAskApiParameters( $parameters, $expected ) {
$instance = new ApiRequestParameterFormatter( $parameters );
$result = $instance->getAskApiParameters();
$this->assertInternalType( 'array', $result );
$this->assertEquals( $expected, $result );
}
public function requestArgsApiParametersDataProvider() {
return [
[ [ 'conditions' => [ 'Lala' ] ], 'conditions', '[[Lala]]' ],
[ [ 'conditions' => [ 'Lala', 'Lima' ] ], 'conditions', '[[Lala]] [[Lima]]' ],
[ [ 'parameters' => [ 'Lila' ] ], 'parameters', [] ],
[ [ 'parameters' => [ 'Lila=isFunny' ] ], 'parameters', [ 'Lila' => 'isFunny' ] ],
[ [ 'parameters' => [ 'Lila=isFunny', 'Lula=isHappy' ] ], 'parameters', [ 'Lila' => 'isFunny', 'Lula' => 'isHappy' ] ],
// array( array( 'printouts' => array( '?Linda' ) ), 'printouts', array( $this->newPrintRequest( '?Linda' ) ) ),
// array( array( 'printouts' => array( '?Luna', '?Mars' ) ), 'printouts', array( $this->newPrintRequest( '?Luna' ), $this->newPrintRequest( '?Mars' ) ) ),
];
}
public function requestAskApiParametersDataProvider() {
return [
[ [], [] ],
[ [ 'query' => '[[Modification date::+]]' ], [ '[[Modification date::+]]' ] ],
[ [ 'query' => '[[Modification date::+]]|?Modification date' ], [ '[[Modification date::+]]', '?Modification date' ] ],
[ [ 'query' => '[[Modification date::+]]|?Modification date|sort=desc' ], [ '[[Modification date::+]]', '?Modification date', 'sort=desc' ] ],
];
}
private function newPrintRequest( $printout ) {
return new \SMW\Query\PrintRequest(
\SMW\Query\PrintRequest::PRINT_PROP,
$printout,
\SMW\DataValueFactory::getInstance()->newPropertyValueByLabel( $printout )
);
}
}
|