2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2011-05-01 19:32:49 +00:00
|
|
|
class TestSample extends MediaWikiLangTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Anything that needs to happen before your tests should go here.
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
// Be sure to do call the parent setup and teardown functions.
|
|
|
|
|
// This makes sure that all the various cleanup and restorations
|
|
|
|
|
// happen as they should (including the restoration for setMwGlobals).
|
2011-06-15 21:03:08 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
// This sets the globals and will restore them automatically
|
|
|
|
|
// after each test.
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgContLang' => Language::factory( 'en' ),
|
|
|
|
|
) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Anything cleanup you need to do should go here.
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function tearDown() {
|
2011-06-14 21:21:26 +00:00
|
|
|
parent::tearDown();
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name tests so that PHPUnit can turn them into sentances when
|
|
|
|
|
* they run. While MediaWiki isn't strictly an Agile Programming
|
|
|
|
|
* project, you are encouraged to use the naming described under
|
|
|
|
|
* "Agile Documentation" at
|
|
|
|
|
* http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
|
|
|
|
|
*/
|
|
|
|
|
function testTitleObjectStringConversion() {
|
|
|
|
|
$title = Title::newFromText("text");
|
|
|
|
|
$this->assertEquals("Text", $title->__toString(), "Title creation");
|
|
|
|
|
$this->assertEquals("Text", "Text", "Automatic string conversion");
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText("text", NS_MEDIA);
|
|
|
|
|
$this->assertEquals("Media:Text", $title->__toString(), "Title creation with namespace");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If you want to run a the same test with a variety of data. use a data provider.
|
|
|
|
|
* see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
|
2012-10-08 10:56:20 +00:00
|
|
|
*
|
|
|
|
|
* Note: Data providers are always called statically and outside setUp/tearDown!
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideTitles() {
|
2010-12-14 16:26:35 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'Text', NS_MEDIA, 'Media:Text' ),
|
|
|
|
|
array( 'Text', null, 'Text' ),
|
|
|
|
|
array( 'text', null, 'Text' ),
|
|
|
|
|
array( 'Text', NS_USER, 'User:Text' ),
|
2012-06-24 19:50:10 +00:00
|
|
|
array( 'Photo.jpg', NS_FILE, 'File:Photo.jpg' )
|
2010-12-14 16:26:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTitles
|
|
|
|
|
* See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateBasicListOfTitles($titleName, $ns, $text) {
|
|
|
|
|
$title = Title::newFromText($titleName, $ns);
|
|
|
|
|
$this->assertEquals($text, "$title", "see if '$titleName' matches '$text'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetUpMainPageTitleForNextTest() {
|
|
|
|
|
$title = Title::newMainPage();
|
|
|
|
|
$this->assertEquals("Main Page", "$title", "Test initial creation of a title");
|
|
|
|
|
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Instead of putting a bunch of tests in a single test method,
|
|
|
|
|
* you should put only one or two tests in each test method. This
|
|
|
|
|
* way, the test method names can remain descriptive.
|
|
|
|
|
*
|
|
|
|
|
* If you want to make tests depend on data created in another
|
|
|
|
|
* method, you can create dependencies feed whatever you return
|
|
|
|
|
* from the dependant method (e.g. testInitialCreation in this
|
|
|
|
|
* example) as arguments to the next method (e.g. $title in
|
|
|
|
|
* testTitleDepends is whatever testInitialCreatiion returned.)
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testSetUpMainPageTitleForNextTest
|
|
|
|
|
* See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
|
|
|
|
|
*/
|
|
|
|
|
public function testCheckMainPageTitleIsConsideredLocal( $title ) {
|
|
|
|
|
$this->assertTrue( $title->isLocal() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException MWException object
|
|
|
|
|
* See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
|
|
|
|
|
*/
|
|
|
|
|
function testTitleObjectFromObject() {
|
2011-04-18 23:20:21 +00:00
|
|
|
$title = Title::newFromText( Title::newFromText( "test" ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( "Test", $title->isLocal() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|