Debian Codegraph @

tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php

raw symbols SCIP
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 use MediaWiki\MainConfigNames;
23 use MediaWiki\Title\ForeignTitle;
24 use MediaWiki\Title\SubpageImportTitleFactory;
25 use MediaWiki\Title\Title;
26
27 /**
28 * @covers \MediaWiki\Title\SubpageImportTitleFactory
29 *
30 * @group Title
31 *
32 * TODO convert to Unit tests
33 */
34 class SubpageImportTitleFactoryTest extends MediaWikiIntegrationTestCase {
35
36 protected function setUp(): void {
37 parent::setUp();
38
39 $this->overrideConfigValues( [
40 MainConfigNames::LanguageCode => 'en',
41 MainConfigNames::NamespacesWithSubpages => [ 0 => false, 2 => true ],
42 ] );
43 }
44
45 private function newSubpageImportTitleFactory( Title $rootPage ) {
46 return new SubpageImportTitleFactory(
47 $this->getServiceContainer()->getNamespaceInfo(),
48 $this->getServiceContainer()->getTitleFactory(),
49 $rootPage
50 );
51 }
52
53 public static function basicProvider() {
54 return [
55 [
56 new ForeignTitle( 0, '', 'MainNamespaceArticle' ),
57 Title::makeTitle( NS_USER, 'Graham' ),
58 Title::makeTitle( NS_USER, 'Graham/MainNamespaceArticle' )
59 ],
60 [
61 new ForeignTitle( 1, 'Discussion', 'Nice_talk' ),
62 Title::makeTitle( NS_USER, 'Graham' ),
63 Title::makeTitle( NS_USER, 'Graham/Discussion:Nice_talk' )
64 ],
65 [
66 new ForeignTitle( 0, '', 'Bogus:Nice_talk' ),
67 Title::makeTitle( NS_USER, 'Graham' ),
68 Title::makeTitle( NS_USER, 'Graham/Bogus:Nice_talk' )
69 ],
70 ];
71 }
72
73 /**
74 * @dataProvider basicProvider
75 */
76 public function testBasic( ForeignTitle $foreignTitle, Title $rootPage,
77 Title $title
78 ) {
79 $factory = $this->newSubpageImportTitleFactory( $rootPage );
80 $testTitle = $factory->createTitleFromForeignTitle( $foreignTitle );
81
82 $this->assertTrue( $testTitle->equals( $title ) );
83 }
84
85 public function testInvalidNamespace() {
86 $this->expectException( InvalidArgumentException::class );
87 $this->newSubpageImportTitleFactory( Title::makeTitle( NS_MAIN, 'Graham' ) );
88 }
89 }