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