MediaWiki
REL1_21
|
00001 <?php 00002 00003 class MWFunctionTest extends MediaWikiTestCase { 00004 function testCallUserFuncWorkarounds() { 00005 $this->assertEquals( 00006 call_user_func( array( 'MWFunctionTest', 'someMethod' ) ), 00007 MWFunction::call( 'MWFunctionTest::someMethod' ) 00008 ); 00009 $this->assertEquals( 00010 call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ), 00011 MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' ) 00012 ); 00013 00014 $this->assertEquals( 00015 call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ), 00016 MWFunction::callArray( 'MWFunctionTest::someMethod', array() ) 00017 ); 00018 $this->assertEquals( 00019 call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ), 00020 MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) ) 00021 ); 00022 } 00023 00024 function testNewObjFunction() { 00025 $arg1 = 'Foo'; 00026 $arg2 = 'Bar'; 00027 $arg3 = array( 'Baz' ); 00028 $arg4 = new ExampleObject; 00029 00030 $args = array( $arg1, $arg2, $arg3, $arg4 ); 00031 00032 $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 ); 00033 $this->assertEquals( 00034 MWFunction::newObj( 'MWBlankClass', $args )->args, 00035 $newObject->args 00036 ); 00037 00038 $this->assertEquals( 00039 MWFunction::newObj( 'MWBlankClass', $args, true )->args, 00040 $newObject->args, 00041 'Works even with PHP version < 5.1.3' 00042 ); 00043 } 00044 00048 function testCallingParentFails() { 00049 MWFunction::call( 'parent::foo' ); 00050 } 00051 00055 function testCallingSelfFails() { 00056 MWFunction::call( 'self::foo' ); 00057 } 00058 00059 public static function someMethod() { 00060 return func_get_args(); 00061 } 00062 00063 } 00064 00065 class MWBlankClass { 00066 00067 public $args = array(); 00068 00069 function __construct( $arg1, $arg2, $arg3, $arg4 ) { 00070 $this->args = array( $arg1, $arg2, $arg3, $arg4 ); 00071 } 00072 } 00073 00074 class ExampleObject { 00075 }