Merge "don't overwrite $item['single-id'] in makeListItem in SkinTemplate"
[lhc/web/wiklou.git] / tests / phpunit / includes / SampleTest.php
1 <?php
2
3 class TestSample extends MediaWikiLangTestCase {
4
5 /**
6 * Anything that needs to happen before your tests should go here.
7 */
8 protected function setUp() {
9 // Be sure to do call the parent setup and teardown functions.
10 // This makes sure that all the various cleanup and restorations
11 // happen as they should (including the restoration for setMwGlobals).
12 parent::setUp();
13
14 // This sets the globals and will restore them automatically
15 // after each test.
16 $this->setMwGlobals( array(
17 'wgContLang' => Language::factory( 'en' ),
18 ) );
19 }
20
21 /**
22 * Anything cleanup you need to do should go here.
23 */
24 protected function tearDown() {
25 parent::tearDown();
26 }
27
28 /**
29 * Name tests so that PHPUnit can turn them into sentances when
30 * they run. While MediaWiki isn't strictly an Agile Programming
31 * project, you are encouraged to use the naming described under
32 * "Agile Documentation" at
33 * http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
34 */
35 function testTitleObjectStringConversion() {
36 $title = Title::newFromText("text");
37 $this->assertEquals("Text", $title->__toString(), "Title creation");
38 $this->assertEquals("Text", "Text", "Automatic string conversion");
39
40 $title = Title::newFromText("text", NS_MEDIA);
41 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
42
43 }
44
45 /**
46 * If you want to run a the same test with a variety of data. use a data provider.
47 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
48 *
49 * Note: Data providers are always called statically and outside setUp/tearDown!
50 */
51 public static function provideTitles() {
52 return array(
53 array( 'Text', NS_MEDIA, 'Media:Text' ),
54 array( 'Text', null, 'Text' ),
55 array( 'text', null, 'Text' ),
56 array( 'Text', NS_USER, 'User:Text' ),
57 array( 'Photo.jpg', NS_FILE, 'File:Photo.jpg' )
58 );
59 }
60
61 /**
62 * @dataProvider provideTitles
63 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
64 */
65 public function testCreateBasicListOfTitles($titleName, $ns, $text) {
66 $title = Title::newFromText($titleName, $ns);
67 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
68 }
69
70 public function testSetUpMainPageTitleForNextTest() {
71 $title = Title::newMainPage();
72 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
73
74 return $title;
75 }
76
77 /**
78 * Instead of putting a bunch of tests in a single test method,
79 * you should put only one or two tests in each test method. This
80 * way, the test method names can remain descriptive.
81 *
82 * If you want to make tests depend on data created in another
83 * method, you can create dependencies feed whatever you return
84 * from the dependant method (e.g. testInitialCreation in this
85 * example) as arguments to the next method (e.g. $title in
86 * testTitleDepends is whatever testInitialCreatiion returned.)
87 */
88
89 /**
90 * @depends testSetUpMainPageTitleForNextTest
91 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
92 */
93 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
94 $this->assertTrue( $title->isLocal() );
95 }
96
97 /**
98 * @expectedException MWException object
99 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
100 */
101 function testTitleObjectFromObject() {
102 $title = Title::newFromText( Title::newFromText( "test" ) );
103 $this->assertEquals( "Test", $title->isLocal() );
104 }
105 }
106