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