<?php
-class TestSample extends PHPUnit_Framework_TestCase {
+class TestSample extends MediaWikiLangTestCase {
/**
* Anything that needs to happen before your tests should go here.
*/
- function setUp() {
- global $wgContLang;
- /* For example, we need to set $wgContLang for creating a new Title */
- $wgContLang = Language::factory( 'en' );
+ protected function setUp() {
+ // Be sure to do call the parent setup and teardown functions.
+ // This makes sure that all the various cleanup and restorations
+ // happen as they should (including the restoration for setMwGlobals).
+ parent::setUp();
+
+ // This sets the globals and will restore them automatically
+ // after each test.
+ $this->setMwGlobals( array(
+ 'wgContLang' => Language::factory( 'en' ),
+ 'wgLanguageCode' => 'en',
+ ) );
}
/**
* Anything cleanup you need to do should go here.
*/
- function tearDown() {
+ protected function tearDown() {
+ parent::tearDown();
}
/**
/**
* If you want to run a the same test with a variety of data. use a data provider.
* see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
+ *
+ * Note: Data providers are always called statically and outside setUp/tearDown!
*/
- public function provideTitles() {
+ public static function provideTitles() {
return array(
array( 'Text', NS_MEDIA, 'Media:Text' ),
array( 'Text', null, 'Text' ),
array( 'text', null, 'Text' ),
array( 'Text', NS_USER, 'User:Text' ),
- array( 'Photo.jpg', NS_IMAGE, 'File:Photo.jpg' )
+ array( 'Photo.jpg', NS_FILE, 'File:Photo.jpg' )
);
}
* example) as arguments to the next method (e.g. $title in
* testTitleDepends is whatever testInitialCreatiion returned.)
*/
+
/**
* @depends testSetUpMainPageTitleForNextTest
* See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
* See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
*/
function testTitleObjectFromObject() {
- $title = Title::newFromText( new Title( "test" ) );
+ $title = Title::newFromText( Title::newFromText( "test" ) );
$this->assertEquals( "Test", $title->isLocal() );
}
}