Use more descriptive names for the test methods.
[lhc/web/wiklou.git] / maintenance / tests / phpunit / includes / SampleTest.php
1 <?php
2
3 class TestSample extends PHPUnit_Framework_TestCase {
4
5 /**
6 * Anything that needs to happen before your tests should go here.
7 */
8 function setUp() {
9 }
10
11 /**
12 * Anything cleanup you need to do should go here.
13 */
14 function tearDown() {
15 }
16
17 /**
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
23 */
24 function testTitleObjectStringConversion() {
25 $title = Title::newFromText("text");
26 $this->assertEquals("Text", $title->__toString(), "Title creation");
27 $this->assertEquals("Text", "Text", "Automatic string conversion");
28
29 $title = Title::newFromText("text", NS_MEDIA);
30 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
31
32 }
33
34 /**
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
37 */
38 public function provideTitles() {
39 return array(
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' )
45 );
46 }
47
48 /**
49 * @dataProvider provideTitles
50 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
51 */
52 public function testCreateBasicListOfTitles($titleName, $ns, $text) {
53 $title = Title::newFromText($titleName, $ns);
54 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
55 }
56
57 public function testSetUpMainPageTitleForNextTest() {
58 $title = Title::newMainPage();
59 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
60
61 return $title;
62 }
63
64 /**
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.
68 *
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.)
74 */
75 /**
76 * @depends testSetUpMainPageTitleForNextTest
77 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
78 */
79 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
80 $this->assertTrue( $title->isLocal() );
81 }
82
83 /**
84 * @expectedException MWException object
85 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
86 */
87 function testTitleObjectFromObject() {
88 $title = Title::newFromText(new Title("test"));
89 $this->assertEquals( "Test", $title->isLocal() );
90 }
91 }
92