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