MediaWiki REL1_33
SampleTest.php
Go to the documentation of this file.
1<?php
2
7
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).
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
28 protected function tearDown() {
29 parent::tearDown();
30 }
31
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
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
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
74 $title = Title::newMainPage();
75 $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" );
76
77 return $title;
78 }
79
96 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
97 $this->assertTrue( $title->isLocal() );
98 }
99
104 public function testTitleObjectFromObject() {
105 $title = Title::newFromText( Title::newFromText( "test" ) );
106 $this->assertEquals( "Test", $title->isLocal() );
107 }
108}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Base class that store and restore the Language objects.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
@coversNothing Just a sample
Definition SampleTest.php:6
tearDown()
Anything cleanup you need to do should go here.
testTitleObjectStringConversion()
Name tests so that PHPUnit can turn them into sentences when they run.
testTitleObjectFromObject()
InvalidArgumentException See https://phpunit.de/manual/3.7/en/appendixes.annotations....
setUp()
Anything that needs to happen before your tests should go here.
testCheckMainPageTitleIsConsideredLocal( $title)
Instead of putting a bunch of tests in a single test method, you should put only one or two tests in ...
testSetUpMainPageTitleForNextTest()
static provideTitles()
If you want to run the same test with a variety of data, use a data provider.
testCreateBasicListOfTitles( $titleName, $ns, $text)
phpcs:disable Generic.Files.LineLength provideTitles See https://phpunit.de/manual/3....
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
const NS_USER
Definition Defines.php:75
const NS_FILE
Definition Defines.php:79
const NS_MEDIA
Definition Defines.php:61