Follow up r75245.
[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 global $wgContLang;
10 /* For example, we need to set $wgContLang for creating a new Title */
11 $wgContLang = Language::factory( 'en' );
12 }
13
14 /**
15 * Anything cleanup you need to do should go here.
16 */
17 function tearDown() {
18 }
19
20 /**
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
26 */
27 function testTitleObjectStringConversion() {
28 $title = Title::newFromText("text");
29 $this->assertEquals("Text", $title->__toString(), "Title creation");
30 $this->assertEquals("Text", "Text", "Automatic string conversion");
31
32 $title = Title::newFromText("text", NS_MEDIA);
33 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
34
35 }
36
37 /**
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
40 */
41 public function provideTitles() {
42 return array(
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( 'Text', NS_USER, 'Blah' )
48 );
49 }
50
51 /**
52 * @dataProvider provideTitles
53 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
54 */
55 public function testCreateBasicListOfTitles($titleName, $ns, $text) {
56 $title = Title::newFromText($titleName, $ns);
57 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
58 }
59
60 public function testSetUpMainPageTitleForNextTest() {
61 $title = Title::newMainPage();
62 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
63
64 return $title;
65 }
66
67 /**
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.
71 *
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.)
77 */
78 /**
79 * @depends testSetUpMainPageTitleForNextTest
80 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
81 */
82 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
83 $this->assertTrue( $title->isLocal() );
84 }
85
86 /**
87 * @expectedException MWException object
88 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
89 */
90 function testTitleObjectFromObject() {
91 $title = Title::newFromText(new Title("test"));
92 $this->assertEquals( "Test", $title->isLocal() );
93 }
94 }
95