5 * @covers ApiFormatWddx
7 class ApiFormatWddxTest
extends ApiFormatTestBase
{
9 protected $printerName = 'wddx';
11 public static function provideGeneralEncoding() {
12 if ( ApiFormatWddx
::useSlowPrinter() ) {
14 array( array(), 'Fast Wddx printer is unavailable', array( 'SKIP' => true ) )
17 return self
::provideEncoding();
20 public static function provideEncoding() {
21 $p = '<wddxPacket version=\'1.0\'><header/><data><struct><var name=\'warnings\'><struct><var name=\'wddx\'><struct><var name=\'*\'><string>format=wddx has been deprecated. Please use format=json instead.</string></var></struct></var></struct></var>';
22 $s = '</struct></data></wddxPacket>';
26 array( array( null ), "{$p}<var name='0'><null/></var>{$s}" ),
27 array( array( true ), "{$p}<var name='0'><boolean value='true'/></var>{$s}" ),
28 array( array( false ), "{$p}<var name='0'><boolean value='false'/></var>{$s}" ),
29 array( array( 42 ), "{$p}<var name='0'><number>42</number></var>{$s}" ),
30 array( array( 42.5 ), "{$p}<var name='0'><number>42.5</number></var>{$s}" ),
31 array( array( 1e42
), "{$p}<var name='0'><number>1.0E+42</number></var>{$s}" ),
32 array( array( 'foo' ), "{$p}<var name='0'><string>foo</string></var>{$s}" ),
33 array( array( 'fóo' ), "{$p}<var name='0'><string>fóo</string></var>{$s}" ),
36 array( array( array() ), "{$p}<var name='0'><array length='0'></array></var>{$s}" ),
37 array( array( array( 1 ) ), "{$p}<var name='0'><array length='1'><number>1</number></array></var>{$s}" ),
38 array( array( array( 'x' => 1 ) ), "{$p}<var name='0'><struct><var name='x'><number>1</number></var></struct></var>{$s}" ),
39 array( array( array( 2 => 1 ) ), "{$p}<var name='0'><struct><var name='2'><number>1</number></var></struct></var>{$s}" ),
42 array( array( '*' => 'foo' ), "{$p}<var name='*'><string>foo</string></var>{$s}" ),
47 * @dataProvider provideEncoding
49 public function testSlowEncoding( array $data, $expect, array $params = array() ) {
50 // Adjust expectation for differences between fast and slow printers.
51 $expect = str_replace( '\'', '"', $expect );
52 $expect = str_replace( '/>', ' />', $expect );
53 $expect = '<?xml version="1.0"?>' . $expect;
55 $this->assertSame( $expect, $this->encodeData( $params, $data, 'ApiFormatWddxTest_SlowWddx' ) );
59 class ApiFormatWddxTest_SlowWddx
extends ApiFormatWddx
{
60 public static function useSlowPrinter() {