Merge "RCFilters UI: Prevent the popup from disappearing when input is out of view"
[lhc/web/wiklou.git] / tests / phpunit / includes / TestingAccessWrapperTest.php
1 <?php
2
3 class TestingAccessWrapperTest extends MediaWikiTestCase {
4 protected $raw;
5 protected $wrapped;
6 protected $wrappedStatic;
7
8 function setUp() {
9 parent::setUp();
10
11 require_once __DIR__ . '/../data/helpers/WellProtectedClass.php';
12 $this->raw = new WellProtectedClass();
13 $this->wrapped = TestingAccessWrapper::newFromObject( $this->raw );
14 $this->wrappedStatic = TestingAccessWrapper::newFromClass( 'WellProtectedClass' );
15 }
16
17 /**
18 * @expectedException InvalidArgumentException
19 */
20 function testConstructorException() {
21 TestingAccessWrapper::newFromObject( 'WellProtectedClass' );
22 }
23
24 /**
25 * @expectedException InvalidArgumentException
26 */
27 function testStaticConstructorException() {
28 TestingAccessWrapper::newFromClass( new WellProtectedClass() );
29 }
30
31 function testGetProperty() {
32 $this->assertSame( 1, $this->wrapped->property );
33 $this->assertSame( 42, $this->wrapped->privateProperty );
34 $this->assertSame( 9000, $this->wrapped->privateParentProperty );
35 $this->assertSame( 'sp', $this->wrapped->staticProperty );
36 $this->assertSame( 'spp', $this->wrapped->staticPrivateProperty );
37 $this->assertSame( 'sp', $this->wrappedStatic->staticProperty );
38 $this->assertSame( 'spp', $this->wrappedStatic->staticPrivateProperty );
39 }
40
41 /**
42 * @expectedException DomainException
43 */
44 function testGetException() {
45 $this->wrappedStatic->property;
46 }
47
48 function testSetProperty() {
49 $this->wrapped->property = 10;
50 $this->assertSame( 10, $this->wrapped->property );
51 $this->assertSame( 10, $this->raw->getProperty() );
52
53 $this->wrapped->privateProperty = 11;
54 $this->assertSame( 11, $this->wrapped->privateProperty );
55 $this->assertSame( 11, $this->raw->getPrivateProperty() );
56
57 $this->wrapped->privateParentProperty = 12;
58 $this->assertSame( 12, $this->wrapped->privateParentProperty );
59 $this->assertSame( 12, $this->raw->getPrivateParentProperty() );
60
61 $this->wrapped->staticProperty = 'x';
62 $this->assertSame( 'x', $this->wrapped->staticProperty );
63 $this->assertSame( 'x', $this->wrappedStatic->staticProperty );
64
65 $this->wrapped->staticPrivateProperty = 'y';
66 $this->assertSame( 'y', $this->wrapped->staticPrivateProperty );
67 $this->assertSame( 'y', $this->wrappedStatic->staticPrivateProperty );
68
69 $this->wrappedStatic->staticProperty = 'X';
70 $this->assertSame( 'X', $this->wrapped->staticProperty );
71 $this->assertSame( 'X', $this->wrappedStatic->staticProperty );
72
73 $this->wrappedStatic->staticPrivateProperty = 'Y';
74 $this->assertSame( 'Y', $this->wrapped->staticPrivateProperty );
75 $this->assertSame( 'Y', $this->wrappedStatic->staticPrivateProperty );
76
77 // don't rely on PHPUnit to restore static properties
78 $this->wrapped->staticProperty = 'sp';
79 $this->wrapped->staticPrivateProperty = 'spp';
80 }
81
82 /**
83 * @expectedException DomainException
84 */
85 function testSetException() {
86 $this->wrappedStatic->property = 1;
87 }
88
89 function testCallMethod() {
90 $this->wrapped->incrementPropertyValue();
91 $this->assertSame( 2, $this->wrapped->property );
92 $this->assertSame( 2, $this->raw->getProperty() );
93
94 $this->wrapped->incrementPrivatePropertyValue();
95 $this->assertSame( 43, $this->wrapped->privateProperty );
96 $this->assertSame( 43, $this->raw->getPrivateProperty() );
97
98 $this->wrapped->incrementPrivateParentPropertyValue();
99 $this->assertSame( 9001, $this->wrapped->privateParentProperty );
100 $this->assertSame( 9001, $this->raw->getPrivateParentProperty() );
101
102 $this->assertSame( 'sm', $this->wrapped->staticMethod() );
103 $this->assertSame( 'spm', $this->wrapped->staticPrivateMethod() );
104 $this->assertSame( 'sm', $this->wrappedStatic->staticMethod() );
105 $this->assertSame( 'spm', $this->wrappedStatic->staticPrivateMethod() );
106 }
107
108 function testCallMethodTwoArgs() {
109 $this->assertSame( 'two', $this->wrapped->whatSecondArg( 'one', 'two' ) );
110 }
111
112 /**
113 * @expectedException DomainException
114 */
115 function testCallMethodException() {
116 $this->wrappedStatic->incrementPropertyValue();
117 }
118
119 }