Merge "resourceloader: Pass jQuery twice to 'implements' module wrapper"
[lhc/web/wiklou.git] / tests / phpunit / tests / MediaWikiTestCaseTest.php
1 <?php
2
3 /**
4 * @covers MediaWikiTestCase
5 * @author Adam Shorland
6 */
7 class MediaWikiTestCaseTest extends MediaWikiTestCase {
8
9 const GLOBAL_KEY_EXISTING = 'MediaWikiTestCaseTestGLOBAL-Existing';
10 const GLOBAL_KEY_NONEXISTING = 'MediaWikiTestCaseTestGLOBAL-NONExisting';
11
12 public static function setUpBeforeClass() {
13 parent::setUpBeforeClass();
14 $GLOBALS[self::GLOBAL_KEY_EXISTING] = 'foo';
15 }
16
17 public static function tearDownAfterClass() {
18 parent::tearDownAfterClass();
19 unset( $GLOBALS[self::GLOBAL_KEY_EXISTING] );
20 }
21
22 /**
23 * @covers MediaWikiTestCase::setMwGlobals
24 * @covers MediaWikiTestCase::tearDown
25 */
26 public function testSetGlobalsAreRestoredOnTearDown() {
27 $this->setMwGlobals( self::GLOBAL_KEY_EXISTING, 'bar' );
28 $this->assertEquals(
29 'bar',
30 $GLOBALS[self::GLOBAL_KEY_EXISTING],
31 'Global failed to correctly set'
32 );
33
34 $this->tearDown();
35
36 $this->assertEquals(
37 'foo',
38 $GLOBALS[self::GLOBAL_KEY_EXISTING],
39 'Global failed to be restored on tearDown'
40 );
41 }
42
43 /**
44 * @covers MediaWikiTestCase::stashMwGlobals
45 * @covers MediaWikiTestCase::tearDown
46 */
47 public function testStashedGlobalsAreRestoredOnTearDown() {
48 $this->stashMwGlobals( self::GLOBAL_KEY_EXISTING );
49 $GLOBALS[self::GLOBAL_KEY_EXISTING] = 'bar';
50 $this->assertEquals(
51 'bar',
52 $GLOBALS[self::GLOBAL_KEY_EXISTING],
53 'Global failed to correctly set'
54 );
55
56 $this->tearDown();
57
58 $this->assertEquals(
59 'foo',
60 $GLOBALS[self::GLOBAL_KEY_EXISTING],
61 'Global failed to be restored on tearDown'
62 );
63 }
64
65 /**
66 * @covers MediaWikiTestCase::stashMwGlobals
67 */
68 public function testExceptionThrownWhenStashingNonExistentGlobals() {
69 $this->setExpectedException(
70 'Exception',
71 'Global with key ' . self::GLOBAL_KEY_NONEXISTING . ' doesn\'t exist and cant be stashed'
72 );
73
74 $this->stashMwGlobals( self::GLOBAL_KEY_NONEXISTING );
75 }
76
77 }