3 class TestSample
extends PHPUnit_Framework_TestCase
{
6 * Anything that needs to happen before your tests should go here.
12 * Anything cleanup you need to do should go here.
18 * Name tests so that PHPUnit can turn them into sentances when
19 * they run. While MediaWiki isn't strictly an Agile Programming
20 * project, you are encouraged to use the naming described under
21 * "Agile Documentation" at
22 * http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
24 function testTitleObjectStringConversion() {
25 $title = Title
::newFromText("text");
26 $this->assertEquals("Text", $title->__toString(), "Title creation");
27 $this->assertEquals("Text", "Text", "Automatic string conversion");
29 $title = Title
::newFromText("text", NS_MEDIA
);
30 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
35 * If you want to run a the same test with a variety of data. use a data provider.
36 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
38 public function provideTitles() {
40 array( 'Text', NS_MEDIA
, 'Media:Text' ),
41 array( 'Text', null, 'Text' ),
42 array( 'text', null, 'Text' ),
43 array( 'Text', NS_USER
, 'User:Text' ),
44 array( 'Text', NS_USER
, 'Blah' )
49 * @dataProvider provideTitles
50 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
52 public function testCreateBasicListOfTitles($titleName, $ns, $text) {
53 $title = Title
::newFromText($titleName, $ns);
54 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
57 public function testSetUpMainPageTitleForNextTest() {
58 $title = Title
::newMainPage();
59 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
65 * Instead of putting a bunch of tests in a single test method,
66 * you should put only one or two tests in each test method. This
67 * way, the test method names can remain descriptive.
69 * If you want to make tests depend on data created in another
70 * method, you can create dependencies feed whatever you return
71 * from the dependant method (e.g. testInitialCreation in this
72 * example) as arguments to the next method (e.g. $title in
73 * testTitleDepends is whatever testInitialCreatiion returned.)
76 * @depends testSetUpMainPageTitleForNextTest
77 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
79 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
80 $this->assertTrue( $title->isLocal() );
84 * @expectedException MWException object
85 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
87 function testTitleObjectFromObject() {
88 $title = Title
::newFromText(new Title("test"));
89 $this->assertEquals( "Test", $title->isLocal() );