Debian Codegraph @

tests/phpunit/unit/includes/title/ForeignTitleTest.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
24 /**
25 * @covers \MediaWiki\Title\ForeignTitle
26 *
27 * @group Title
28 */
29 class ForeignTitleTest extends \MediaWikiUnitTestCase {
30
31 public static function basicProvider() {
32 return [
33 [
34 new ForeignTitle( 20, 'Contributor', 'JohnDoe' ),
35 20, 'Contributor', 'JohnDoe'
36 ],
37 [
38 new ForeignTitle( '1', 'Discussion', 'Capital' ),
39 1, 'Discussion', 'Capital'
40 ],
41 [
42 new ForeignTitle( 0, '', 'MainNamespace' ),
43 0, '', 'MainNamespace'
44 ],
45 [
46 new ForeignTitle( 4, 'Some ns', 'Article title with spaces' ),
47 4, 'Some_ns', 'Article_title_with_spaces'
48 ],
49 ];
50 }
51
52 /**
53 * @dataProvider basicProvider
54 */
55 public function testBasic( ForeignTitle $title, $expectedId, $expectedName,
56 $expectedText
57 ) {
58 $this->assertTrue( $title->isNamespaceIdKnown() );
59 $this->assertEquals( $expectedId, $title->getNamespaceId() );
60 $this->assertEquals( $expectedName, $title->getNamespaceName() );
61 $this->assertEquals( $expectedText, $title->getText() );
62 }
63
64 public function testUnknownNamespaceCheck() {
65 $title = new ForeignTitle( null, 'this', 'that' );
66
67 $this->assertFalse( $title->isNamespaceIdKnown() );
68 $this->assertEquals( 'this', $title->getNamespaceName() );
69 $this->assertEquals( 'that', $title->getText() );
70 }
71
72 public function testUnknownNamespaceError() {
73 $this->expectException( RuntimeException::class );
74 $title = new ForeignTitle( null, 'this', 'that' );
75 $title->getNamespaceId();
76 }
77
78 public static function fullTextProvider() {
79 return [
80 [
81 new ForeignTitle( 20, 'Contributor', 'JohnDoe' ),
82 'Contributor:JohnDoe'
83 ],
84 [
85 new ForeignTitle( '1', 'Discussion', 'Capital' ),
86 'Discussion:Capital'
87 ],
88 [
89 new ForeignTitle( 0, '', 'MainNamespace' ),
90 'MainNamespace'
91 ],
92 [
93 new ForeignTitle( 4, 'Some ns', 'Article title with spaces' ),
94 'Some_ns:Article_title_with_spaces'
95 ],
96 ];
97 }
98
99 /**
100 * @dataProvider fullTextProvider
101 */
102 public function testFullText( ForeignTitle $title, $fullText ) {
103 $this->assertEquals( $fullText, $title->getFullText() );
104 }
105 }