overrideConfigValues( [ MainConfigNames::LanguageCode => 'en', MainConfigNames::CapitalLinks => true, ] ); } /** * Anything cleanup you need to do should go here. */ protected function tearDown(): void { parent::tearDown(); } /** * Name tests so that PHPUnit can turn them into sentences when * they run. You are encouraged to use the naming described at: * https://docs.phpunit.de/en/9.6/annotations.html and * https://docs.phpunit.de/en/9.6/textui.html?highlight=testdox#testdox */ public function testTitleObjectStringConversion() { $title = Title::makeTitle( NS_MAIN, "Text" ); $this->assertInstanceOf( Title::class, $title, "Title creation" ); $this->assertEquals( "Text", $title, "Automatic string conversion" ); $title = Title::makeTitle( NS_MEDIA, "Text" ); $this->assertEquals( "Media:Text", $title, "Title creation with namespace" ); } /** * If you want to run the same test with a variety of data, use a data provider. * See https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html */ public static function provideTitles() { return [ [ 'Text', NS_MEDIA, 'Media:Text' ], [ 'Text', null, 'Text' ], [ 'text', null, 'Text' ], [ 'Text', NS_USER, 'User:Text' ], [ 'Photo.jpg', NS_FILE, 'File:Photo.jpg' ] ]; } /** * @dataProvider provideTitles * See https://docs.phpunit.de/en/9.6/annotations.html#dataprovider */ public function testCreateBasicListOfTitles( $titleName, $ns, $text ) { $title = Title::newFromText( $titleName, $ns ); $this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" ); } /** * 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. */ /** * See https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html?highlight=exceptions#testing-exceptions */ public function testTitleObjectFromObject() { $this->expectException( InvalidArgumentException::class ); Title::newFromText( Title::makeTitle( NS_MAIN, 'Test' ) ); } }