Tobias Gritschacher has submitted this change and it was merged.
Change subject: Rewrote SiteLink test to not depends on the database
......................................................................
Rewrote SiteLink test to not depends on the database
Also decreases complexity, increased readability and maintainability
And got rid of deprecated method usage
Change-Id: Ifbd141dcc41640fd9348558efdc8d82a5423be82
---
M DataModel/DataModel/SiteLink.php
M DataModel/tests/phpunit/SiteLinkTest.php
2 files changed, 98 insertions(+), 107 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataModel/DataModel/SiteLink.php b/DataModel/DataModel/SiteLink.php
index 155f329..2c2e53c 100644
--- a/DataModel/DataModel/SiteLink.php
+++ b/DataModel/DataModel/SiteLink.php
@@ -53,7 +53,11 @@
* @return \Wikibase\SiteLink the new SiteLink
* @throws \MWException if the $siteID isn't known.
*/
- public static function newFromText( $globalSiteId, $page, $normalize =
false ) {
+ public static function newFromText( $globalSiteId, $page, $normalize =
null ) {
+ if ( $normalize !== null ) {
+ throw new \Exception( 'Support for $normalize parameter
has been dropped' );
+ }
+
wfProfileIn( __METHOD__ );
$site = Sites::singleton()->getSite( $globalSiteId );
diff --git a/DataModel/tests/phpunit/SiteLinkTest.php
b/DataModel/tests/phpunit/SiteLinkTest.php
index 1516fea..47a430e 100644
--- a/DataModel/tests/phpunit/SiteLinkTest.php
+++ b/DataModel/tests/phpunit/SiteLinkTest.php
@@ -2,10 +2,26 @@
namespace Wikibase\Test;
+use Site;
use Wikibase\SiteLink;
/**
- * Tests for the Wikibase\SiteLink class.
+ * @covers Wikibase\SiteLink
+ *
+ * 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
* @since 0.1
@@ -16,138 +32,109 @@
* @group Wikibase
* @group WikibaseDataModel
* @group SiteLink
- * @group Database
*
* @licence GNU GPL v2+
- * @author Daniel Kinzler <[email protected]>
* @author Jeroen De Dauw < [email protected] >
*/
class SiteLinkTest extends \MediaWikiTestCase {
- public function setUp() {
- parent::setUp();
+ /**
+ * @dataProvider constructorProvider
+ */
+ public function testConstructor( Site $site, $pageName ) {
+ $link = new SiteLink( $site, $pageName );
- static $hasSites = false;
+ $this->assertEquals( $site, $link->getSite() );
+ $this->assertEquals( $pageName, $link->getPage() );
+ }
- if ( !$hasSites ) {
- \TestSites::insertIntoDb();
- $hasSites = true;
+ public function constructorProvider() {
+ $argLists = array();
+
+ foreach ( $this->getSites() as $site ) {
+ foreach ( array( 'Nyan', 'Nyan!', 'Main_Page' ) as
$pageName ) {
+ $argLists[] = array( $site, $pageName );
+ }
}
+
+ return $argLists;
+ }
+
+ protected function getSites() {
+ $sites = array();
+
+ $enWiki = new \MediaWikiSite();
+ $enWiki->setGlobalId( 'enwiki' );
+
+ $sites[] = $enWiki;
+
+
+ $nlWiki = new \MediaWikiSite();
+ $nlWiki->setGlobalId( 'nlwiki' );
+
+ $sites[] = $nlWiki;
+
+
+ $fooWiki = new \Site();
+ $fooWiki->setGlobalId( 'foobarbaz' );
+
+ $sites[] = $fooWiki;
+
+ return $sites;
}
/**
- * Returns a site to test with.
- * @return \MediaWikiSite
+ * @dataProvider constructorProvider
*/
- protected function getSite() {
- $site = \MediaWikiSite::newFromGlobalId( 'enwiki' );
- $site->setPagePath( 'https://en.wikipedia.org/wiki/$1' );
+ public function testToString( Site $site, $pageName ) {
+ $link = new SiteLink( $site, $pageName );
- return $site;
- }
+ $this->assertInternalType( 'string', (string)$link );
- protected function newFromText( $pageText ) {
- return new SiteLink( $this->getSite(), $pageText );
- }
+ $parts = explode( ':', (string)$link );
+ $this->assertCount( 2, $parts, 'string representation should
contain one colon' );
- public function testNewFromText() {
- $link = SiteLink::newFromText( "enwiki", " foo " );
- $this->assertEquals( " foo ", $link->getPage() );
+ $this->assertEquals(
+ $site->getGlobalId(),
+ substr( $parts[0], 2 ),
+ 'The first part of the string representation should be
[[$globalSiteId'
+ );
- //NOTE: this does not actually call out to the enwiki site to
perform the normalization,
- // but uses a local Title object to do so. This is
hardcoded on SiteLink::normalizePageTitle
- // for the case that MW_PHPUNIT_TEST is set.
- $link = SiteLink::newFromText( "enwiki", " foo ", true );
- $this->assertEquals( "Foo", $link->getPage() );
- }
-
- public function testConstructor() {
- $link = new SiteLink( $this->getSite(), "Foo" );
- $this->assertEquals( "Foo", $link->getPage() );
- }
-
- /**
- * @depends testNewFromText
- */
- public function testGetPage() {
- $link = $this->newFromText( 'Foo' );
- $this->assertEquals( "Foo", $link->getPage() );
- }
-
- /**
- * @depends testNewFromText
- */
- public function testGetSite() {
- $this->assertEquals( $this->getSite(), $this->newFromText(
'Foo' )->getSite() );
- }
-
- /**
- * @depends testNewFromText
- */
- public function testGetSiteID() {
- $this->assertEquals( 'enwiki', $this->newFromText( 'Foo'
)->getSite()->getGlobalId() );
- }
-
- /**
- * @depends testNewFromText
- */
- public function testToString() {
- $link = $this->newFromText( 'Foo Bar' );
-
- $this->assertEquals( "[[enwiki:Foo Bar]]", "$link" );
- }
-
- public function dataGetSiteIDs() {
- return array(
- array(
- array(),
- array() ),
-
- array(
- array( SiteLink::newFromText( 'enwiki', "Foo
Bar" ), SiteLink::newFromText( 'dewiki', "Bla bla" ) ),
- array( 'enwiki', 'dewiki' ) ),
-
- array(
- array( SiteLink::newFromText( 'enwiki', "Foo
Bar" ), SiteLink::newFromText( 'dewiki', "Bla bla" ), SiteLink::newFromText(
'enwiki', "More Stuff" ) ),
- array( 'enwiki', 'dewiki' ) ),
+ $this->assertEquals(
+ $pageName,
+ substr( $parts[1], 0, strlen( $parts[1] ) - 2 ),
+ 'The second part of the string representation should be
$pageName]]'
);
}
/**
- *
- * @dataProvider dataGetSiteIDs
- * @depends testNewFromText
+ * @dataProvider constructorProvider
*/
- public function testGetSiteIDs( $links, $expected ) {
- $ids = SiteLink::getSiteIDs( $links );
+ public function testGetUrl( Site $site, $pageName ) {
+ $link = new SiteLink( $site, $pageName );
- $this->assertArrayEquals( $expected, $ids );
- }
-
- public function dataSiteLinksToArray() {
- return array(
- array(
- array(),
- array() ),
-
- array(
- array( SiteLink::newFromText( 'enwiki', "Foo
Bar" ), SiteLink::newFromText( 'dewiki', "Bla bla" ) ),
- array( 'enwiki' => "Foo Bar", 'dewiki' => "Bla
bla" ) ),
-
- array(
- array( SiteLink::newFromText( 'enwiki', "Foo
Bar" ), SiteLink::newFromText( 'dewiki', "Bla bla" ), SiteLink::newFromText(
'enwiki', "More Stuff" ) ),
- array( 'enwiki' => "More Stuff", 'dewiki' =>
"Bla bla" ) ),
+ $this->assertEquals(
+ $site->getPageUrl( $pageName ),
+ $link->getUrl()
);
}
/**
- *
- * @dataProvider dataSiteLinksToArray
- * @depends testNewFromText
+ * @dataProvider siteProvider
*/
- public function testSiteLinksToArray( $links, $expected ) {
- $array = SiteLink::siteLinksToArray( $links );
-
- $this->assertArrayEquals( $expected, $array );
+ public function testConstructorWithNullPageName( Site $site ) {
+ $this->setExpectedException( 'MWException' );
+ new SiteLink( $site, null );
}
+
+ public function siteProvider() {
+ $argLists = array();
+
+ foreach ( $this->getSites() as $site ) {
+ $argLists[] = array( $site );
+ }
+
+ return $argLists;
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/63126
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifbd141dcc41640fd9348558efdc8d82a5423be82
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Anja Jentzsch <[email protected]>
Gerrit-Reviewer: Ataherivand <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: Lydia Pintscher <[email protected]>
Gerrit-Reviewer: Markus Kroetzsch <[email protected]>
Gerrit-Reviewer: Nikola Smolenski <[email protected]>
Gerrit-Reviewer: Silke Meyer <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits