MediaWiki  1.32.5
SampleTest.php
Go to the documentation of this file.
1 <?php
2 
7 
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 
28  protected function tearDown() {
29  parent::tearDown();
30  }
31 
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 
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 
75  $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" );
76 
77  return $title;
78  }
79 
97  $this->assertTrue( $title->isLocal() );
98  }
99 
104  public function testTitleObjectFromObject() {
106  $this->assertEquals( "Test", $title->isLocal() );
107  }
108 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:280
SampleTest
@coversNothing Just a sample
Definition: SampleTest.php:6
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:597
NS_FILE
const NS_FILE
Definition: Defines.php:70
SampleTest\testTitleObjectStringConversion
testTitleObjectStringConversion()
Name tests so that PHPUnit can turn them into sentences when they run.
Definition: SampleTest.php:39
php
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:35
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
SampleTest\tearDown
tearDown()
Anything cleanup you need to do should go here.
Definition: SampleTest.php:28
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:706
SampleTest\testTitleObjectFromObject
testTitleObjectFromObject()
InvalidArgumentException See https://phpunit.de/manual/3.7/en/appendixes.annotations....
Definition: SampleTest.php:104
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:1063
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
SampleTest\testCreateBasicListOfTitles
testCreateBasicListOfTitles( $titleName, $ns, $text)
phpcs:disable Generic.Files.LineLength provideTitles See https://phpunit.de/manual/3....
Definition: SampleTest.php:68
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
SampleTest\testCheckMainPageTitleIsConsideredLocal
testCheckMainPageTitleIsConsideredLocal( $title)
Instead of putting a bunch of tests in a single test method, you should put only one or two tests in ...
Definition: SampleTest.php:96
SampleTest\testSetUpMainPageTitleForNextTest
testSetUpMainPageTitleForNextTest()
Definition: SampleTest.php:73
NS_USER
const NS_USER
Definition: Defines.php:66
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
SampleTest\provideTitles
static provideTitles()
If you want to run a the same test with a variety of data, use a data provider.
Definition: SampleTest.php:52
SampleTest\setUp
setUp()
Anything that needs to happen before your tests should go here.
Definition: SampleTest.php:11