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..ce098c8 --- /dev/null +++ b/tests/Integration/SQLStore/DataValueHandlerIntegrationTest.php @@ -0,0 +1,129 @@ +store = IntegrationStoreBuilder::newStore( $this ); + + $this->store->newInstaller()->install(); + + $this->insertItems(); + } + + public function tearDown() { + if ( isset( $this->store ) ) { + $this->store->newUninstaller()->uninstall(); + } + } + + /** + * @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 ) { + $mainSnak = new PropertyValueSnak( new PropertyId( 'P7701' ), $dataValue ); + + $guid = 'statement' . $this->guidCounter; + $this->guidCounter++; + + $item->getStatements()->addNewStatement( $mainSnak, null, null, $guid ); + } + + $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( new PropertyId( 'P7701' ) ), + 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 ); + } + + /** + * @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 ); + } + +}