diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:31:04 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:58:39 +0200 |
commit | f6d65e533c62f6deb21342d4901ece24497b433e (patch) | |
tree | f28adf0362d14bcd448f7b65a7aaf38650f923aa /tests/phpunit/includes/title | |
parent | c27b2e832fe25651ef2410fae85b41072aae7519 (diff) |
Update to MediaWiki 1.25.1
Diffstat (limited to 'tests/phpunit/includes/title')
9 files changed, 538 insertions, 10 deletions
diff --git a/tests/phpunit/includes/title/ForeignTitleTest.php b/tests/phpunit/includes/title/ForeignTitleTest.php new file mode 100644 index 00000000..599d2a33 --- /dev/null +++ b/tests/phpunit/includes/title/ForeignTitleTest.php @@ -0,0 +1,103 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author This, that and the other + */ + +/** + * @covers ForeignTitle + * + * @group Title + */ +class ForeignTitleTest extends MediaWikiTestCase { + + public function basicProvider() { + return array( + array( + new ForeignTitle( 20, 'Contributor', 'JohnDoe' ), + 20, 'Contributor', 'JohnDoe' + ), + array( + new ForeignTitle( '1', 'Discussion', 'Capital' ), + 1, 'Discussion', 'Capital' + ), + array( + new ForeignTitle( 0, '', 'MainNamespace' ), + 0, '', 'MainNamespace' + ), + array( + new ForeignTitle( 4, 'Some ns', 'Article title with spaces' ), + 4, 'Some_ns', 'Article_title_with_spaces' + ), + ); + } + + /** + * @dataProvider basicProvider + */ + public function testBasic( ForeignTitle $title, $expectedId, $expectedName, + $expectedText ) { + + $this->assertEquals( true, $title->isNamespaceIdKnown() ); + $this->assertEquals( $expectedId, $title->getNamespaceId() ); + $this->assertEquals( $expectedName, $title->getNamespaceName() ); + $this->assertEquals( $expectedText, $title->getText() ); + } + + public function testUnknownNamespaceCheck( ) { + $title = new ForeignTitle( null, 'this', 'that' ); + + $this->assertEquals( false, $title->isNamespaceIdKnown() ); + $this->assertEquals( 'this', $title->getNamespaceName() ); + $this->assertEquals( 'that', $title->getText() ); + } + + public function testUnknownNamespaceError( ) { + $this->setExpectedException( 'MWException' ); + $title = new ForeignTitle( null, 'this', 'that' ); + $title->getNamespaceId(); + } + + public function fullTextProvider() { + return array( + array( + new ForeignTitle( 20, 'Contributor', 'JohnDoe' ), + 'Contributor:JohnDoe' + ), + array( + new ForeignTitle( '1', 'Discussion', 'Capital' ), + 'Discussion:Capital' + ), + array( + new ForeignTitle( 0, '', 'MainNamespace' ), + 'MainNamespace' + ), + array( + new ForeignTitle( 4, 'Some ns', 'Article title with spaces' ), + 'Some_ns:Article_title_with_spaces' + ), + ); + } + + /** + * @dataProvider fullTextProvider + */ + public function testFullText( ForeignTitle $title, $fullText ) { + $this->assertEquals( $fullText, $title->getFullText() ); + } +} diff --git a/tests/phpunit/includes/title/MediaWikiPageLinkRendererTest.php b/tests/phpunit/includes/title/MediaWikiPageLinkRendererTest.php index 4171c10e..cd0d0b1c 100644 --- a/tests/phpunit/includes/title/MediaWikiPageLinkRendererTest.php +++ b/tests/phpunit/includes/title/MediaWikiPageLinkRendererTest.php @@ -16,7 +16,6 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @license GPL 2+ * @author Daniel Kinzler */ diff --git a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php index f95b3050..78d304c1 100644 --- a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php +++ b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php @@ -16,7 +16,6 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @license GPL 2+ * @author Daniel Kinzler */ @@ -39,6 +38,7 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase { 'wgLang' => Language::factory( 'en' ), 'wgAllowUserJs' => false, 'wgDefaultLanguageVariant' => false, + 'wgMetaNamespace' => 'Project', 'wgLocalInterwikis' => array( 'localtestiw' ), 'wgCapitalLinks' => true, @@ -82,6 +82,8 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase { protected function makeCodec( $lang ) { $gender = $this->getGenderCache(); $lang = Language::factory( $lang ); + // language object can came from cache, which does not respect test settings + $lang->resetNamespaces(); return new MediaWikiTitleCodec( $lang, $gender ); } @@ -367,13 +369,6 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase { /** * @dataProvider provideGetNamespaceName - * - * @param int $namespace - * @param string $text - * @param string $lang - * @param string $expected - * - * @internal param \TitleValue $title */ public function testGetNamespaceName( $namespace, $text, $lang, $expected ) { $codec = $this->makeCodec( $lang ); diff --git a/tests/phpunit/includes/title/NaiveForeignTitleFactoryTest.php b/tests/phpunit/includes/title/NaiveForeignTitleFactoryTest.php new file mode 100644 index 00000000..504e8712 --- /dev/null +++ b/tests/phpunit/includes/title/NaiveForeignTitleFactoryTest.php @@ -0,0 +1,91 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author This, that and the other + */ + +/** + * @covers NaiveForeignTitleFactory + * + * @group Title + */ +class NaiveForeignTitleFactoryTest extends MediaWikiTestCase { + + public function basicProvider() { + return array( + array( + 'MainNamespaceArticle', 0, + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + ), + array( + 'MainNamespaceArticle', null, + new ForeignTitle( null, '', 'MainNamespaceArticle' ), + ), + array( + 'Talk:Nice_talk', 1, + new ForeignTitle( 1, 'Talk', 'Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', 0, + new ForeignTitle( 0, '', 'Bogus:Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', 9000, // non-existent local namespace ID + new ForeignTitle( 9000, 'Bogus', 'Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', 4, // existing local namespace ID + new ForeignTitle( 4, 'Bogus', 'Nice_talk' ), + ), + array( + 'Talk:Extra:Nice_talk', 1, + new ForeignTitle( 1, 'Talk', 'Extra:Nice_talk' ), + ), + array( + 'Talk:Extra:Nice_talk', null, + new ForeignTitle( null, 'Talk', 'Extra:Nice_talk' ), + ), + ); + } + + /** + * @dataProvider basicProvider + */ + public function testBasic( $title, $ns, ForeignTitle $foreignTitle ) { + $factory = new NaiveForeignTitleFactory(); + $testTitle = $factory->createForeignTitle( $title, $ns ); + + $this->assertEquals( $testTitle->isNamespaceIdKnown(), + $foreignTitle->isNamespaceIdKnown() ); + + if ( + $testTitle->isNamespaceIdKnown() && + $foreignTitle->isNamespaceIdKnown() + ) { + $this->assertEquals( $testTitle->getNamespaceId(), + $foreignTitle->getNamespaceId() ); + } + + $this->assertEquals( $testTitle->getNamespaceName(), + $foreignTitle->getNamespaceName() ); + $this->assertEquals( $testTitle->getText(), $foreignTitle->getText() ); + + $this->assertEquals( str_replace( ' ', '_', $title ), + $foreignTitle->getFullText() ); + } +} diff --git a/tests/phpunit/includes/title/NaiveImportTitleFactoryTest.php b/tests/phpunit/includes/title/NaiveImportTitleFactoryTest.php new file mode 100644 index 00000000..98b414e0 --- /dev/null +++ b/tests/phpunit/includes/title/NaiveImportTitleFactoryTest.php @@ -0,0 +1,89 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author This, that and the other + */ + +/** + * @covers NaiveImportTitleFactory + * + * @group Title + */ +class NaiveImportTitleFactoryTest extends MediaWikiTestCase { + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + 'wgLanguageCode' => 'en', + 'wgContLang' => Language::factory( 'en' ), + 'wgExtraNamespaces' => array( 100 => 'Portal' ), + ) ); + } + + public function basicProvider() { + return array( + array( + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + Title::newFromText( 'MainNamespaceArticle' ) + ), + array( + new ForeignTitle( null, '', 'MainNamespaceArticle' ), + Title::newFromText( 'MainNamespaceArticle' ) + ), + array( + new ForeignTitle( 1, 'Discussion', 'Nice_talk' ), + Title::newFromText( 'Talk:Nice_talk' ) + ), + array( + new ForeignTitle( 0, '', 'Bogus:Nice_talk' ), + Title::newFromText( 'Bogus:Nice_talk' ) + ), + array( + new ForeignTitle( 100, 'Bogus', 'Nice_talk' ), + Title::newFromText( 'Bogus:Nice_talk' ) // not Portal:Nice_talk + ), + array( + new ForeignTitle( 1, 'Bogus', 'Nice_talk' ), + Title::newFromText( 'Talk:Nice_talk' ) // not Bogus:Nice_talk + ), + array( + new ForeignTitle( 100, 'Portal', 'Nice_talk' ), + Title::newFromText( 'Portal:Nice_talk' ) + ), + array( + new ForeignTitle( 724, 'Portal', 'Nice_talk' ), + Title::newFromText( 'Portal:Nice_talk' ) + ), + array( + new ForeignTitle( 2, 'Portal', 'Nice_talk' ), + Title::newFromText( 'User:Nice_talk' ) + ), + ); + } + + /** + * @dataProvider basicProvider + */ + public function testBasic( ForeignTitle $foreignTitle, Title $title ) { + $factory = new NaiveImportTitleFactory(); + $testTitle = $factory->createTitleFromForeignTitle( $foreignTitle ); + + $this->assertTrue( $title->equals( $testTitle ) ); + } +} diff --git a/tests/phpunit/includes/title/NamespaceAwareForeignTitleFactoryTest.php b/tests/phpunit/includes/title/NamespaceAwareForeignTitleFactoryTest.php new file mode 100644 index 00000000..9cb195cc --- /dev/null +++ b/tests/phpunit/includes/title/NamespaceAwareForeignTitleFactoryTest.php @@ -0,0 +1,89 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author This, that and the other + */ + +/** + * @covers NamespaceAwareForeignTitleFactory + * + * @group Title + */ +class NamespaceAwareForeignTitleFactoryTest extends MediaWikiTestCase { + + public function basicProvider() { + return array( + array( + 'MainNamespaceArticle', 0, + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + ), + array( + 'MainNamespaceArticle', null, + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + ), + array( + 'Talk:Nice_talk', 1, + new ForeignTitle( 1, 'Talk', 'Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', 0, + new ForeignTitle( 0, '', 'Bogus:Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', null, + new ForeignTitle( 9000, 'Bogus', 'Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', 4, + new ForeignTitle( 4, 'Bogus', 'Nice_talk' ), + ), + array( + 'Bogus:Nice_talk', 1, + new ForeignTitle( 1, 'Talk', 'Nice_talk' ), + ), + ); + } + + /** + * @dataProvider basicProvider + */ + public function testBasic( $title, $ns, ForeignTitle $foreignTitle ) { + + $foreignNamespaces = array( + 0 => '', 1 => 'Talk', 100 => 'Portal', 9000 => 'Bogus' + ); + + $factory = new NamespaceAwareForeignTitleFactory( $foreignNamespaces ); + $testTitle = $factory->createForeignTitle( $title, $ns ); + + $this->assertEquals( $testTitle->isNamespaceIdKnown(), + $foreignTitle->isNamespaceIdKnown() ); + + if ( + $testTitle->isNamespaceIdKnown() && + $foreignTitle->isNamespaceIdKnown() + ) { + $this->assertEquals( $testTitle->getNamespaceId(), + $foreignTitle->getNamespaceId() ); + } + + $this->assertEquals( $testTitle->getNamespaceName(), + $foreignTitle->getNamespaceName() ); + $this->assertEquals( $testTitle->getText(), $foreignTitle->getText() ); + } +} diff --git a/tests/phpunit/includes/title/NamespaceImportTitleFactoryTest.php b/tests/phpunit/includes/title/NamespaceImportTitleFactoryTest.php new file mode 100644 index 00000000..d6fe6848 --- /dev/null +++ b/tests/phpunit/includes/title/NamespaceImportTitleFactoryTest.php @@ -0,0 +1,77 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author This, that and the other + */ + +/** + * @covers NamespaceImportTitleFactory + * + * @group Title + */ +class NamespaceImportTitleFactoryTest extends MediaWikiTestCase { + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + 'wgLanguageCode' => 'en', + 'wgContLang' => Language::factory( 'en' ), + ) ); + } + + public function basicProvider() { + return array( + array( + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + 0, + Title::newFromText( 'MainNamespaceArticle' ) + ), + array( + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + 2, + Title::newFromText( 'User:MainNamespaceArticle' ) + ), + array( + new ForeignTitle( 1, 'Discussion', 'Nice_talk' ), + 0, + Title::newFromText( 'Nice_talk' ) + ), + array( + new ForeignTitle( 0, '', 'Bogus:Nice_talk' ), + 0, + Title::newFromText( 'Bogus:Nice_talk' ) + ), + array( + new ForeignTitle( 0, '', 'Bogus:Nice_talk' ), + 2, + Title::newFromText( 'User:Bogus:Nice_talk' ) + ), + ); + } + + /** + * @dataProvider basicProvider + */ + public function testBasic( ForeignTitle $foreignTitle, $ns, Title $title ) { + $factory = new NamespaceImportTitleFactory( $ns ); + $testTitle = $factory->createTitleFromForeignTitle( $foreignTitle ); + + $this->assertTrue( $title->equals( $testTitle ) ); + } +} diff --git a/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php b/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php new file mode 100644 index 00000000..d5c17f3e --- /dev/null +++ b/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php @@ -0,0 +1,86 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author This, that and the other + */ + +/** + * @covers SubpageImportTitleFactory + * + * @group Title + */ +class SubpageImportTitleFactoryTest extends MediaWikiTestCase { + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( array( + 'wgLanguageCode' => 'en', + 'wgContLang' => Language::factory( 'en' ), + 'wgNamespacesWithSubpages' => array( 0 => false, 2 => true ), + ) ); + } + + public function basicProvider() { + return array( + array( + new ForeignTitle( 0, '', 'MainNamespaceArticle' ), + Title::newFromText( 'User:Graham' ), + Title::newFromText( 'User:Graham/MainNamespaceArticle' ) + ), + array( + new ForeignTitle( 1, 'Discussion', 'Nice_talk' ), + Title::newFromText( 'User:Graham' ), + Title::newFromText( 'User:Graham/Discussion:Nice_talk' ) + ), + array( + new ForeignTitle( 0, '', 'Bogus:Nice_talk' ), + Title::newFromText( 'User:Graham' ), + Title::newFromText( 'User:Graham/Bogus:Nice_talk' ) + ), + ); + } + + /** + * @dataProvider basicProvider + */ + public function testBasic( ForeignTitle $foreignTitle, Title $rootPage, + Title $title ) { + + $factory = new SubpageImportTitleFactory( $rootPage ); + $testTitle = $factory->createTitleFromForeignTitle( $foreignTitle ); + + $this->assertTrue( $testTitle->equals( $title ) ); + } + + public function failureProvider() { + return array( + array( + Title::newFromText( 'Graham' ), + ), + ); + } + + /** + * @dataProvider failureProvider + */ + public function testFailures( Title $rootPage ) { + $this->setExpectedException( 'MWException' ); + new SubpageImportTitleFactory( $rootPage ); + } +} diff --git a/tests/phpunit/includes/title/TitleValueTest.php b/tests/phpunit/includes/title/TitleValueTest.php index 3ba008d6..184198d2 100644 --- a/tests/phpunit/includes/title/TitleValueTest.php +++ b/tests/phpunit/includes/title/TitleValueTest.php @@ -16,7 +16,6 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @license GPL 2+ * @author Daniel Kinzler */ |