Merge "Fix some issues with Microsoft SQL Server Driver"
[lhc/web/wiklou.git] / tests / phpunit / includes / specialpage / SpecialPageFactoryTest.php
1 <?php
2 /**
3 * Factory for handling the special page list and generating SpecialPage objects.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @covers SpecialPageFactory
21 * @group SpecialPage
22 */
23 class SpecialPageFactoryTest extends MediaWikiTestCase {
24
25 public function newSpecialAllPages() {
26 return new SpecialAllPages();
27 }
28
29 public function specialPageProvider() {
30 return array(
31 'class name' => array( 'SpecialAllPages', false ),
32 'closure' => array( function() {
33 return new SpecialAllPages();
34 }, false ),
35 'function' => array( array( $this, 'newSpecialAllPages' ), false ),
36 );
37 }
38
39 /**
40 * @dataProvider specialPageProvider
41 */
42 public function testGetPage( $spec, $shouldReuseInstance ) {
43 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => $spec ) );
44
45 SpecialPageFactory::resetList();
46
47 $page = SpecialPageFactory::getPage( 'testdummy' );
48 $this->assertInstanceOf( 'SpecialPage', $page );
49
50 $page2 = SpecialPageFactory::getPage( 'testdummy' );
51 $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" );
52
53 SpecialPageFactory::resetList();
54 }
55
56 public function testGetNames() {
57 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => 'SpecialAllPages' ) );
58
59 SpecialPageFactory::resetList();
60 $names = SpecialPageFactory::getNames();
61 $this->assertInternalType( 'array', $names );
62 $this->assertContains( 'testdummy', $names );
63 SpecialPageFactory::resetList();
64 }
65
66 public function testResolveAlias() {
67 $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
68
69 SpecialPageFactory::resetList();
70
71 list( $name, $param ) = SpecialPageFactory::resolveAlias( 'Spezialseiten/Foo' );
72 $this->assertEquals( 'Specialpages', $name );
73 $this->assertEquals( 'Foo', $param );
74
75 SpecialPageFactory::resetList();
76 }
77
78 public function testGetLocalNameFor() {
79 $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
80
81 SpecialPageFactory::resetList();
82
83 $name = SpecialPageFactory::getLocalNameFor( 'Specialpages', 'Foo' );
84 $this->assertEquals( 'Spezialseiten/Foo', $name );
85
86 SpecialPageFactory::resetList();
87 }
88
89 public function testGetTitleForAlias() {
90 $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
91
92 SpecialPageFactory::resetList();
93
94 $title = SpecialPageFactory::getTitleForAlias( 'Specialpages/Foo' );
95 $this->assertEquals( 'Spezialseiten/Foo', $title->getText() );
96 $this->assertEquals( NS_SPECIAL, $title->getNamespace() );
97
98 SpecialPageFactory::resetList();
99 }
100
101 }