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