Add a test for capitalization to the data provider
[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 testCreation($titleName, $ns, $text) {
45 $title = Title::newFromText($titleName, $ns);
46 $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
47 }
48
49 /**
50 * @expectedException MWException object
51 *
52 * Above comment tells PHPUnit to expect an exception of the
53 * MWException class containing the string "object" in the
54 * message.
55 */
56 function testException() {
57 $title = Title::newFromText(new Title("test"));
58 }
59 }