3 class TestSample
extends MediaWikiLangTestCase
{
6 * Anything that needs to happen before your tests should go here.
12 /* For example, we need to set $wgContLang for creating a new Title */
13 $wgContLang = Language
::factory( 'en' );
17 * Anything cleanup you need to do should go here.
24 * Name tests so that PHPUnit can turn them into sentances when
25 * they run. While MediaWiki isn't strictly an Agile Programming
26 * project, you are encouraged to use the naming described under
27 * "Agile Documentation" at
28 * http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
30 function testTitleObjectStringConversion() {
31 $title = Title
::newFromText("text");
32 $this->assertEquals("Text", $title->__toString(), "Title creation");
33 $this->assertEquals("Text", "Text", "Automatic string conversion");
35 $title = Title
::newFromText("text", NS_MEDIA
);
36 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
41 * If you want to run a the same test with a variety of data. use a data provider.
42 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
44 public function provideTitles() {
46 array( 'Text', NS_MEDIA
, 'Media:Text' ),
47 array( 'Text', null, 'Text' ),
48 array( 'text', null, 'Text' ),
49 array( 'Text', NS_USER
, 'User:Text' ),
50 array( 'Photo.jpg', NS_IMAGE
, 'File:Photo.jpg' )
55 * @dataProvider provideTitles
56 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
58 public function testCreateBasicListOfTitles($titleName, $ns, $text) {
59 $title = Title
::newFromText($titleName, $ns);
60 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
63 public function testSetUpMainPageTitleForNextTest() {
64 $title = Title
::newMainPage();
65 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
71 * Instead of putting a bunch of tests in a single test method,
72 * you should put only one or two tests in each test method. This
73 * way, the test method names can remain descriptive.
75 * If you want to make tests depend on data created in another
76 * method, you can create dependencies feed whatever you return
77 * from the dependant method (e.g. testInitialCreation in this
78 * example) as arguments to the next method (e.g. $title in
79 * testTitleDepends is whatever testInitialCreatiion returned.)
82 * @depends testSetUpMainPageTitleForNextTest
83 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
85 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
86 $this->assertTrue( $title->isLocal() );
90 * @expectedException MWException object
91 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
93 function testTitleObjectFromObject() {
94 $title = Title
::newFromText( Title
::newFromText( "test" ) );
95 $this->assertEquals( "Test", $title->isLocal() );