Skip to content

Instantly share code, notes, and snippets.

@JeroenDeDauw
Created April 10, 2013 15:17
Show Gist options
  • Save JeroenDeDauw/5355531 to your computer and use it in GitHub Desktop.
Save JeroenDeDauw/5355531 to your computer and use it in GitHub Desktop.
<?php
namespace Wikibase\Test\Query\SQLStore;
use Wikibase\Database\FieldDefinition;
use Wikibase\Database\ObservableQueryInterface;
use Wikibase\Database\TableDefinition;
use Wikibase\Item;
use Wikibase\QueryEngine\SQLStore\DVHandler\BooleanHandler;
use Wikibase\QueryEngine\SQLStore\DVHandler\MonolingualTextHandler;
use Wikibase\QueryEngine\SQLStore\DataValueTable;
use Wikibase\QueryEngine\SQLStore\Schema;
use Wikibase\QueryEngine\SQLStore\StoreConfig;
use Wikibase\QueryEngine\SQLStore\Updater;
use Wikibase\Test\Query\QueryStoreUpdaterTest;
/**
* Unit tests for the Wikibase\QueryEngine\SQLStore\Updater class.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @since 0.1
*
* @ingroup WikibaseQueryEngineTest
*
* @group Wikibase
* @group WikibaseQueryEngine
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
class UpdaterTest extends QueryStoreUpdaterTest {
/**
* @see QueryStoreUpdaterTest::getInstances
*
* @since 0.1
*
* @return Updater[]
*/
protected function getInstances() {
$instances = array();
$storeSchema = new Schema( new StoreConfig( 'foo', 'bar', array() ) );
$queryInterface = new ObservableQueryInterface();
$instances[] = new Updater( $storeSchema, $queryInterface );
return $instances;
}
protected function newStoreSchema() {
$dataValueHandlers = array();
$dataValueHandlers['boolean'] = new BooleanHandler( new DataValueTable(
new TableDefinition(
'boolean',
array(
new FieldDefinition( 'value', FieldDefinition::TYPE_BOOLEAN, false ),
)
),
'value',
'value'
) );
$dataValueHandlers['monolingualtext'] = new MonolingualTextHandler( new DataValueTable(
new TableDefinition(
'mono_text',
array(
new FieldDefinition( 'text', FieldDefinition::TYPE_TEXT, false ),
new FieldDefinition( 'language', FieldDefinition::TYPE_TEXT, false ),
new FieldDefinition( 'json', FieldDefinition::TYPE_TEXT, false ),
)
),
'json',
'text',
'text'
) );
return new Schema( new StoreConfig( 'foobar', 'nyan', $dataValueHandlers ) );
}
public function testInsertEntity() {
$item = Item::newEmpty();
$item->setId( 42 );
$queryInterface = new ObservableQueryInterface();
$assertEquals = array( $this, 'assertEquals' );
$queryInterface->registerCallback(
'insert',
function( $tableName, array $values ) use ( $assertEquals ) {
call_user_func(
$assertEquals,
'nyan_entities',
$tableName,
'The only insert call should be to the entities table'
);
call_user_func(
$assertEquals,
'nyan_entities',
array(
'type' => 'item',
'number' => 42,
),
'The entity info should be inserted correctly'
);
}
);
$updater = new Updater( $this->newStoreSchema(), $queryInterface );
$updater->insertEntity( $item );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment