MediaWiki  1.30.0
TitleValueTest.php
Go to the documentation of this file.
1 <?php
28 
29  public function goodConstructorProvider() {
30  return [
31  [ NS_USER, 'TestThis', 'stuff', '', true, false ],
32  [ NS_USER, 'TestThis', '', 'baz', false, true ],
33  ];
34  }
35 
39  public function testConstruction( $ns, $text, $fragment, $interwiki, $hasFragment,
40  $hasInterwiki
41  ) {
42  $title = new TitleValue( $ns, $text, $fragment, $interwiki );
43 
44  $this->assertEquals( $ns, $title->getNamespace() );
45  $this->assertTrue( $title->inNamespace( $ns ) );
46  $this->assertEquals( $text, $title->getText() );
47  $this->assertEquals( $fragment, $title->getFragment() );
48  $this->assertEquals( $hasFragment, $title->hasFragment() );
49  $this->assertEquals( $interwiki, $title->getInterwiki() );
50  $this->assertEquals( $hasInterwiki, $title->isExternal() );
51  }
52 
53  public function badConstructorProvider() {
54  return [
55  [ 'foo', 'title', 'fragment', '' ],
56  [ null, 'title', 'fragment', '' ],
57  [ 2.3, 'title', 'fragment', '' ],
58 
59  [ NS_MAIN, 5, 'fragment', '' ],
60  [ NS_MAIN, null, 'fragment', '' ],
61  [ NS_MAIN, '', 'fragment', '' ],
62  [ NS_MAIN, 'foo bar', '', '' ],
63  [ NS_MAIN, 'bar_', '', '' ],
64  [ NS_MAIN, '_foo', '', '' ],
65  [ NS_MAIN, ' eek ', '', '' ],
66 
67  [ NS_MAIN, 'title', 5, '' ],
68  [ NS_MAIN, 'title', null, '' ],
69  [ NS_MAIN, 'title', [], '' ],
70 
71  [ NS_MAIN, 'title', '', 5 ],
72  [ NS_MAIN, 'title', null, 5 ],
73  [ NS_MAIN, 'title', [], 5 ],
74  ];
75  }
76 
80  public function testConstructionErrors( $ns, $text, $fragment, $interwiki ) {
81  $this->setExpectedException( 'InvalidArgumentException' );
82  new TitleValue( $ns, $text, $fragment, $interwiki );
83  }
84 
85  public function fragmentTitleProvider() {
86  return [
87  [ new TitleValue( NS_MAIN, 'Test' ), 'foo' ],
88  [ new TitleValue( NS_TALK, 'Test', 'foo' ), '' ],
89  [ new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
90  ];
91  }
92 
96  public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
97  $fragmentTitle = $title->createFragmentTarget( $fragment );
98 
99  $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
100  $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
101  $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
102  }
103 
104  public function getTextProvider() {
105  return [
106  [ 'Foo', 'Foo' ],
107  [ 'Foo_Bar', 'Foo Bar' ],
108  ];
109  }
110 
114  public function testGetText( $dbkey, $text ) {
115  $title = new TitleValue( NS_MAIN, $dbkey );
116 
117  $this->assertEquals( $text, $title->getText() );
118  }
119 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
TitleValueTest\badConstructorProvider
badConstructorProvider()
Definition: TitleValueTest.php:53
TitleValueTest\testCreateFragmentTitle
testCreateFragmentTitle(TitleValue $title, $fragment)
fragmentTitleProvider
Definition: TitleValueTest.php:96
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
TitleValueTest\getTextProvider
getTextProvider()
Definition: TitleValueTest.php:104
NS_MAIN
const NS_MAIN
Definition: Defines.php:65
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
TitleValueTest\testGetText
testGetText( $dbkey, $text)
getTextProvider
Definition: TitleValueTest.php:114
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:79
TitleValueTest\testConstructionErrors
testConstructionErrors( $ns, $text, $fragment, $interwiki)
badConstructorProvider
Definition: TitleValueTest.php:80
TitleValueTest\goodConstructorProvider
goodConstructorProvider()
Definition: TitleValueTest.php:29
TitleValueTest\testConstruction
testConstruction( $ns, $text, $fragment, $interwiki, $hasFragment, $hasInterwiki)
goodConstructorProvider
Definition: TitleValueTest.php:39
TitleValueTest
TitleValue.
Definition: TitleValueTest.php:27
NS_USER
const NS_USER
Definition: Defines.php:67
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1965
NS_TALK
const NS_TALK
Definition: Defines.php:66
TitleValueTest\fragmentTitleProvider
fragmentTitleProvider()
Definition: TitleValueTest.php:85
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36