[MediaWiki-commits] [Gerrit] Fix validation of snakhash parameter - change (mediawiki...Wikibase)

2013-09-23 Thread Jeroen De Dauw (Code Review)
Jeroen De Dauw has submitted this change and it was merged.

Change subject: Fix validation of snakhash parameter
..


Fix validation of snakhash parameter

Also rewrote the test case.

Change-Id: Ib57c03fe8522f5cfb637f371423e1f93b331fa3a
---
M repo/includes/api/SetQualifier.php
M repo/tests/phpunit/includes/api/SetQualifierTest.php
2 files changed, 107 insertions(+), 108 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/api/SetQualifier.php 
b/repo/includes/api/SetQualifier.php
index bc0bbe1..1614dfd 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Api;
 
 use ApiBase;
-use Wikibase\Entity;
 use Wikibase\Claim;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\ChangeOpQualifier;
@@ -44,7 +43,7 @@
$claim = $this-claimModificationHelper-getClaimFromEntity( 
$params['claim'], $entity );
 
if ( isset( $params['snakhash'] ) ) {
-   $this-validateReferenceHash( $claim, 
$params['snakhash'] );
+   $this-validateQualifierHash( $claim, 
$params['snakhash'] );
}
 
$changeOp = $this-getChangeOp();
@@ -95,8 +94,8 @@
 * @param string $qualifierHash
 */
protected function validateQualifierHash( Claim $claim, $qualifierHash 
) {
-   if ( !$claim-getReferences()-hasReferenceHash( $qualifierHash 
) ) {
-   $this-dieUsage( Claim does not have a qualifier with 
the given hash , 'no-such-reference' );
+   if ( !$claim-getQualifiers()-hasSnakHash( $qualifierHash ) ) {
+   $this-dieUsage( Claim does not have a qualifier with 
the given hash , 'no-such-qualifier' );
}
}
 
diff --git a/repo/tests/phpunit/includes/api/SetQualifierTest.php 
b/repo/tests/phpunit/includes/api/SetQualifierTest.php
index 1dcbd35..fc25146 100644
--- a/repo/tests/phpunit/includes/api/SetQualifierTest.php
+++ b/repo/tests/phpunit/includes/api/SetQualifierTest.php
@@ -4,7 +4,6 @@
 
 use DataValues\StringValue;
 use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\DataModel\Entity\EntityIdValue;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\Item;
@@ -13,10 +12,8 @@
 use Wikibase\PropertyNoValueSnak;
 use Wikibase\PropertySomeValueSnak;
 use Wikibase\PropertyValueSnak;
-use Wikibase\Reference;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Snak;
-use Wikibase\SnakList;
 use Wikibase\Statement;
 use Wikibase\Claim;
 
@@ -45,134 +42,140 @@
 class SetQualifierTest extends WikibaseApiTestCase {
 
/**
-* @return Snak[]
+* Creates the given property in the database, if necessary.
+*
+* @param \Wikibase\DataModel\Entity\PropertyId $id
+* @param $type
+*
+* @return Property
 */
-   protected function snakProvider() {
-   static $hasProperties = false;
+   protected function makeProperty( PropertyId $id, $type ) {
+   static $properties = array();
 
-   $prop42 = new PropertyId( 'p42' );
-   $prop9001 = new PropertyId( 'p9001' );
-   $prop7201010 = new PropertyId( 'p7201010' );
+   $key = $id-getPrefixedId();
 
-   if ( !$hasProperties ) {
+   if ( !isset( $properties[$key] ) ) {
$prop = PropertyContent::newEmpty();
-   $prop-getEntity()-setId( $prop42 );
-   $prop-getEntity()-setDataTypeId( 'string' );
+   $prop-getProperty()-setId( $id );
+   $prop-getProperty()-setDataTypeId( $type );
$prop-save( 'testing' );
 
-   $prop = PropertyContent::newEmpty();
-   $prop-getEntity()-setId( $prop9001 );
-   $prop-getEntity()-setDataTypeId( 'string' );
-   $prop-save( 'testing' );
-
-   $prop = PropertyContent::newEmpty();
-   $prop-getEntity()-setId( $prop7201010 );
-   $prop-getEntity()-setDataTypeId( 'string' );
-   $prop-save( 'testing' );
-
-   $hasProperties = true;
+   $properties[$key] = $prop-getProperty();
}
 
-   $snaks = array();
-
-   $snaks[] = new PropertyNoValueSnak( $prop42 );
-   $snaks[] = new PropertySomeValueSnak( $prop9001 );
-   $snaks[] = new PropertyValueSnak( $prop7201010, new 
StringValue( 'o_O' ) );
-
-   return $snaks;
+   return $properties[$key];
}
 
-   /**
-* @return Claim[]
-*/
-   protected function claimProvider() {
-   $statements = array();

[MediaWiki-commits] [Gerrit] Fix validation of snakhash parameter - change (mediawiki...Wikibase)

2013-09-20 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has uploaded a new change for review.

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


Change subject: Fix validation of snakhash parameter
..

Fix validation of snakhash parameter

Change-Id: Ib57c03fe8522f5cfb637f371423e1f93b331fa3a
---
M repo/includes/api/SetQualifier.php
1 file changed, 3 insertions(+), 4 deletions(-)


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

diff --git a/repo/includes/api/SetQualifier.php 
b/repo/includes/api/SetQualifier.php
index bc0bbe1..1614dfd 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Api;
 
 use ApiBase;
-use Wikibase\Entity;
 use Wikibase\Claim;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\ChangeOpQualifier;
@@ -44,7 +43,7 @@
$claim = $this-claimModificationHelper-getClaimFromEntity( 
$params['claim'], $entity );
 
if ( isset( $params['snakhash'] ) ) {
-   $this-validateReferenceHash( $claim, 
$params['snakhash'] );
+   $this-validateQualifierHash( $claim, 
$params['snakhash'] );
}
 
$changeOp = $this-getChangeOp();
@@ -95,8 +94,8 @@
 * @param string $qualifierHash
 */
protected function validateQualifierHash( Claim $claim, $qualifierHash 
) {
-   if ( !$claim-getReferences()-hasReferenceHash( $qualifierHash 
) ) {
-   $this-dieUsage( Claim does not have a qualifier with 
the given hash , 'no-such-reference' );
+   if ( !$claim-getQualifiers()-hasSnakHash( $qualifierHash ) ) {
+   $this-dieUsage( Claim does not have a qualifier with 
the given hash , 'no-such-qualifier' );
}
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib57c03fe8522f5cfb637f371423e1f93b331fa3a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler daniel.kinz...@wikimedia.de

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits