3 * Factory for handling the special page list and generating SpecialPage objects.
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.
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.
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
20 * @covers SpecialPageFactory
23 class SpecialPageFactoryTest
extends MediaWikiTestCase
{
25 public function newSpecialAllPages() {
26 return new SpecialAllPages();
29 public function specialPageProvider() {
31 'class name' => array( 'SpecialAllPages', false ),
32 'closure' => array( function() {
33 return new SpecialAllPages();
35 'function' => array( array( $this, 'newSpecialAllPages' ), false ),
40 * @covers SpecialPageFactory::getPage
41 * @dataProvider specialPageProvider
43 public function testGetPage( $spec, $shouldReuseInstance ) {
44 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => $spec ) );
46 SpecialPageFactory
::resetList();
48 $page = SpecialPageFactory
::getPage( 'testdummy' );
49 $this->assertInstanceOf( 'SpecialPage', $page );
51 $page2 = SpecialPageFactory
::getPage( 'testdummy' );
52 $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" );
54 SpecialPageFactory
::resetList();
58 * @covers SpecialPageFactory::getNames
60 public function testGetNames() {
61 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => 'SpecialAllPages' ) );
63 SpecialPageFactory
::resetList();
64 $names = SpecialPageFactory
::getNames();
65 $this->assertInternalType( 'array', $names );
66 $this->assertContains( 'testdummy', $names );
67 SpecialPageFactory
::resetList();
71 * @covers SpecialPageFactory::resolveAlias
73 public function testResolveAlias() {
74 $this->setMwGlobals( 'wgContLang', Language
::factory( 'de' ) );
76 SpecialPageFactory
::resetList();
78 list( $name, $param ) = SpecialPageFactory
::resolveAlias( 'Spezialseiten/Foo' );
79 $this->assertEquals( 'Specialpages', $name );
80 $this->assertEquals( 'Foo', $param );
82 SpecialPageFactory
::resetList();
86 * @covers SpecialPageFactory::getLocalNameFor
88 public function testGetLocalNameFor() {
89 $this->setMwGlobals( 'wgContLang', Language
::factory( 'de' ) );
91 SpecialPageFactory
::resetList();
93 $name = SpecialPageFactory
::getLocalNameFor( 'Specialpages', 'Foo' );
94 $this->assertEquals( 'Spezialseiten/Foo', $name );
96 SpecialPageFactory
::resetList();
100 * @covers SpecialPageFactory::getTitleForAlias
102 public function testGetTitleForAlias() {
103 $this->setMwGlobals( 'wgContLang', Language
::factory( 'de' ) );
105 SpecialPageFactory
::resetList();
107 $title = SpecialPageFactory
::getTitleForAlias( 'Specialpages/Foo' );
108 $this->assertEquals( 'Spezialseiten/Foo', $title->getText() );
109 $this->assertEquals( NS_SPECIAL
, $title->getNamespace() );
111 SpecialPageFactory
::resetList();