7 class ApiFormatPhpTest
extends ApiFormatTestBase
{
9 protected $printerName = 'php';
11 public static function provideGeneralEncoding() {
14 array( array( null ), 'a:1:{i:0;N;}' ),
15 array( array( true ), 'a:1:{i:0;b:1;}' ),
16 array( array( false ), 'a:1:{i:0;b:0;}' ),
17 array( array( 42 ), 'a:1:{i:0;i:42;}' ),
18 array( array( 42.5 ), 'a:1:{i:0;d:42.5;}' ),
19 array( array( 1e42
), 'a:1:{i:0;d:1.0E+42;}' ),
20 array( array( 'foo' ), 'a:1:{i:0;s:3:"foo";}' ),
21 array( array( 'fóo' ), 'a:1:{i:0;s:4:"fóo";}' ),
24 array( array( array() ), 'a:1:{i:0;a:0:{}}' ),
25 array( array( array( 1 ) ), 'a:1:{i:0;a:1:{i:0;i:1;}}' ),
26 array( array( array( 'x' => 1 ) ), 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ),
27 array( array( array( 2 => 1 ) ), 'a:1:{i:0;a:1:{i:2;i:1;}}' ),
30 array( array( '*' => 'foo' ), 'a:1:{s:1:"*";s:3:"foo";}' ),
34 public function testCrossDomainMangling() {
35 $config = new HashConfig( array( 'MangleFlashPolicy' => false ) );
36 $context = new RequestContext
;
37 $context->setConfig( new MultiConfig( array(
39 $context->getConfig(),
41 $main = new ApiMain( $context );
42 $main->getResult()->addValue( null, null, '< Cross-Domain-Policy >' );
44 if ( !function_exists( 'wfOutputHandler' ) ) {
45 function wfOutputHandler( $s ) {
50 $printer = $main->createPrinterByName( 'php' );
51 ob_start( 'wfOutputHandler' );
52 $printer->initPrinter();
54 $printer->closePrinter();
55 $ret = ob_get_clean();
56 $this->assertSame( 'a:1:{i:0;s:23:"< Cross-Domain-Policy >";}', $ret );
58 $config->set( 'MangleFlashPolicy', true );
59 $printer = $main->createPrinterByName( 'php' );
60 ob_start( 'wfOutputHandler' );
62 $printer->initPrinter();
64 $printer->closePrinter();
66 $this->fail( 'Expected exception not thrown' );
67 } catch ( UsageException
$ex ) {
70 'This response cannot be represented using format=php. See https://bugzilla.wikimedia.org/show_bug.cgi?id=66776',