Update documentation a bit more.
[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 function testEqual() {
18 $title = Title::newFromText("text");
19 $this->assertEquals("Text", $title->__toString(), "Title creation");
20 $this->assertEquals("Text", "Text", "Automatic string conversion");
21
22 $title = Title::newFromText("text", NS_MEDIA);
23 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
24
25 }
26
27 /**
28 * If you want to run a the same test with a variety of data. use a data provider.
29 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
30 */
31 public function provideTitles() {
32 return array(
33 array( 'Text', NS_MEDIA, 'Media:Text' ),
34 array( 'Text', null, 'Text' ),
35 array( 'text', null, 'Text' ),
36 array( 'Text', NS_USER, 'User:Text' ),
37 array( 'Text', NS_USER, 'Blah' )
38 );
39 }
40
41 /**
42 * @dataProvider provideTitles()
43 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
44 */
45 public function testTitleCreation($titleName, $ns, $text) {
46 $title = Title::newFromText($titleName, $ns);
47 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
48 }
49
50 public function testInitialCreation() {
51 $title = Title::newMainPage();
52 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
53
54 return $title;
55 }
56
57 /**
58 * Instead of putting a bunch of tests in a single test method,
59 * you should put only one or two tests in each test method. This
60 * way, the test method names can remain descriptive.
61 *
62 * If you want to make tests depend on data created in another
63 * method, you can create dependencies feed whatever you return
64 * from the dependant method (e.g. testInitialCreation in this
65 * example) as arguments to the next method (e.g. $title in
66 * testTitleDepends is whatever testInitialCreatiion returned.)
67 */
68 /**
69 * @depends testInitialCreation
70 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
71 */
72 public function testTitleDepends( $title ) {
73 $this->assertTrue( $title->isLocal() );
74 }
75
76 /**
77 * If the code you're testing can produce Exceptions, you can also
78 * test for them. In the following example, the test expects a
79 * MWException containing the string "object" in the message..
80 */
81 /**
82 * @expectedException MWException object
83 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
84 */
85 function testException() {
86 $title = Title::newFromText(new Title("test"));
87 }
88 }