Merge "Documentation: Remove paragraph about not creating a 2nd WebRequest"
[lhc/web/wiklou.git] / tests / phpunit / includes / title / SubpageImportTitleFactoryTest.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author This, that and the other
20 */
21
22 /**
23 * @covers SubpageImportTitleFactory
24 *
25 * @group Title
26 */
27 class SubpageImportTitleFactoryTest extends MediaWikiTestCase {
28
29 protected function setUp() {
30 parent::setUp();
31
32 $this->setMwGlobals( array(
33 'wgLanguageCode' => 'en',
34 'wgContLang' => Language::factory( 'en' ),
35 'wgNamespacesWithSubpages' => array( 0 => false, 2 => true ),
36 ) );
37 }
38
39 public function basicProvider() {
40 return array(
41 array(
42 new ForeignTitle( 0, '', 'MainNamespaceArticle' ),
43 Title::newFromText( 'User:Graham' ),
44 Title::newFromText( 'User:Graham/MainNamespaceArticle' )
45 ),
46 array(
47 new ForeignTitle( 1, 'Discussion', 'Nice_talk' ),
48 Title::newFromText( 'User:Graham' ),
49 Title::newFromText( 'User:Graham/Discussion:Nice_talk' )
50 ),
51 array(
52 new ForeignTitle( 0, '', 'Bogus:Nice_talk' ),
53 Title::newFromText( 'User:Graham' ),
54 Title::newFromText( 'User:Graham/Bogus:Nice_talk' )
55 ),
56 );
57 }
58
59 /**
60 * @dataProvider basicProvider
61 */
62 public function testBasic( ForeignTitle $foreignTitle, Title $rootPage,
63 Title $title ) {
64
65 $factory = new SubpageImportTitleFactory( $rootPage );
66 $testTitle = $factory->createTitleFromForeignTitle( $foreignTitle );
67
68 $this->assertTrue( $testTitle->equals( $title ) );
69 }
70
71 public function failureProvider() {
72 return array(
73 array(
74 Title::newFromText( 'Graham' ),
75 ),
76 );
77 }
78
79 /**
80 * @dataProvider failureProvider
81 */
82 public function testFailures( Title $rootPage ) {
83 $this->setExpectedException( 'MWException' );
84 new SubpageImportTitleFactory( $rootPage );
85 }
86 }