Debian Codegraph @

tests/phpunit/unit/includes/title/NamespaceAwareForeignTitleFactoryTest.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\Title\ForeignTitle;
23 use MediaWiki\Title\NamespaceAwareForeignTitleFactory;
24
25 /**
26 * @covers \MediaWiki\Title\NamespaceAwareForeignTitleFactory
27 *
28 * @group Title
29 */
30 class NamespaceAwareForeignTitleFactoryTest extends \MediaWikiUnitTestCase {
31
32 public static function basicProvider() {
33 return [
34 [
35 'MainNamespaceArticle', 0,
36 new ForeignTitle( 0, '', 'MainNamespaceArticle' ),
37 ],
38 [
39 'MainNamespaceArticle', null,
40 new ForeignTitle( 0, '', 'MainNamespaceArticle' ),
41 ],
42 [
43 'Magic:_The_Gathering', 0,
44 new ForeignTitle( 0, '', 'Magic:_The_Gathering' ),
45 ],
46 [
47 'Talk:Nice_talk', 1,
48 new ForeignTitle( 1, 'Talk', 'Nice_talk' ),
49 ],
50 [
51 'Talk:Magic:_The_Gathering', 1,
52 new ForeignTitle( 1, 'Talk', 'Magic:_The_Gathering' ),
53 ],
54 [
55 'Bogus:Nice_talk', 0,
56 new ForeignTitle( 0, '', 'Bogus:Nice_talk' ),
57 ],
58 [
59 'Bogus:Nice_talk', null,
60 new ForeignTitle( 9000, 'Bogus', 'Nice_talk' ),
61 ],
62 [
63 'Bogus:Nice_talk', 4,
64 new ForeignTitle( 4, 'Bogus', 'Nice_talk' ),
65 ],
66 [
67 'Bogus:Nice_talk', 1,
68 new ForeignTitle( 1, 'Talk', 'Nice_talk' ),
69 ],
70 // Misconfigured wiki with unregistered namespace (T114115)
71 [
72 'Nice_talk', 1234,
73 new ForeignTitle( 1234, 'Ns1234', 'Nice_talk' ),
74 ],
75 ];
76 }
77
78 /**
79 * @dataProvider basicProvider
80 */
81 public function testBasic( $title, $ns, ForeignTitle $foreignTitle ) {
82 $foreignNamespaces = [
83 0 => '', 1 => 'Talk', 100 => 'Portal', 9000 => 'Bogus'
84 ];
85
86 $factory = new NamespaceAwareForeignTitleFactory( $foreignNamespaces );
87 $testTitle = $factory->createForeignTitle( $title, $ns );
88
89 $this->assertEquals( $testTitle->isNamespaceIdKnown(),
90 $foreignTitle->isNamespaceIdKnown() );
91
92 if (
93 $testTitle->isNamespaceIdKnown() &&
94 $foreignTitle->isNamespaceIdKnown()
95 ) {
96 $this->assertEquals( $testTitle->getNamespaceId(),
97 $foreignTitle->getNamespaceId() );
98 }
99
100 $this->assertEquals( $testTitle->getNamespaceName(),
101 $foreignTitle->getNamespaceName() );
102 $this->assertEquals( $testTitle->getText(), $foreignTitle->getText() );
103 }
104 }