MediaWiki  1.29.1
NaiveForeignTitleFactoryTest.php
Go to the documentation of this file.
1 <?php
28 
29  public function basicProvider() {
30  return [
31  [
32  'MainNamespaceArticle', 0,
33  new ForeignTitle( 0, '', 'MainNamespaceArticle' ),
34  ],
35  [
36  'MainNamespaceArticle', null,
37  new ForeignTitle( null, '', 'MainNamespaceArticle' ),
38  ],
39  [
40  'Talk:Nice_talk', 1,
41  new ForeignTitle( 1, 'Talk', 'Nice_talk' ),
42  ],
43  [
44  'Bogus:Nice_talk', 0,
45  new ForeignTitle( 0, '', 'Bogus:Nice_talk' ),
46  ],
47  [
48  'Bogus:Nice_talk', 9000, // non-existent local namespace ID
49  new ForeignTitle( 9000, 'Bogus', 'Nice_talk' ),
50  ],
51  [
52  'Bogus:Nice_talk', 4, // existing local namespace ID
53  new ForeignTitle( 4, 'Bogus', 'Nice_talk' ),
54  ],
55  [
56  'Talk:Extra:Nice_talk', 1,
57  new ForeignTitle( 1, 'Talk', 'Extra:Nice_talk' ),
58  ],
59  [
60  'Talk:Extra:Nice_talk', null,
61  new ForeignTitle( null, 'Talk', 'Extra:Nice_talk' ),
62  ],
63  ];
64  }
65 
69  public function testBasic( $title, $ns, ForeignTitle $foreignTitle ) {
70  $factory = new NaiveForeignTitleFactory();
71  $testTitle = $factory->createForeignTitle( $title, $ns );
72 
73  $this->assertEquals( $testTitle->isNamespaceIdKnown(),
74  $foreignTitle->isNamespaceIdKnown() );
75 
76  if (
77  $testTitle->isNamespaceIdKnown() &&
78  $foreignTitle->isNamespaceIdKnown()
79  ) {
80  $this->assertEquals( $testTitle->getNamespaceId(),
81  $foreignTitle->getNamespaceId() );
82  }
83 
84  $this->assertEquals( $testTitle->getNamespaceName(),
85  $foreignTitle->getNamespaceName() );
86  $this->assertEquals( $testTitle->getText(), $foreignTitle->getText() );
87 
88  $this->assertEquals( str_replace( ' ', '_', $title ),
89  $foreignTitle->getFullText() );
90  }
91 }
NaiveForeignTitleFactory
A parser that translates page titles on a foreign wiki into ForeignTitle objects, with no knowledge o...
Definition: NaiveForeignTitleFactory.php:26
ForeignTitle\getText
getText()
Definition: ForeignTitle.php:84
ForeignTitle\getFullText
getFullText()
Definition: ForeignTitle.php:89
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
NaiveForeignTitleFactoryTest\basicProvider
basicProvider()
Definition: NaiveForeignTitleFactoryTest.php:29
NaiveForeignTitleFactoryTest\testBasic
testBasic( $title, $ns, ForeignTitle $foreignTitle)
basicProvider
Definition: NaiveForeignTitleFactoryTest.php:69
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
ForeignTitle\getNamespaceName
getNamespaceName()
Definition: ForeignTitle.php:79
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
ForeignTitle\getNamespaceId
getNamespaceId()
Definition: ForeignTitle.php:70
ForeignTitle
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
Definition: ForeignTitle.php:28
NaiveForeignTitleFactoryTest
NaiveForeignTitleFactory.
Definition: NaiveForeignTitleFactoryTest.php:27
ForeignTitle\isNamespaceIdKnown
isNamespaceIdKnown()
Do we know the namespace ID of the page on the foreign wiki?
Definition: ForeignTitle.php:61