Use setContentLang() instead of setMwGlobals()
[lhc/web/wiklou.git] / tests / phpunit / includes / SampleTest.php
1 <?php
2
3 /**
4 * @coversNothing Just a sample
5 */
6 class SampleTest extends MediaWikiLangTestCase {
7
8 /**
9 * Anything that needs to happen before your tests should go here.
10 */
11 protected function setUp() {
12 // Be sure to do 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).
15 parent::setUp();
16
17 // This sets the globals and will restore them automatically
18 // after each test.
19 $this->setContentLang( 'en' );
20 $this->setMwGlobals( [
21 'wgCapitalLinks' => true,
22 ] );
23 }
24
25 /**
26 * Anything cleanup you need to do should go here.
27 */
28 protected function tearDown() {
29 parent::tearDown();
30 }
31
32 /**
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
38 */
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" );
43
44 $title = Title::newFromText( "text", NS_MEDIA );
45 $this->assertEquals( "Media:Text", $title, "Title creation with namespace" );
46 }
47
48 /**
49 * If you want to run a 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
51 */
52 public static function provideTitles() {
53 return [
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' ]
59 ];
60 }
61
62 /**
63 * phpcs:disable Generic.Files.LineLength
64 * @dataProvider provideTitles
65 * See https://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.dataProvider
66 * phpcs:enable
67 */
68 public function testCreateBasicListOfTitles( $titleName, $ns, $text ) {
69 $title = Title::newFromText( $titleName, $ns );
70 $this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" );
71 }
72
73 public function testSetUpMainPageTitleForNextTest() {
74 $title = Title::newMainPage();
75 $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" );
76
77 return $title;
78 }
79
80 /**
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.
84 *
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.)
90 */
91
92 /**
93 * @depends testSetUpMainPageTitleForNextTest
94 * See https://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.depends
95 */
96 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
97 $this->assertTrue( $title->isLocal() );
98 }
99
100 /**
101 * @expectedException InvalidArgumentException
102 * See https://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.expectedException
103 */
104 public function testTitleObjectFromObject() {
105 $title = Title::newFromText( Title::newFromText( "test" ) );
106 $this->assertEquals( "Test", $title->isLocal() );
107 }
108 }