Skip to content
This repository was archived by the owner on Sep 16, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions tests/Integration/IntegrationStoreBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Wikibase\QueryEngine\Tests\Integration\SQLStore\DVHandler;

use DataValues\BooleanValue;
use Wikibase\QueryEngine\Tests\Integration\SQLStore\DataValueHandlerIntegrationTest;

/**
* @group Wikibase
* @group WikibaseQueryEngine
* @group WikibaseQueryEngineIntegration
*
* @group medium
*
* @licence GNU GPL v2+
* @author Thiemo Mättig
*/
class BooleanHandlerIntegrationTest extends DataValueHandlerIntegrationTest {

public function getDataValueType() {
return 'boolean';
}

protected function insertItems() {
$this->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' ),
),
);
}

}
129 changes: 129 additions & 0 deletions tests/Integration/SQLStore/DataValueHandlerIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

namespace Wikibase\QueryEngine\Tests\Integration\SQLStore;

use Ask\Language\Description\SomeProperty;
use Ask\Language\Description\ValueDescription;
use Ask\Language\Option\QueryOptions;
use DataValues\DataValue;
use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\QueryEngine\SQLStore\SQLStoreWithDependencies;
use Wikibase\QueryEngine\Tests\Integration\IntegrationStoreBuilder;

/**
* @licence GNU GPL v2+
* @author Thiemo Mättig
*/
abstract class DataValueHandlerIntegrationTest extends \PHPUnit_Framework_TestCase {

/**
* @var SQLStoreWithDependencies
*/
private $store;

/**
* @var int
*/
private $guidCounter = 0;

/**
* @return string
*/
abstract public function getDataValueType();

abstract protected function insertItems();

/**
* @return array[]
*/
abstract public function queryProvider();

public function setUp() {
$this->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 );
}

}