Add examples of depends
[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 */
44 public function testTitleCreation($titleName, $ns, $text) {
45 $title = Title::newFromText($titleName, $ns);
46 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
47 }
48
49 public function testInitialCreation() {
50 $title = Title::newMainPage();
51 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
52
53 return $title;
54 }
55
56 /**
57 * Instead of putting a bunch of tests in a single test method,
58 * you should put only one or two tests in each test method. This
59 * way, the test method names can remain descriptive.
60 *
61 * If you want to make tests depend on data created in another
62 * method, you can create dependencies feed whatever you return
63 * from the dependant method (e.g. testInitialCreation in this
64 * example) as arguments to the next method (e.g. $title in
65 * testTitleDepends is whatever testInitialCreatiion returned.)
66 */
67 /**
68 * @depends testInitialCreation
69 */
70 public function testTitleDepends( $title ) {
71 $this->assertTrue( $title->isLocal() );
72 }
73
74 /**
75 * @expectedException MWException object
76 *
77 * Above comment tells PHPUnit to expect an exception of the
78 * MWException class containing the string "object" in the
79 * message.
80 */
81 function testException() {
82 $title = Title::newFromText(new Title("test"));
83 }
84 }