da6df70e69ec66a09ba4341bec236487f60a335e
4 * @coversNothing Just a sample
6 class SampleTest
extends MediaWikiLangTestCase
{
9 * Anything that needs to happen before your tests should go here.
11 protected function setUp() {
12 // Be sure to call the parent setup and teardown functions.
13 // This makes sure that all the various cleanup and restorations
14 // happen as they should (including the restoration for setMwGlobals).
17 // This sets the globals and will restore them automatically
19 $this->setContentLang( 'en' );
20 $this->setMwGlobals( [
21 'wgCapitalLinks' => true,
26 * Anything cleanup you need to do should go here.
28 protected function tearDown() {
33 * Name tests so that PHPUnit can turn them into sentences when
34 * they run. While MediaWiki isn't strictly an Agile Programming
35 * project, you are encouraged to use the naming described under
36 * "Agile Documentation" at
37 * https://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html
39 public function testTitleObjectStringConversion() {
40 $title = Title
::newFromText( "text" );
41 $this->assertInstanceOf( Title
::class, $title, "Title creation" );
42 $this->assertEquals( "Text", $title, "Automatic string conversion" );
44 $title = Title
::newFromText( "text", NS_MEDIA
);
45 $this->assertEquals( "Media:Text", $title, "Title creation with namespace" );
49 * If you want to run the same test with a variety of data, use a data provider.
50 * see: https://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
52 public static function provideTitles() {
54 [ 'Text', NS_MEDIA
, 'Media:Text' ],
55 [ 'Text', null, 'Text' ],
56 [ 'text', null, 'Text' ],
57 [ 'Text', NS_USER
, 'User:Text' ],
58 [ 'Photo.jpg', NS_FILE
, 'File:Photo.jpg' ]
63 * phpcs:disable Generic.Files.LineLength
64 * @dataProvider provideTitles
65 * See https://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.dataProvider
68 public function testCreateBasicListOfTitles( $titleName, $ns, $text ) {
69 $title = Title
::newFromText( $titleName, $ns );
70 $this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" );
73 public function testSetUpMainPageTitleForNextTest() {
74 $title = Title
::newMainPage();
75 $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" );
81 * Instead of putting a bunch of tests in a single test method,
82 * you should put only one or two tests in each test method. This
83 * way, the test method names can remain descriptive.
85 * If you want to make tests depend on data created in another
86 * method, you can create dependencies feed whatever you return
87 * from the dependant method (e.g. testInitialCreation in this
88 * example) as arguments to the next method (e.g. $title in
89 * testTitleDepends is whatever testInitialCreatiion returned.)
93 * @depends testSetUpMainPageTitleForNextTest
94 * See https://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.depends
96 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
97 $this->assertTrue( $title->isLocal() );
101 * @expectedException InvalidArgumentException
102 * See https://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.expectedException
104 public function testTitleObjectFromObject() {
105 $title = Title
::newFromText( Title
::newFromText( "test" ) );
106 $this->assertEquals( "Test", $title->isLocal() );