Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/65814


Change subject: Added EntityUpdater
......................................................................

Added EntityUpdater

Change-Id: I809273a8b21ff08522c9d9331b8f917478e51cc8
---
A QueryEngine/includes/SQLStore/EntityUpdater.php
A QueryEngine/tests/phpunit/SQLStore/EntityUpdaterTest.php
2 files changed, 170 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/14/65814/1

diff --git a/QueryEngine/includes/SQLStore/EntityUpdater.php 
b/QueryEngine/includes/SQLStore/EntityUpdater.php
new file mode 100644
index 0000000..255d735
--- /dev/null
+++ b/QueryEngine/includes/SQLStore/EntityUpdater.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace Wikibase\QueryEngine\SQLStore;
+
+use Wikibase\Entity;
+
+/**
+ * Use case for updating entities in the store.
+ *
+ * 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
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup WikibaseSQLStore
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EntityUpdater {
+
+       private $remover;
+       private $inserter;
+
+       /**
+        * @since 0.1
+        *
+        */
+       public function __construct( EntityRemover $remover, EntityInserter 
$inserter ) {
+               $this->remover = $remover;
+               $this->inserter = $inserter;
+       }
+
+       /**
+        * @since 0.1
+        *
+        * @param Entity $entity
+        */
+       public function updateEntity( Entity $entity ) {
+               $this->remover->removeEntity( $entity );
+               $this->inserter->insertEntity( $entity );
+       }
+
+}
diff --git a/QueryEngine/tests/phpunit/SQLStore/EntityUpdaterTest.php 
b/QueryEngine/tests/phpunit/SQLStore/EntityUpdaterTest.php
new file mode 100644
index 0000000..d449278
--- /dev/null
+++ b/QueryEngine/tests/phpunit/SQLStore/EntityUpdaterTest.php
@@ -0,0 +1,113 @@
+<?php
+
+namespace Wikibase\QueryEngine\Tests\SQLStore;
+
+use Wikibase\Claim;
+use Wikibase\Database\FieldDefinition;
+use Wikibase\Database\TableDefinition;
+use Wikibase\Entity;
+use Wikibase\Item;
+use Wikibase\Property;
+use Wikibase\PropertyNoValueSnak;
+use Wikibase\QueryEngine\SQLStore\DataValueTable;
+use Wikibase\QueryEngine\SQLStore\EntityUpdater;
+
+/**
+ * @covers Wikibase\QueryEngine\SQLStore\EntityUpdater
+ *
+ * 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 EntityUpdaterTest extends \PHPUnit_Framework_TestCase {
+
+       /**
+        * @dataProvider entityProvider
+        */
+       public function testUpdateEntity( Entity $entity ) {
+               $remover = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\EntityRemover' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $remover->expects( $this->once() )
+                       ->method( 'removeEntity' )
+                       ->with( $this->equalTo( $entity ) );
+
+               $inserter = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\EntityInserter' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $inserter->expects( $this->once() )
+                       ->method( 'insertEntity' )
+                       ->with( $this->equalTo( $entity ) );
+
+               $updater = new EntityUpdater( $remover, $inserter );
+
+               $updater->updateEntity( $entity );
+       }
+
+       public function entityProvider() {
+               $argLists = array();
+
+               $item = Item::newEmpty();
+               $item->setId( 42 );
+
+               $argLists[] = array( $item );
+
+
+               $item = Item::newEmpty();
+               $item->setId( 31337 );
+
+               $argLists[] = array( $item );
+
+
+               $property = Property::newEmpty();
+               $property->setDataTypeId( 'string' );
+               $property->setId( 9001 );
+
+               $argLists[] = array( $property );
+
+
+               $property = Property::newEmpty();
+               $property->setDataTypeId( 'string' );
+               $property->setId( 1 );
+               $property->addAliases( 'en', array( 'foo', 'bar', 'baz' ) );
+               $property->addClaim( new Claim( new PropertyNoValueSnak( 42 ) ) 
);
+
+               $argLists[] = array( $property );
+
+
+               $item = Item::newEmpty();
+               $item->setId( 2 );
+               $item->addClaim( new Claim( new PropertyNoValueSnak( 42 ) ) );
+               $item->addClaim( new Claim( new PropertyNoValueSnak( 43 ) ) );
+               $item->addClaim( new Claim( new PropertyNoValueSnak( 44 ) ) );
+
+               $argLists[] = array( $item );
+
+               return $argLists;
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I809273a8b21ff08522c9d9331b8f917478e51cc8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to