MediaWiki REL1_28
Go to the documentation of this file.
8 protected function setUp() {
9 // Be sure to do call the parent setup and teardown functions.
10 // This makes sure that all the various cleanup and restorations
11 // happen as they should (including the restoration for setMwGlobals).
12 parent::setUp();
14 // This sets the globals and will restore them automatically
15 // after each test.
16 $this->setMwGlobals( [
17 'wgContLang' => Language::factory( 'en' ),
18 'wgLanguageCode' => 'en',
19 'wgCapitalLinks' => true,
20 ] );
21 }
26 protected function tearDown() {
27 parent::tearDown();
28 }
38 $title = Title::newFromText( "text" );
39 $this->assertInstanceOf( 'Title', $title, "Title creation" );
40 $this->assertEquals( "Text", $title, "Automatic string conversion" );
42 $title = Title::newFromText( "text", NS_MEDIA );
43 $this->assertEquals( "Media:Text", $title, "Title creation with namespace" );
44 }
50 public static function provideTitles() {
51 return [
52 [ 'Text', NS_MEDIA, 'Media:Text' ],
53 [ 'Text', null, 'Text' ],
54 [ 'text', null, 'Text' ],
55 [ 'Text', NS_USER, 'User:Text' ],
56 [ 'Photo.jpg', NS_FILE, 'File:Photo.jpg' ]
57 ];
58 }
60 // @codingStandardsIgnoreStart Generic.Files.LineLength
65 // @codingStandardsIgnoreEnd
66 public function testCreateBasicListOfTitles( $titleName, $ns, $text ) {
67 $title = Title::newFromText( $titleName, $ns );
68 $this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" );
69 }
72 $title = Title::newMainPage();
73 $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" );
75 return $title;
76 }
94 public function testCheckMainPageTitleIsConsideredLocal( $title ) {
95 $this->assertTrue( $title->isLocal() );
96 }
98 // @codingStandardsIgnoreStart Generic.Files.LineLength
103 // @codingStandardsIgnoreEnd
104 public function testTitleObjectFromObject() {
105 $title = Title::newFromText( Title::newFromText( "test" ) );
106 $this->assertEquals( "Test", $title->isLocal() );
107 }
Base class that store and restore the Language objects.
setMwGlobals( $pairs, $value=null)
InvalidArgumentException See
testCheckMainPageTitleIsConsideredLocal( $title)
Instead of putting a bunch of tests in a single test method, you should put only one or two tests in ...
Anything cleanup you need to do should go here.
testCreateBasicListOfTitles( $titleName, $ns, $text)
provideTitles See
Anything that needs to happen before your tests should go here.
Definition SampleTest.php:8
Name tests so that PHPUnit can turn them into sentences when they run.
static provideTitles()
If you want to run a the same test with a variety of data, use a data provider.
const NS_USER
Definition Defines.php:58
const NS_FILE
Definition Defines.php:62
const NS_MEDIA
Definition Defines.php:44
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37