| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
use MediaWiki\Title\Title; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class SampleTest extends MediaWikiLangTestCase { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
protected function setUp(): void { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
parent::setUp(); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
$this->overrideConfigValues( [ |
| 23 |
MainConfigNames::LanguageCode => 'en', |
| 24 |
MainConfigNames::CapitalLinks => true, |
| 25 |
] ); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
protected function tearDown(): void { |
| 32 |
parent::tearDown(); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public function testTitleObjectStringConversion() { |
| 41 |
$title = Title::makeTitle( NS_MAIN, "Text" ); |
| 42 |
$this->assertInstanceOf( Title::class, $title, "Title creation" ); |
| 43 |
$this->assertEquals( "Text", $title, "Automatic string conversion" ); |
| 44 |
|
| 45 |
$title = Title::makeTitle( NS_MEDIA, "Text" ); |
| 46 |
$this->assertEquals( "Media:Text", $title, "Title creation with namespace" ); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public static function provideTitles() { |
| 54 |
return [ |
| 55 |
[ 'Text', NS_MEDIA, 'Media:Text' ], |
| 56 |
[ 'Text', null, 'Text' ], |
| 57 |
[ 'text', null, 'Text' ], |
| 58 |
[ 'Text', NS_USER, 'User:Text' ], |
| 59 |
[ 'Photo.jpg', NS_FILE, 'File:Photo.jpg' ] |
| 60 |
]; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public function testCreateBasicListOfTitles( $titleName, $ns, $text ) { |
| 68 |
$title = Title::newFromText( $titleName, $ns ); |
| 69 |
$this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" ); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function testTitleObjectFromObject() { |
| 82 |
$this->expectException( InvalidArgumentException::class ); |
| 83 |
Title::newFromText( Title::makeTitle( NS_MAIN, 'Test' ) ); |
| 84 |
} |
| 85 |
} |