|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SFS\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SFS\ApiSemanticFormsSelectRequestProcessor; |
|
6
|
|
|
use ApiMain; |
|
7
|
|
|
use RequestContext; |
|
8
|
|
|
use WebRequest; |
|
9
|
|
|
use FauxRequest; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \SFS\ApiSemanticFormsSelectRequestProcessor |
|
13
|
|
|
* @group semantic-forms-select |
|
14
|
|
|
* |
|
15
|
|
|
* @license GNU GPL v2+ |
|
16
|
|
|
* @since 3.0.0 |
|
17
|
|
|
* |
|
18
|
|
|
* @author FelixAba |
|
19
|
|
|
*/ |
|
20
|
|
|
class ApiSemanticFormsSelectRequestProcessorTest |
|
21
|
|
|
extends \PHPUnit_Framework_TestCase { |
|
22
|
|
|
|
|
23
|
|
|
private $ApiSFSRP; |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp() { |
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
|
28
|
|
|
->disableOriginalConstructor()->getMock(); |
|
29
|
|
|
$this->ApiSFSRP = new ApiSemanticFormsSelectRequestProcessor( $parser ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function tearDown() { |
|
33
|
|
|
unset( $this->ApiSFSRP ); |
|
34
|
|
|
parent::tearDown(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testCanConstruct() { |
|
38
|
|
|
$this->assertInstanceOf( |
|
39
|
|
|
'\SFS\ApiSemanticFormsSelectRequestProcessor', $this->ApiSFSRP |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testMissingParametersThrowsException() { |
|
44
|
|
|
|
|
45
|
|
|
$parameters = []; |
|
46
|
|
|
|
|
47
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
|
48
|
|
|
$this->ApiSFSRP->getJsonDecodedResultValuesForRequestParameters( |
|
49
|
|
|
$parameters |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testJsonResultValuesFromRequestParameters() { |
|
54
|
|
|
|
|
55
|
|
|
$parameters = [ 'query' => 'foo', 'sep' => ',' ]; |
|
56
|
|
|
|
|
57
|
|
|
$this->assertInternalType( |
|
58
|
|
|
'object', |
|
59
|
|
|
$this->ApiSFSRP->getJsonDecodedResultValuesForRequestParameters( |
|
60
|
|
|
$parameters |
|
61
|
|
|
) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testJsonResultValuesFromRequestParameters_doProcessQueryFor( |
|
66
|
|
|
) { |
|
67
|
|
|
|
|
68
|
|
|
$parameters = [ 'approach' => 'smw', 'query' => 'foo, baa, gaah', |
|
69
|
|
|
'sep' => ',' ]; |
|
70
|
|
|
|
|
71
|
|
|
$this->assertInternalType( |
|
72
|
|
|
'object', |
|
73
|
|
|
$this->ApiSFSRP->getJsonDecodedResultValuesForRequestParameters( |
|
74
|
|
|
$parameters |
|
75
|
|
|
) |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testSetDebugFlag() { |
|
80
|
|
|
$this->ApiSFSRP->setDebugFlag( true ); |
|
81
|
|
|
$parameters = [ 'query' => 'foo , function', 'sep' => ',' ]; |
|
82
|
|
|
|
|
83
|
|
|
$this->assertInternalType( |
|
84
|
|
|
'object', |
|
85
|
|
|
$this->ApiSFSRP->getJsonDecodedResultValuesForRequestParameters( |
|
86
|
|
|
$parameters |
|
87
|
|
|
) |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testSetDebugFlag_doProcessQueryFor() { |
|
92
|
|
|
$this->ApiSFSRP->setDebugFlag( true ); |
|
93
|
|
|
$parameters = [ 'approach' => 'smw', 'query' => 'my Query,query2', |
|
94
|
|
|
'sep' => ',' ]; |
|
95
|
|
|
|
|
96
|
|
|
$this->assertInternalType( |
|
97
|
|
|
'object', |
|
98
|
|
|
$this->ApiSFSRP->getJsonDecodedResultValuesForRequestParameters( |
|
99
|
|
|
$parameters |
|
100
|
|
|
) |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testGetFormattedValuesFrom() { |
|
105
|
|
|
$sep = ","; |
|
106
|
|
|
$values = "my Query,query2"; |
|
107
|
|
|
$result = [ "", "my Query", "query2" ]; |
|
108
|
|
|
$formattedValues = $this->invokeMethod( |
|
109
|
|
|
$this->ApiSFSRP, 'getFormattedValuesFrom', [ $sep, $values ] |
|
110
|
|
|
); |
|
111
|
|
|
$this->assertEquals( $result, $formattedValues ); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Call protected/private method of a class. |
|
116
|
|
|
* |
|
117
|
|
|
* @param object &$object Instantiated object that we will run method on. |
|
118
|
|
|
* @param string $methodName Method name to call |
|
119
|
|
|
* @param array $parameters Array of parameters to pass into method. |
|
120
|
|
|
* |
|
121
|
|
|
* @return mixed Method return. |
|
122
|
|
|
*/ |
|
123
|
|
|
public function invokeMethod( &$object, $methodName, |
|
124
|
|
|
array $parameters = [] |
|
125
|
|
|
) { |
|
126
|
|
|
$reflection = new \ReflectionClass( get_class( $object ) ); |
|
127
|
|
|
$method = $reflection->getMethod( $methodName ); |
|
128
|
|
|
$method->setAccessible( true ); |
|
129
|
|
|
|
|
130
|
|
|
return $method->invokeArgs( $object, $parameters ); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|