test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / SampleTest.php
blob8a881915ad576db07349d857c441418ee4c410d9
1 <?php
3 class TestSample extends MediaWikiLangTestCase {
5 /**
6 * Anything that needs to happen before your tests should go here.
7 */
8 protected function setUp() {
9 // Be sure to do call the parent setup and teardown functions.
10 // This makes sure that all the various cleanup and restorations
11 // happen as they should (including the restoration for setMwGlobals).
12 parent::setUp();
14 // This sets the globals and will restore them automatically
15 // after each test.
16 $this->setMwGlobals( array(
17 'wgContLang' => Language::factory( 'en' ),
18 'wgLanguageCode' => 'en',
19 ) );
22 /**
23 * Anything cleanup you need to do should go here.
25 protected function tearDown() {
26 parent::tearDown();
29 /**
30 * Name tests so that PHPUnit can turn them into sentences when
31 * they run. While MediaWiki isn't strictly an Agile Programming
32 * project, you are encouraged to use the naming described under
33 * "Agile Documentation" at
34 * http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
36 function testTitleObjectStringConversion() {
37 $title = Title::newFromText( "text" );
38 $this->assertInstanceOf( 'Title', $title, "Title creation" );
39 $this->assertEquals( "Text", $title, "Automatic string conversion" );
41 $title = Title::newFromText( "text", NS_MEDIA );
42 $this->assertEquals( "Media:Text", $title, "Title creation with namespace" );
45 /**
46 * If you want to run a the same test with a variety of data. use a data provider.
47 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
49 * Note: Data providers are always called statically and outside setUp/tearDown!
51 public static function provideTitles() {
52 return array(
53 array( 'Text', NS_MEDIA, 'Media:Text' ),
54 array( 'Text', null, 'Text' ),
55 array( 'text', null, 'Text' ),
56 array( 'Text', NS_USER, 'User:Text' ),
57 array( 'Photo.jpg', NS_FILE, 'File:Photo.jpg' )
61 /**
62 * @dataProvider provideTitles
63 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
65 public function testCreateBasicListOfTitles( $titleName, $ns, $text ) {
66 $title = Title::newFromText( $titleName, $ns );
67 $this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" );
70 public function testSetUpMainPageTitleForNextTest() {
71 $title = Title::newMainPage();
72 $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" );
74 return $title;
77 /**
78 * Instead of putting a bunch of tests in a single test method,
79 * you should put only one or two tests in each test method. This
80 * way, the test method names can remain descriptive.
82 * If you want to make tests depend on data created in another
83 * method, you can create dependencies feed whatever you return
84 * from the dependant method (e.g. testInitialCreation in this
85 * example) as arguments to the next method (e.g. $title in
86 * testTitleDepends is whatever testInitialCreatiion returned.)
89 /**
90 * @depends testSetUpMainPageTitleForNextTest
91 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
93 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
94 $this->assertTrue( $title->isLocal() );
97 /**
98 * @expectedException MWException object
99 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
101 function testTitleObjectFromObject() {
102 $title = Title::newFromText( Title::newFromText( "test" ) );
103 $this->assertEquals( "Test", $title->isLocal() );