8 class ApiBaseTest
extends ApiTestCase
{
11 * @covers ApiBase::requireOnlyOneParameter
13 public function testRequireOnlyOneParameterDefault() {
14 $mock = new MockApi();
15 $mock->requireOnlyOneParameter(
16 [ "filename" => "foo.txt", "enablechunks" => false ],
17 "filename", "enablechunks"
19 $this->assertTrue( true );
23 * @expectedException UsageException
24 * @covers ApiBase::requireOnlyOneParameter
26 public function testRequireOnlyOneParameterZero() {
27 $mock = new MockApi();
28 $mock->requireOnlyOneParameter(
29 [ "filename" => "foo.txt", "enablechunks" => 0 ],
30 "filename", "enablechunks"
35 * @expectedException UsageException
36 * @covers ApiBase::requireOnlyOneParameter
38 public function testRequireOnlyOneParameterTrue() {
39 $mock = new MockApi();
40 $mock->requireOnlyOneParameter(
41 [ "filename" => "foo.txt", "enablechunks" => true ],
42 "filename", "enablechunks"
47 * @dataProvider provideGetParameterFromSettings
48 * @param string|null $input
49 * @param array $paramSettings
50 * @param mixed $expected
51 * @param string[] $warnings
53 public function testGetParameterFromSettings( $input, $paramSettings, $expected, $warnings ) {
54 $mock = new MockApi();
55 $wrapper = TestingAccessWrapper
::newFromObject( $mock );
57 $context = new DerivativeContext( $mock );
58 $context->setRequest( new FauxRequest( $input !== null ?
[ 'foo' => $input ] : [] ) );
59 $wrapper->mMainModule
= new ApiMain( $context );
61 if ( $expected instanceof UsageException
) {
63 $wrapper->getParameterFromSettings( 'foo', $paramSettings, true );
64 } catch ( UsageException
$ex ) {
65 $this->assertEquals( $expected, $ex );
68 $result = $wrapper->getParameterFromSettings( 'foo', $paramSettings, true );
69 $this->assertSame( $expected, $result );
70 $this->assertSame( $warnings, $mock->warnings
);
74 public static function provideGetParameterFromSettings() {
76 'The value passed for \'foo\' contains invalid or non-normalized data. Textual data should ' .
77 'be valid, NFC-normalized Unicode without C0 control characters other than ' .
78 'HT (\\t), LF (\\n), and CR (\\r).'
83 for ( $i = 0; $i < 32; $i++
) {
85 $enc .= ( $i === 9 ||
$i === 10 ||
$i === 13 )
91 'Basic param' => [ 'bar', null, 'bar', [] ],
92 'Basic param, C0 controls' => [ $c0, null, $enc, $warnings ],
93 'String param' => [ 'bar', '', 'bar', [] ],
94 'String param, defaulted' => [ null, '', '', [] ],
95 'String param, empty' => [ '', 'default', '', [] ],
96 'String param, required, empty' => [
98 [ ApiBase
::PARAM_DFLT
=> 'default', ApiBase
::PARAM_REQUIRED
=> true ],
99 new UsageException( 'The foo parameter must be set', 'nofoo' ),
102 'Multi-valued parameter' => [
104 [ ApiBase
::PARAM_ISMULTI
=> true ],
108 'Multi-valued parameter, alternative separator' => [
110 [ ApiBase
::PARAM_ISMULTI
=> true ],
114 'Multi-valued parameter, other C0 controls' => [
116 [ ApiBase
::PARAM_ISMULTI
=> true ],
120 'Multi-valued parameter, other C0 controls (2)' => [
122 [ ApiBase
::PARAM_ISMULTI
=> true ],
123 [ substr( $enc, 0, -3 ), '' ],