Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67363


Change subject: Added SimpleSiteLink class so we can migrate DataModel code 
away from SiteLink
......................................................................

Added SimpleSiteLink class so we can migrate DataModel code away from SiteLink

Change-Id: I4caf3758921fe3e399ae9ef8fd7478263f64455f
---
M DataModel/DataModel.classes.php
A DataModel/DataModel/SimpleSiteLink.php
A DataModel/tests/phpunit/SimpleSiteLinkTest.php
3 files changed, 177 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/63/67363/1

diff --git a/DataModel/DataModel.classes.php b/DataModel/DataModel.classes.php
index eb9ef89..015d559 100644
--- a/DataModel/DataModel.classes.php
+++ b/DataModel/DataModel.classes.php
@@ -65,6 +65,7 @@
                'Wikibase\ReferenceList' => 'DataModel/ReferenceList.php',
                'Wikibase\References' => 'DataModel/References.php',
 
+               'Wikibase\DataModel\SimpleSiteLink' => 
'DataModel/SimpleSiteLink.php',
                'Wikibase\SiteLink' => 'DataModel/SiteLink.php',
        );
 
diff --git a/DataModel/DataModel/SimpleSiteLink.php 
b/DataModel/DataModel/SimpleSiteLink.php
new file mode 100644
index 0000000..87ea341
--- /dev/null
+++ b/DataModel/DataModel/SimpleSiteLink.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Wikibase\DataModel;
+
+use InvalidArgumentException;
+
+/**
+ * Class representing a link to another site.
+ *
+ * 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
+ *
+ * @since 0.4
+ *
+ * @file
+ * @ingroup WikibaseDataModel
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SimpleSiteLink {
+
+       protected $siteId;
+       protected $pageName;
+
+       public function __construct( $siteId, $pageName ) {
+               if ( !is_string( $siteId ) ) {
+                       throw new InvalidArgumentException( '$siteId needs to 
be a string' );
+               }
+
+               if ( !is_string( $pageName ) ) {
+                       throw new InvalidArgumentException( '$pageName needs to 
be a string' );
+               }
+
+               $this->siteId = $siteId;
+               $this->pageName = $pageName;
+       }
+
+       /**
+        * @since 0.4
+        *
+        * @return string
+        */
+       public function getSiteId() {
+               return $this->siteId;
+       }
+
+       /**
+        * @since 0.4
+        *
+        * @return string
+        */
+       public function getPageName() {
+               return $this->pageName;
+       }
+
+}
diff --git a/DataModel/tests/phpunit/SimpleSiteLinkTest.php 
b/DataModel/tests/phpunit/SimpleSiteLinkTest.php
new file mode 100644
index 0000000..c9435a7
--- /dev/null
+++ b/DataModel/tests/phpunit/SimpleSiteLinkTest.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace Wikibase\DataModel\Test;
+
+use Wikibase\DataModel\SimpleSiteLink;
+
+/**
+ * @covers Wikibase\DataModel\SimpleSiteLink
+ *
+ * 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.4
+ *
+ * @ingroup WikibaseDataModel
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseDataModel
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SimpleSiteLinkTest extends \PHPUnit_Framework_TestCase {
+
+       public function testCanConstruct() {
+               new SimpleSiteLink( 'enwiki', 'Wikidata' );
+               $this->assertTrue( true );
+       }
+
+       /**
+        * @dataProvider siteIdProvider
+        */
+       public function testGetSiteId( $siteId ) {
+               $siteLink = new SimpleSiteLink( $siteId, 'Wikidata' );
+               $this->assertEquals( $siteId, $siteLink->getSiteId() );
+       }
+
+       public function siteIdProvider() {
+               $argLists = array();
+
+               $argLists[] = array( 'enwiki' );
+               $argLists[] = array( 'nlwiki' );
+               $argLists[] = array( 'Nyan!' );
+
+               return $argLists;
+       }
+
+       /**
+        * @dataProvider stuffThatIsNotStringProvider
+        */
+       public function testCannotConstructWithNonStringSiteId( $invalidSiteId 
) {
+               $this->setExpectedException( 'InvalidArgumentException' );
+               new SimpleSiteLink( $invalidSiteId, 'Wikidata' );
+       }
+
+       public function stuffThatIsNotStringProvider() {
+               $argLists = array();
+
+               $argLists[] = array( 42 );
+               $argLists[] = array( true );
+               $argLists[] = array( array() );
+               $argLists[] = array( null );
+
+               return $argLists;
+       }
+
+       /**
+        * @dataProvider pageNameProvider
+        */
+       public function testGetPageName( $pageName ) {
+               $siteLink = new SimpleSiteLink( 'enwiki', $pageName );
+               $this->assertEquals( $pageName, $siteLink->getPageName() );
+       }
+
+       public function pageNameProvider() {
+               $argLists = array();
+
+               $argLists[] = array( 'Wikidata' );
+               $argLists[] = array( 'Nyan_Cat' );
+               $argLists[] = array( 'NYAN DATA ALL ACROSS THE SKY ~=[,,_,,]:3' 
);
+
+               return $argLists;
+       }
+
+       /**
+        * @dataProvider stuffThatIsNotStringProvider
+        */
+       public function testCannotConstructWithNonStringPageName( 
$invalidPageName ) {
+               $this->setExpectedException( 'InvalidArgumentException' );
+               new SimpleSiteLink( 'enwiki', $invalidPageName );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/67363
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4caf3758921fe3e399ae9ef8fd7478263f64455f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to