Merge "Revert "Preprocessor: Don't allow unclosed extension tags (matching until...
[lhc/web/wiklou.git] / tests / phpunit / tests / MediaWikiTestCaseTest.php
1 <?php
2
3 /**
4 * @covers MediaWikiTestCase
5 * @author Addshore
6 */
7 class MediaWikiTestCaseTest extends MediaWikiTestCase {
8
9 const GLOBAL_KEY_NONEXISTING = 'MediaWikiTestCaseTestGLOBAL-NONExisting';
10
11 private static $startGlobals = array(
12 'MediaWikiTestCaseTestGLOBAL-ExistingString' => 'foo',
13 'MediaWikiTestCaseTestGLOBAL-ExistingStringEmpty' => '',
14 'MediaWikiTestCaseTestGLOBAL-ExistingArray' => array( 1, 'foo' => 'bar' ),
15 'MediaWikiTestCaseTestGLOBAL-ExistingArrayEmpty' => array(),
16 );
17
18 public static function setUpBeforeClass() {
19 parent::setUpBeforeClass();
20 foreach ( self::$startGlobals as $key => $value ) {
21 $GLOBALS[$key] = $value;
22 }
23 }
24
25 public static function tearDownAfterClass() {
26 parent::tearDownAfterClass();
27 foreach ( self::$startGlobals as $key => $value ) {
28 unset( $GLOBALS[$key] );
29 }
30 }
31
32 public function provideExistingKeysAndNewValues() {
33 $providedArray = array();
34 foreach ( array_keys( self::$startGlobals ) as $key ) {
35 $providedArray[] = array( $key, 'newValue' );
36 $providedArray[] = array( $key, array( 'newValue' ) );
37 }
38 return $providedArray;
39 }
40
41 /**
42 * @dataProvider provideExistingKeysAndNewValues
43 *
44 * @covers MediaWikiTestCase::setMwGlobals
45 * @covers MediaWikiTestCase::tearDown
46 */
47 public function testSetGlobalsAreRestoredOnTearDown( $globalKey, $newValue ) {
48 $this->setMwGlobals( $globalKey, $newValue );
49 $this->assertEquals(
50 $newValue,
51 $GLOBALS[$globalKey],
52 'Global failed to correctly set'
53 );
54
55 $this->tearDown();
56
57 $this->assertEquals(
58 self::$startGlobals[$globalKey],
59 $GLOBALS[$globalKey],
60 'Global failed to be restored on tearDown'
61 );
62 }
63
64 /**
65 * @dataProvider provideExistingKeysAndNewValues
66 *
67 * @covers MediaWikiTestCase::stashMwGlobals
68 * @covers MediaWikiTestCase::tearDown
69 */
70 public function testStashedGlobalsAreRestoredOnTearDown( $globalKey, $newValue ) {
71 $this->stashMwGlobals( $globalKey );
72 $GLOBALS[$globalKey] = $newValue;
73 $this->assertEquals(
74 $newValue,
75 $GLOBALS[$globalKey],
76 'Global failed to correctly set'
77 );
78
79 $this->tearDown();
80
81 $this->assertEquals(
82 self::$startGlobals[$globalKey],
83 $GLOBALS[$globalKey],
84 'Global failed to be restored on tearDown'
85 );
86 }
87
88 /**
89 * @covers MediaWikiTestCase::stashMwGlobals
90 */
91 public function testExceptionThrownWhenStashingNonExistentGlobals() {
92 $this->setExpectedException(
93 'Exception',
94 'Global with key ' . self::GLOBAL_KEY_NONEXISTING . ' doesn\'t exist and cant be stashed'
95 );
96
97 $this->stashMwGlobals( self::GLOBAL_KEY_NONEXISTING );
98 }
99
100 }