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