Merge "Class renaming didn't went into change 12729"
[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 function setUp() {
9 global $wgContLang;
10 parent::setUp();
11
12 /* For example, we need to set $wgContLang for creating a new Title */
13 $wgContLang = Language::factory( 'en' );
14 }
15
16 /**
17 * Anything cleanup you need to do should go here.
18 */
19 function tearDown() {
20 parent::tearDown();
21 }
22
23 /**
24 * Name tests so that PHPUnit can turn them into sentances when
25 * they run. While MediaWiki isn't strictly an Agile Programming
26 * project, you are encouraged to use the naming described under
27 * "Agile Documentation" at
28 * http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
29 */
30 function testTitleObjectStringConversion() {
31 $title = Title::newFromText("text");
32 $this->assertEquals("Text", $title->__toString(), "Title creation");
33 $this->assertEquals("Text", "Text", "Automatic string conversion");
34
35 $title = Title::newFromText("text", NS_MEDIA);
36 $this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
37
38 }
39
40 /**
41 * If you want to run a the same test with a variety of data. use a data provider.
42 * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
43 */
44 public function provideTitles() {
45 return array(
46 array( 'Text', NS_MEDIA, 'Media:Text' ),
47 array( 'Text', null, 'Text' ),
48 array( 'text', null, 'Text' ),
49 array( 'Text', NS_USER, 'User:Text' ),
50 array( 'Photo.jpg', NS_FILE, 'File:Photo.jpg' )
51 );
52 }
53
54 /**
55 * @dataProvider provideTitles
56 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
57 */
58 public function testCreateBasicListOfTitles($titleName, $ns, $text) {
59 $title = Title::newFromText($titleName, $ns);
60 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
61 }
62
63 public function testSetUpMainPageTitleForNextTest() {
64 $title = Title::newMainPage();
65 $this->assertEquals("Main Page", "$title", "Test initial creation of a title");
66
67 return $title;
68 }
69
70 /**
71 * Instead of putting a bunch of tests in a single test method,
72 * you should put only one or two tests in each test method. This
73 * way, the test method names can remain descriptive.
74 *
75 * If you want to make tests depend on data created in another
76 * method, you can create dependencies feed whatever you return
77 * from the dependant method (e.g. testInitialCreation in this
78 * example) as arguments to the next method (e.g. $title in
79 * testTitleDepends is whatever testInitialCreatiion returned.)
80 */
81 /**
82 * @depends testSetUpMainPageTitleForNextTest
83 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
84 */
85 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
86 $this->assertTrue( $title->isLocal() );
87 }
88
89 /**
90 * @expectedException MWException object
91 * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
92 */
93 function testTitleObjectFromObject() {
94 $title = Title::newFromText( Title::newFromText( "test" ) );
95 $this->assertEquals( "Test", $title->isLocal() );
96 }
97 }
98