Merge "Add @covers tags to SpecialPageFactoryTest"
[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 * @covers SpecialPageFactory::getPage
41 * @dataProvider specialPageProvider
42 */
43 public function testGetPage( $spec, $shouldReuseInstance ) {
44 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => $spec ) );
45
46 SpecialPageFactory::resetList();
47
48 $page = SpecialPageFactory::getPage( 'testdummy' );
49 $this->assertInstanceOf( 'SpecialPage', $page );
50
51 $page2 = SpecialPageFactory::getPage( 'testdummy' );
52 $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" );
53
54 SpecialPageFactory::resetList();
55 }
56
57 /**
58 * @covers SpecialPageFactory::getNames
59 */
60 public function testGetNames() {
61 $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array( 'testdummy' => 'SpecialAllPages' ) );
62
63 SpecialPageFactory::resetList();
64 $names = SpecialPageFactory::getNames();
65 $this->assertInternalType( 'array', $names );
66 $this->assertContains( 'testdummy', $names );
67 SpecialPageFactory::resetList();
68 }
69
70 /**
71 * @covers SpecialPageFactory::resolveAlias
72 */
73 public function testResolveAlias() {
74 $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
75
76 SpecialPageFactory::resetList();
77
78 list( $name, $param ) = SpecialPageFactory::resolveAlias( 'Spezialseiten/Foo' );
79 $this->assertEquals( 'Specialpages', $name );
80 $this->assertEquals( 'Foo', $param );
81
82 SpecialPageFactory::resetList();
83 }
84
85 /**
86 * @covers SpecialPageFactory::getLocalNameFor
87 */
88 public function testGetLocalNameFor() {
89 $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
90
91 SpecialPageFactory::resetList();
92
93 $name = SpecialPageFactory::getLocalNameFor( 'Specialpages', 'Foo' );
94 $this->assertEquals( 'Spezialseiten/Foo', $name );
95
96 SpecialPageFactory::resetList();
97 }
98
99 /**
100 * @covers SpecialPageFactory::getTitleForAlias
101 */
102 public function testGetTitleForAlias() {
103 $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
104
105 SpecialPageFactory::resetList();
106
107 $title = SpecialPageFactory::getTitleForAlias( 'Specialpages/Foo' );
108 $this->assertEquals( 'Spezialseiten/Foo', $title->getText() );
109 $this->assertEquals( NS_SPECIAL, $title->getNamespace() );
110
111 SpecialPageFactory::resetList();
112 }
113
114 }