Merge "(bug 40154) On action=info show where this page redirects to and whether it...
[lhc/web/wiklou.git] / tests / phpunit / includes / MWFunctionTest.php
1 <?php
2
3 class MWFunctionTest extends MediaWikiTestCase {
4
5 function testCallUserFuncWorkarounds() {
6 $this->assertEquals(
7 call_user_func( array( 'MWFunctionTest', 'someMethod' ) ),
8 MWFunction::call( 'MWFunctionTest::someMethod' )
9 );
10 $this->assertEquals(
11 call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ),
12 MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' )
13 );
14
15 $this->assertEquals(
16 call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ),
17 MWFunction::callArray( 'MWFunctionTest::someMethod', array() )
18 );
19 $this->assertEquals(
20 call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ),
21 MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) )
22 );
23 }
24
25 function testNewObjFunction() {
26 $arg1 = 'Foo';
27 $arg2 = 'Bar';
28 $arg3 = array( 'Baz' );
29 $arg4 = new ExampleObject;
30
31 $args = array( $arg1, $arg2, $arg3, $arg4 );
32
33 $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 );
34 $this->assertEquals(
35 MWFunction::newObj( 'MWBlankClass', $args )->args,
36 $newObject->args
37 );
38
39 $this->assertEquals(
40 MWFunction::newObj( 'MWBlankClass', $args, true )->args,
41 $newObject->args,
42 'Works even with PHP version < 5.1.3'
43 );
44 }
45
46 /**
47 * @expectedException MWException
48 */
49 function testCallingParentFails() {
50 MWFunction::call( 'parent::foo' );
51 }
52
53 /**
54 * @expectedException MWException
55 */
56 function testCallingSelfFails() {
57 MWFunction::call( 'self::foo' );
58 }
59
60 public static function someMethod() {
61 return func_get_args();
62 }
63
64 }
65
66 class MWBlankClass {
67
68 public $args = array();
69
70 function __construct( $arg1, $arg2, $arg3, $arg4 ) {
71 $this->args = array( $arg1, $arg2, $arg3, $arg4 );
72 }
73 }
74
75 class ExampleObject {
76 }