John Erling Blad has submitted this change and it was merged.

Change subject: Introduced support for sub properties in SomeProperty 
description
......................................................................


Introduced support for sub properties in SomeProperty description

Change-Id: Icf9295a700cb32f98877f1755cd752ad9bcbc434
---
M includes/Ask/Language/Description/SomeProperty.php
M tests/phpunit/Language/Description/SomePropertyTest.php
2 files changed, 81 insertions(+), 4 deletions(-)

Approvals:
  John Erling Blad: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Ask/Language/Description/SomeProperty.php 
b/includes/Ask/Language/Description/SomeProperty.php
index d851776..88c5166 100644
--- a/includes/Ask/Language/Description/SomeProperty.php
+++ b/includes/Ask/Language/Description/SomeProperty.php
@@ -3,6 +3,7 @@
 namespace Ask\Language\Description;
 
 use DataValues\PropertyValue;
+use InvalidArgumentException;
 
 /**
  * Description of a set of instances that have an attribute with some value
@@ -40,6 +41,8 @@
 final class SomeProperty extends Description implements \Ask\Immutable {
 
        /**
+        * The property that should be present.
+        *
         * @since 0.1
         *
         * @var PropertyValue
@@ -47,11 +50,27 @@
        private $property;
 
        /**
+        * The description the properties value should match.
+        *
         * @since 0.1
         *
         * @var Description
         */
        private $description;
+
+       /**
+        * If the property is a sub property or not.
+        *
+        * For instance in the Wikibase Claim context,
+        * a non-sub property would point to the property
+        * of the main snak, while a sub property would
+        * point to a qualifier.
+        *
+        * @since 0.1
+        *
+        * @var boolean
+        */
+       private $isSubProperty;
 
        /**
         * Cache for the hash.
@@ -69,10 +88,19 @@
         *
         * @param PropertyValue $property
         * @param Description $description
+        * @param boolean $isSubProperty
+        *
+        * @throws InvalidArgumentException
         */
-       public function __construct( PropertyValue $property, Description 
$description ) {
+       public function __construct( PropertyValue $property, Description 
$description, $isSubProperty = false ) {
                $this->property = $property;
                $this->description = $description;
+
+               if ( !is_bool( $isSubProperty ) ) {
+                       throw new InvalidArgumentException( '$isSubProperty 
must be of type boolean' );
+               }
+
+               $this->isSubProperty = $isSubProperty;
        }
 
        /**
@@ -95,6 +123,17 @@
         */
        public function getProperty() {
                return $this->property;
+       }
+
+       /**
+        * Returns if the property is a sub property.
+        *
+        * @since 0.1
+        *
+        * @return boolean
+        */
+       public function isSubProperty() {
+               return $this->isSubProperty;
        }
 
        /**
@@ -141,6 +180,7 @@
                return array(
                        'property' => $this->property->toArray(),
                        'description' => $this->description->toArray(),
+                       'issubproperty' => $this->isSubProperty
                );
        }
 
@@ -155,6 +195,7 @@
         */
        public function equals( $mixed ) {
                return $mixed instanceof SomeProperty
+                       && $this->isSubProperty === $mixed->isSubProperty()
                        && $this->property->equals( $mixed->getProperty() )
                        && $this->description->equals( $mixed->getDescription() 
);
        }
@@ -168,7 +209,12 @@
         */
        public function getHash() {
                if ( $this->hash === null ) {
-                       $this->hash = sha1( $this->getType() . 
$this->property->getHash() . $this->description->getHash() );
+                       $this->hash = sha1(
+                               $this->getType() .
+                               $this->property->getHash() .
+                               $this->description->getHash() .
+                               $this->isSubProperty
+                       );
                }
 
                return $this->hash;
diff --git a/tests/phpunit/Language/Description/SomePropertyTest.php 
b/tests/phpunit/Language/Description/SomePropertyTest.php
index ba7f39a..141da69 100644
--- a/tests/phpunit/Language/Description/SomePropertyTest.php
+++ b/tests/phpunit/Language/Description/SomePropertyTest.php
@@ -43,6 +43,8 @@
 
                $instances[] = new SomeProperty( new PropertyValue( '_geo' ), 
new \Ask\Language\Description\AnyValue() );
                $instances[] = new SomeProperty( new PropertyValue( 'p42' ), 
new \Ask\Language\Description\Conjunction( array() ) );
+               $instances[] = new SomeProperty( new PropertyValue( 'foo' ), 
new \Ask\Language\Description\AnyValue(), true );
+               $instances[] = new SomeProperty( new PropertyValue( 
'~=[,,_,,]:3' ), new \Ask\Language\Description\AnyValue(), false );
 
                return $instances;
        }
@@ -61,7 +63,11 @@
 
                $newInstance = new SomeProperty( $description->getProperty(), 
$subDescription );
 
-               $this->assertEquals( $subDescription, 
$newInstance->getDescription(), 'Description is returned as it was passed to 
the constructor' );
+               $this->assertEquals(
+                       $subDescription,
+                       $newInstance->getDescription(),
+                       'Description is returned as it was passed to the 
constructor'
+               );
        }
 
        /**
@@ -78,7 +84,32 @@
 
                $newInstance = new SomeProperty( $property, 
$description->getDescription() );
 
-               $this->assertEquals( $property, $newInstance->getProperty(), 
'Property is returned as it was passed to the constructor' );
+               $this->assertEquals(
+                       $property,
+                       $newInstance->getProperty(),
+                       'Property is returned as it was passed to the 
constructor'
+               );
+       }
+
+       /**
+        * @dataProvider instanceProvider
+        *
+        * @since 0.1
+        *
+        * @param SomeProperty $description
+        */
+       public function testIsSubProperty( SomeProperty $description ) {
+               $isSubProperty = $description->isSubProperty();
+
+               $this->assertInternalType( 'boolean', $isSubProperty );
+
+               $newInstance = new SomeProperty( $description->getProperty(), 
$description->getDescription(), $isSubProperty );
+
+               $this->assertEquals(
+                       $isSubProperty,
+                       $newInstance->isSubProperty(),
+                       'Is sub property is returned as it was passed to the 
constructor'
+               );
        }
 
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icf9295a700cb32f98877f1755cd752ad9bcbc434
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Ask
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de>
Gerrit-Reviewer: John Erling Blad <john.b...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to