From 8e02b510cd222b88f5e5e84073beafcc93f8f9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiemo=20M=C3=A4ttig?= Date: Thu, 28 Aug 2014 16:44:56 +0200 Subject: [PATCH 1/2] BooleanHandlerIntegrationTest --- tests/Integration/IntegrationStoreBuilder.php | 13 +- .../BooleanHandlerIntegrationTest.php | 45 ++++++ .../DataValueHandlerIntegrationTest.php | 137 ++++++++++++++++++ 3 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 tests/Integration/SQLStore/DVHandler/BooleanHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DataValueHandlerIntegrationTest.php diff --git a/tests/Integration/IntegrationStoreBuilder.php b/tests/Integration/IntegrationStoreBuilder.php index b75ea4a..4c20b0d 100644 --- a/tests/Integration/IntegrationStoreBuilder.php +++ b/tests/Integration/IntegrationStoreBuilder.php @@ -63,11 +63,18 @@ private function buildStore() { * @return PropertyDataValueTypeLookup */ private function getPropertyDataValueTypeLookup() { - $propertyDvTypeLookup = $this->testCase->getMock( 'Wikibase\QueryEngine\PropertyDataValueTypeLookup' ); + $testCase = $this->testCase; + $propertyDvTypeLookup = $testCase->getMock( 'Wikibase\QueryEngine\PropertyDataValueTypeLookup' ); - $propertyDvTypeLookup->expects( $this->testCase->any() ) + $propertyDvTypeLookup->expects( $testCase->any() ) ->method( 'getDataValueTypeForProperty' ) - ->will( $this->testCase->returnValue( 'number' ) ); + ->will( $testCase->returnCallback( function() use ( $testCase ) { + if ( method_exists( $testCase, 'getDataValueType' ) ) { + return call_user_func( array( $testCase, 'getDataValueType' ) ); + } + + return 'number'; + } ) ); return $propertyDvTypeLookup; } diff --git a/tests/Integration/SQLStore/DVHandler/BooleanHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/BooleanHandlerIntegrationTest.php new file mode 100644 index 0000000..75b0f34 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/BooleanHandlerIntegrationTest.php @@ -0,0 +1,45 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new BooleanValue( false ) ); + + $this->insertItem( 'Q21', new BooleanValue( true ) ); + } + + public function queryProvider() { + return array( + array( + new BooleanValue( false ), + array( 'Q20' ), + ), + array( + new BooleanValue( true ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DataValueHandlerIntegrationTest.php b/tests/Integration/SQLStore/DataValueHandlerIntegrationTest.php new file mode 100644 index 0000000..28e16e0 --- /dev/null +++ b/tests/Integration/SQLStore/DataValueHandlerIntegrationTest.php @@ -0,0 +1,137 @@ +store = IntegrationStoreBuilder::newStore( $this ); + + $this->store->newInstaller()->install(); + + $this->insertItems(); + } + + public function tearDown() { + if ( isset( $this->store ) ) { + $this->store->newUninstaller()->uninstall(); + } + } + + private function getPropertyId() { + return new PropertyId( 'P7701' ); + } + + /** + * @return string + */ + abstract public function getDataValueType(); + + /** + * @return Item[] + */ + abstract protected function insertItems(); + + /** + * @param string $idString + * @param DataValue|null $dataValue + */ + protected function insertItem( $idString, DataValue $dataValue = null ) { + $item = Item::newEmpty(); + $item->setId( new ItemId( $idString ) ); + + if ( $dataValue !== null ) { + $propertyId = $this->getPropertyId(); + $mainSnak = new PropertyValueSnak( $propertyId, $dataValue ); + $statement = new Statement( $mainSnak ); + + $statement->setGuid( 'statement' . $this->guidCounter ); + $this->guidCounter++; + + $item->addClaim( $statement ); + } + + $this->store->newWriter()->insertEntity( $item ); + } + + /** + * @dataProvider queryProvider + * @param DataValue $dataValue + * @param string[] $expectedIdStrings + */ + public function testQuery( DataValue $dataValue, array $expectedIdStrings ) { + $someProperty = new SomeProperty( + new EntityIdValue( $this->getPropertyId() ), + new ValueDescription( $dataValue ) + ); + + $queryEngine = $this->store->newQueryEngine(); + $options = new QueryOptions( 100, 0 ); + $entityIds = $queryEngine->getMatchingEntities( $someProperty, $options ); + + $idStrings = $this->getIdStrings( $entityIds ); + $this->assertSameElements( $expectedIdStrings, $idStrings ); + } + + /** + * @return array[] + */ + abstract public function queryProvider(); + + /** + * @param EntityId[] $entityIds + * + * @return string[] + */ + private function getIdStrings( array $entityIds ) { + $idStrings = array(); + + foreach ( $entityIds as $entityId ) { + $idStrings[] = $entityId->getSerialization(); + } + + return $idStrings; + } + + /** + * @param string[] $expected + * @param string[] $actual + */ + private function assertSameElements( array $expected, array $actual ) { + $this->assertCount( count( $expected ), $actual ); + + sort( $expected ); + sort( $actual ); + + $this->assertSame( $expected, $actual ); + } + +} From 875a9f9e5c6f6684a80f6522cb603e0327a9c2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiemo=20M=C3=A4ttig?= Date: Tue, 2 Sep 2014 11:43:53 +0200 Subject: [PATCH 2/2] Add all DVHandler integration tests --- .../EntityIdHandlerIntegrationTest.php | 46 ++++++++++++++ .../GlobeCoordinateHandlerIntegrationTest.php | 62 +++++++++++++++++++ .../DVHandler/IriHandlerIntegrationTest.php | 45 ++++++++++++++ .../MonolingualTextHandlerIntegrationTest.php | 45 ++++++++++++++ .../NumberHandlerIntegrationTest.php | 45 ++++++++++++++ .../QuantityHandlerIntegrationTest.php | 51 +++++++++++++++ .../StringHandlerIntegrationTest.php | 45 ++++++++++++++ .../DVHandler/TimeHandlerIntegrationTest.php | 57 +++++++++++++++++ 8 files changed, 396 insertions(+) create mode 100644 tests/Integration/SQLStore/DVHandler/EntityIdHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/GlobeCoordinateHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/IriHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/MonolingualTextHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/NumberHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/QuantityHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/StringHandlerIntegrationTest.php create mode 100644 tests/Integration/SQLStore/DVHandler/TimeHandlerIntegrationTest.php diff --git a/tests/Integration/SQLStore/DVHandler/EntityIdHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/EntityIdHandlerIntegrationTest.php new file mode 100644 index 0000000..866721f --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/EntityIdHandlerIntegrationTest.php @@ -0,0 +1,46 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new EntityIdValue( new ItemId( 'Q30' ) ) ); + + $this->insertItem( 'Q21', new EntityIdValue( new ItemId( 'Q31' ) ) ); + } + + public function queryProvider() { + return array( + array( + new EntityIdValue( new ItemId( 'Q30' ) ), + array( 'Q20' ), + ), + array( + new EntityIdValue( new ItemId( 'Q31' ) ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/GlobeCoordinateHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/GlobeCoordinateHandlerIntegrationTest.php new file mode 100644 index 0000000..168dfe1 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/GlobeCoordinateHandlerIntegrationTest.php @@ -0,0 +1,62 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new GlobeCoordinateValue( new LatLongValue( 0, 20 ), null ) ); + + $this->insertItem( 'Q21', new GlobeCoordinateValue( new LatLongValue( 0, 21 ), 10 ) ); + + $this->insertItem( 'Q22', new GlobeCoordinateValue( new LatLongValue( 0, 22 ), 0.1 ) ); + + $this->insertItem( 'Q23', new GlobeCoordinateValue( new LatLongValue( 0, 22 ), 0.1, 'Vulcan' ) ); + } + + public function queryProvider() { + return array( + array( + new GlobeCoordinateValue( new LatLongValue( 0, 20 ), null ), + array( 'Q20' ), + ), + array( + new GlobeCoordinateValue( new LatLongValue( 0, 21 ), null ), + array( 'Q21' ), + ), + array( + new GlobeCoordinateValue( new LatLongValue( 0, 22 ), 0.1 ), + array( 'Q22' ), + ), + array( + new GlobeCoordinateValue( new LatLongValue( 0, 22 ), 1 ), + array( 'Q21', 'Q22' ), + ), + array( + new GlobeCoordinateValue( new LatLongValue( 0, 22 ), 0.1, 'Vulcan' ), + array( 'Q23' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/IriHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/IriHandlerIntegrationTest.php new file mode 100644 index 0000000..2d0b8b5 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/IriHandlerIntegrationTest.php @@ -0,0 +1,45 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new IriValue( 'http', '//www.wikidata.org/' ) ); + + $this->insertItem( 'Q21', new IriValue( 'http', '//en.wikipedia.org/' ) ); + } + + public function queryProvider() { + return array( + array( + new IriValue( 'http', '//www.wikidata.org/' ), + array( 'Q20' ), + ), + array( + new IriValue( 'http', '//en.wikipedia.org/' ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/MonolingualTextHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/MonolingualTextHandlerIntegrationTest.php new file mode 100644 index 0000000..1867c99 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/MonolingualTextHandlerIntegrationTest.php @@ -0,0 +1,45 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new MonolingualTextValue( 'en', 'A' ) ); + + $this->insertItem( 'Q21', new MonolingualTextValue( 'en', 'B' ) ); + } + + public function queryProvider() { + return array( + array( + new MonolingualTextValue( 'en', 'A' ), + array( 'Q20' ), + ), + array( + new MonolingualTextValue( 'en', 'B' ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/NumberHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/NumberHandlerIntegrationTest.php new file mode 100644 index 0000000..f410a8a --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/NumberHandlerIntegrationTest.php @@ -0,0 +1,45 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new NumberValue( 20 ) ); + + $this->insertItem( 'Q21', new NumberValue( 21 ) ); + } + + public function queryProvider() { + return array( + array( + new NumberValue( 20 ), + array( 'Q20' ), + ), + array( + new NumberValue( 21 ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/QuantityHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/QuantityHandlerIntegrationTest.php new file mode 100644 index 0000000..b216414 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/QuantityHandlerIntegrationTest.php @@ -0,0 +1,51 @@ +insertItem( 'Q10' ); + + $amount = new DecimalValue( 20 ); + $this->insertItem( 'Q20', new QuantityValue( $amount, '1', $amount, $amount ) ); + + $amount = new DecimalValue( 21 ); + $this->insertItem( 'Q21', new QuantityValue( $amount, '1', $amount, $amount ) ); + } + + public function queryProvider() { + $amount1 = new DecimalValue( 20 ); + $amount2 = new DecimalValue( 21 ); + + return array( + array( + new QuantityValue( $amount1, '1', $amount1, $amount1 ), + array( 'Q20' ), + ), + array( + new QuantityValue( $amount2, '1', $amount2, $amount2 ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/StringHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/StringHandlerIntegrationTest.php new file mode 100644 index 0000000..5a19c08 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/StringHandlerIntegrationTest.php @@ -0,0 +1,45 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new StringValue( 'A' ) ); + + $this->insertItem( 'Q21', new StringValue( 'B' ) ); + } + + public function queryProvider() { + return array( + array( + new StringValue( 'A' ), + array( 'Q20' ), + ), + array( + new StringValue( 'B' ), + array( 'Q21' ), + ), + ); + } + +} diff --git a/tests/Integration/SQLStore/DVHandler/TimeHandlerIntegrationTest.php b/tests/Integration/SQLStore/DVHandler/TimeHandlerIntegrationTest.php new file mode 100644 index 0000000..20eb677 --- /dev/null +++ b/tests/Integration/SQLStore/DVHandler/TimeHandlerIntegrationTest.php @@ -0,0 +1,57 @@ +insertItem( 'Q10' ); + + $this->insertItem( 'Q20', new TimeValue( + '+20-00-00T00:00:00Z', + 0, 0, 0, TimeValue::PRECISION_YEAR, 'Stardate' + ) ); + + $this->insertItem( 'Q21', new TimeValue( + '+21-00-00T00:00:00Z', + 0, 0, 0, TimeValue::PRECISION_YEAR, 'Stardate' + ) ); + } + + public function queryProvider() { + return array( + array( + new TimeValue( + '+20-00-00T00:00:00Z', + 0, 0, 0, TimeValue::PRECISION_YEAR, 'Stardate' + ), + array( 'Q20' ), + ), + array( + new TimeValue( + '+21-00-00T00:00:00Z', + 0, 0, 0, TimeValue::PRECISION_YEAR, 'Stardate' + ), + array( 'Q21' ), + ), + ); + } + +}