1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<?php
/**
* @coversNothing Just a sample
*/
class SampleTest extends MediaWikiLangTestCase {
/**
* Anything that needs to happen before your tests should go here.
*/
protected function setUp(): void {
// Be sure to 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).
parent::setUp();
// This sets the globals and will restore them automatically
// after each test.
$this->setContentLang( 'en' );
$this->setMwGlobals( [
'wgCapitalLinks' => 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://phpunit.de/manual/6.5/en/other-uses-for-tests.html
*/
public function testTitleObjectStringConversion() {
$title = Title::newFromText( "text" );
$this->assertInstanceOf( Title::class, $title, "Title creation" );
$this->assertEquals( "Text", $title, "Automatic string conversion" );
$title = Title::newFromText( "text", NS_MEDIA );
$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://phpunit.de/manual/6.5/en/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://phpunit.de/manual/6.5/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'" );
}
/**
* 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://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.exceptions
*/
public function testTitleObjectFromObject() {
$this->expectException( InvalidArgumentException::class );
Title::newFromText( Title::newFromText( "test" ) );
}
}
|