MediaWiki  1.33.0
SubpageImportTitleFactoryTest.php
Go to the documentation of this file.
1 <?php
28 
29  protected function setUp() {
30  parent::setUp();
31 
32  $this->setContentLang( 'en' );
33  $this->setMwGlobals( [
34  'wgNamespacesWithSubpages' => [ 0 => false, 2 => true ],
35  ] );
36  }
37 
38  public function basicProvider() {
39  return [
40  [
41  new ForeignTitle( 0, '', 'MainNamespaceArticle' ),
42  Title::newFromText( 'User:Graham' ),
43  Title::newFromText( 'User:Graham/MainNamespaceArticle' )
44  ],
45  [
46  new ForeignTitle( 1, 'Discussion', 'Nice_talk' ),
47  Title::newFromText( 'User:Graham' ),
48  Title::newFromText( 'User:Graham/Discussion:Nice_talk' )
49  ],
50  [
51  new ForeignTitle( 0, '', 'Bogus:Nice_talk' ),
52  Title::newFromText( 'User:Graham' ),
53  Title::newFromText( 'User:Graham/Bogus:Nice_talk' )
54  ],
55  ];
56  }
57 
61  public function testBasic( ForeignTitle $foreignTitle, Title $rootPage,
63  ) {
64  $factory = new SubpageImportTitleFactory( $rootPage );
65  $testTitle = $factory->createTitleFromForeignTitle( $foreignTitle );
66 
67  $this->assertTrue( $testTitle->equals( $title ) );
68  }
69 
70  public function failureProvider() {
71  return [
72  [
73  Title::newFromText( 'Graham' ),
74  ],
75  ];
76  }
77 
81  public function testFailures( Title $rootPage ) {
82  $this->setExpectedException( MWException::class );
83  new SubpageImportTitleFactory( $rootPage );
84  }
85 }
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:306
SubpageImportTitleFactoryTest\testBasic
testBasic(ForeignTitle $foreignTitle, Title $rootPage, Title $title)
basicProvider
Definition: SubpageImportTitleFactoryTest.php:61
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
SubpageImportTitleFactoryTest\testFailures
testFailures(Title $rootPage)
failureProvider
Definition: SubpageImportTitleFactoryTest.php:81
SubpageImportTitleFactoryTest\setUp
setUp()
Definition: SubpageImportTitleFactoryTest.php:29
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
SubpageImportTitleFactoryTest\basicProvider
basicProvider()
Definition: SubpageImportTitleFactoryTest.php:38
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:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
SubpageImportTitleFactory
A class to convert page titles on a foreign wiki (ForeignTitle objects) into page titles on the local...
Definition: SubpageImportTitleFactory.php:26
SubpageImportTitleFactoryTest
SubpageImportTitleFactory.
Definition: SubpageImportTitleFactoryTest.php:27
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:1066
SubpageImportTitleFactoryTest\failureProvider
failureProvider()
Definition: SubpageImportTitleFactoryTest.php:70
Title
Represents a title within MediaWiki.
Definition: Title.php:40
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
ForeignTitle
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
Definition: ForeignTitle.php:28