Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/237652
Change subject: Add tests for WikiMap and WikiReference
......................................................................
Add tests for WikiMap and WikiReference
Change-Id: Ie218296fc7c1ceba588fadef076d66be865b1905
---
A tests/phpunit/includes/WikiMapTest.php
A tests/phpunit/includes/WikiReferenceTest.php
2 files changed, 195 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/52/237652/1
diff --git a/tests/phpunit/includes/WikiMapTest.php
b/tests/phpunit/includes/WikiMapTest.php
new file mode 100644
index 0000000..2218d05
--- /dev/null
+++ b/tests/phpunit/includes/WikiMapTest.php
@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * @covers WikiMap
+ */
+
+class WikiMapTest extends MediaWikiLangTestCase {
+
+ public function setUp() {
+ parent::setUp();
+
+ $conf = new SiteConfiguration();
+ $conf->settings = array(
+ 'wgServer' => array(
+ 'enwiki' => 'http://en.example.org',
+ 'ruwiki' => '//ru.example.org',
+ ),
+ 'wgArticlePath' => array(
+ 'enwiki' => '/w/$1',
+ 'ruwiki' => '/wiki/$1',
+ ),
+ );
+ $conf->suffixes = array( 'wiki' );
+ $this->setMwGlobals( array(
+ 'wgConf' => $conf,
+ ) );
+ }
+
+ public function provideGetWiki() {
+ $enwiki = new WikiReference( 'wiki', 'en',
'http://en.example.org', '/w/$1' );
+ $ruwiki = new WikiReference( 'wiki', 'ru', '//ru.example.org',
'/wiki/$1' );
+
+ return array(
+ 'unknown' => array( false, 'xyzzy' ),
+ 'enwiki' => array( $enwiki, 'enwiki' ),
+ 'ruwiki' => array( $ruwiki, 'ruwiki' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetWiki
+ */
+ public function testGetWiki( $expected, $wikiId ) {
+ $this->assertEquals( $expected, WikiMap::getWiki( $wikiId ) );
+ }
+
+ public function provideGetWikiName() {
+ return array(
+ 'unknown' => array( 'xyzzy', 'xyzzy' ),
+ 'enwiki' => array( 'en.example.org', 'enwiki' ),
+ 'ruwiki' => array( 'ru.example.org', 'ruwiki' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetWikiName
+ */
+ public function testGetWikiName( $expected, $wikiId ) {
+ $this->assertEquals( $expected, WikiMap::getWikiName( $wikiId )
);
+ }
+
+ public function provideMakeForeignLink() {
+ return array(
+ 'unknown' => array( false, 'xyzzy', 'Foo' ),
+ 'enwiki' => array( '<a class="external" rel="nofollow"
href="http://en.example.org/w/Foo">Foo</a>', 'enwiki', 'Foo', ),
+ 'ruwiki' => array( '<a class="external" rel="nofollow"
href="//ru.example.org/wiki/%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideMakeForeignLink
+ */
+ public function testMakeForeignLink( $expected, $wikiId, $page, $text =
null ) {
+ $this->assertEquals( $expected, WikiMap::makeForeignLink(
$wikiId, $page, $text ) );
+ }
+
+ public function provideForeignUserLink() {
+ return array(
+ 'unknown' => array( false, 'xyzzy', 'Foo' ),
+ 'enwiki' => array( '<a class="external" rel="nofollow"
href="http://en.example.org/w/User:Foo">User:Foo</a>', 'enwiki', 'Foo', ),
+ 'ruwiki' => array( '<a class="external" rel="nofollow"
href="//ru.example.org/wiki/User:%D0%A4%D1%83">вар</a>', 'ruwiki', 'Фу', 'вар'
),
+ );
+ }
+
+ /**
+ * @dataProvider provideForeignUserLink
+ */
+ public function testForeignUserLink( $expected, $wikiId, $user, $text =
null ) {
+ $this->assertEquals( $expected, WikiMap::foreignUserLink(
$wikiId, $user, $text ) );
+ }
+
+ public function provideGetForeignURL() {
+ return array(
+ 'unknown' => array( false, 'xyzzy', 'Foo' ),
+ 'enwiki' => array( 'http://en.example.org/w/Foo',
'enwiki', 'Foo', ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetForeignURL
+ */
+ public function testGetForeignURL( $expected, $wikiId, $page, $fragment
= null ) {
+ $this->assertEquals( $expected, WikiMap::getForeignURL(
$wikiId, $page, $fragment ) );
+ }
+
+}
+
diff --git a/tests/phpunit/includes/WikiReferenceTest.php
b/tests/phpunit/includes/WikiReferenceTest.php
new file mode 100644
index 0000000..592a477
--- /dev/null
+++ b/tests/phpunit/includes/WikiReferenceTest.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * @covers WikiReference
+ */
+
+class WikiReferenceTest extends PHPUnit_Framework_TestCase {
+
+ public function provideGetHostname() {
+ return array(
+ 'http' => array( 'foo.bar', 'http://foo.bar' ),
+ 'https' => array( 'foo.bar', 'https://foo.bar' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetHostname
+ */
+ public function testGetHostname( $expected, $canonicalServer ) {
+ $this->markTestSkipped( 'The implementation is patently
broken.' );
+
+ $reference = new WikiReference( 'wiki', 'xx', $canonicalServer,
'/wiki/$1' );
+ $this->assertEquals( $expected, $reference->getHostname() );
+ }
+
+ public function provideGetDisplayName() {
+ return array(
+ 'http' => array( 'foo.bar', 'http://foo.bar' ),
+ 'https' => array( 'foo.bar', 'http://foo.bar' ),
+
+ // apparently, this is the expected behavior
+ 'invalid' => array( 'purple kittens/wiki/', 'purple
kittens' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetDisplayName
+ */
+ public function testGetDisplayName( $expected, $canonicalServer ) {
+ $reference = new WikiReference( 'wiki', 'xx', $canonicalServer,
'/wiki/$1' );
+ $this->assertEquals( $expected, $reference->getDisplayName() );
+ }
+
+ public function testGetCanonicalServer() {
+ $reference = new WikiReference( 'wiki', 'xx',
'https://acme.com', '/wiki/$1', '//acme.com' );
+ $this->assertEquals( 'https://acme.com',
$reference->getCanonicalServer() );
+ }
+
+ public function provideGetCanonicalUrl() {
+ return array(
+ 'wiki path' => array( 'https://acme.com/wiki/Foo',
'https://acme.com', '//acme.com', '/wiki/$1', 'Foo' ),
+ 'empty path' => array( 'https://acme.com/Foo',
'https://acme.com', '//acme.com', '/$1', 'Foo' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetCanonicalUrl
+ */
+ public function testGetCanonicalUrl( $expected, $canonicalServer,
$server, $path, $page ) {
+ $reference = new WikiReference( 'wiki', 'xx', $canonicalServer,
$path, $server );
+ $this->assertEquals( $expected, $reference->getCanonicalUrl(
$page ) );
+ }
+
+ /**
+ * @dataProvider provideGetCanonicalUrl
+ */
+ public function testGetUrl( $expected, $canonicalServer, $server,
$path, $page ) {
+ $reference = new WikiReference( 'wiki', 'xx', $canonicalServer,
$path, $server );
+ $this->assertEquals( $expected, $reference->getUrl( $page ) );
+ }
+
+ public function provideGetFullUrl() {
+ return array(
+ 'wiki path' => array( '//acme.com/wiki/Foo',
'https://acme.com', '//acme.com', '/wiki/$1', 'Foo', null ),
+ 'empty path' => array( '//acme.com/Foo',
'https://acme.com', '//acme.com', '/$1', 'Foo', null ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetFullUrl
+ */
+ public function testGetFullUrl( $expected, $canonicalServer, $server,
$path, $page ) {
+ $reference = new WikiReference( 'wiki', 'xx', $canonicalServer,
$path, $server );
+ $this->assertEquals( $expected, $reference->getFullUrl( $page )
);
+ }
+
+}
+
--
To view, visit https://gerrit.wikimedia.org/r/237652
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie218296fc7c1ceba588fadef076d66be865b1905
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits