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 * @dataProvider specialPageProvider
42 public function testGetPage( $spec, $shouldReuseInstance ) {
43 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => $spec ) );
45 SpecialPageFactory
::resetList();
47 $page = SpecialPageFactory
::getPage( 'testdummy' );
48 $this->assertInstanceOf( 'SpecialPage', $page );
50 $page2 = SpecialPageFactory
::getPage( 'testdummy' );
51 $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" );
53 SpecialPageFactory
::resetList();
56 public function testGetNames() {
57 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => 'SpecialAllPages' ) );
59 SpecialPageFactory
::resetList();
60 $names = SpecialPageFactory
::getNames();
61 $this->assertInternalType( 'array', $names );
62 $this->assertContains( 'testdummy', $names );
63 SpecialPageFactory
::resetList();
66 public function testResolveAlias() {
67 $this->setMwGlobals( 'wgContLang', Language
::factory( 'de' ) );
69 SpecialPageFactory
::resetList();
71 list( $name, $param ) = SpecialPageFactory
::resolveAlias( 'Spezialseiten/Foo' );
72 $this->assertEquals( 'Specialpages', $name );
73 $this->assertEquals( 'Foo', $param );
75 SpecialPageFactory
::resetList();
78 public function testGetLocalNameFor() {
79 $this->setMwGlobals( 'wgContLang', Language
::factory( 'de' ) );
81 SpecialPageFactory
::resetList();
83 $name = SpecialPageFactory
::getLocalNameFor( 'Specialpages', 'Foo' );
84 $this->assertEquals( 'Spezialseiten/Foo', $name );
86 SpecialPageFactory
::resetList();
89 public function testGetTitleForAlias() {
90 $this->setMwGlobals( 'wgContLang', Language
::factory( 'de' ) );
92 SpecialPageFactory
::resetList();
94 $title = SpecialPageFactory
::getTitleForAlias( 'Specialpages/Foo' );
95 $this->assertEquals( 'Spezialseiten/Foo', $title->getText() );
96 $this->assertEquals( NS_SPECIAL
, $title->getNamespace() );
98 SpecialPageFactory
::resetList();