Index: trunk/phase3/maintenance/tests/phpunit/includes/SampleTest.php |
— | — | @@ -2,9 +2,18 @@ |
3 | 3 | |
4 | 4 | class TestSample extends PHPUnit_Framework_TestCase { |
5 | 5 | |
| 6 | + /** |
| 7 | + * Anything that needs to happen before your tests should go here. |
| 8 | + */ |
6 | 9 | function setUp() { |
7 | 10 | } |
8 | 11 | |
| 12 | + /** |
| 13 | + * Anything cleanup you need to do should go here. |
| 14 | + */ |
| 15 | + function tearDown() { |
| 16 | + } |
| 17 | + |
9 | 18 | function testEqual() { |
10 | 19 | $title = Title::newFromText("text"); |
11 | 20 | $this->assertEquals("Text", $title->__toString(), "Title creation"); |
— | — | @@ -16,6 +25,27 @@ |
17 | 26 | } |
18 | 27 | |
19 | 28 | /** |
| 29 | + * If you want to run a the same test with a variety of data. use a data provider. |
| 30 | + * See: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html |
| 31 | + */ |
| 32 | + public function provideTitles() { |
| 33 | + return array( |
| 34 | + array( 'Text', NS_MEDIA, 'Media: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 | + /** |
20 | 50 | * @expectedException MWException object |
21 | 51 | * |
22 | 52 | * Above comment tells PHPUnit to expect an exception of the |