summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/EntityStore/TraversalPropertyLookupTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/EntityStore/TraversalPropertyLookupTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/EntityStore/TraversalPropertyLookupTest.php140
1 files changed, 140 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/EntityStore/TraversalPropertyLookupTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/EntityStore/TraversalPropertyLookupTest.php
new file mode 100644
index 00000000..50ca8b28
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/EntityStore/TraversalPropertyLookupTest.php
@@ -0,0 +1,140 @@
+<?php
+
+namespace SMW\Tests\SQLStore\EntityStore;
+
+use SMW\DIWikiPage;
+use SMW\Options;
+use SMW\SQLStore\EntityStore\TraversalPropertyLookup;
+
+/**
+ * @covers \SMW\SQLStore\EntityStore\TraversalPropertyLookup
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 3.0
+ *
+ * @author mwjames
+ */
+class TraversalPropertyLookupTest extends \PHPUnit_Framework_TestCase {
+
+ public function testCanConstruct() {
+
+ $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->assertInstanceOf(
+ TraversalPropertyLookup::class,
+ new TraversalPropertyLookup( $store )
+ );
+ }
+
+ public function testlookupForNonFixedPropertyTable() {
+
+ $dataItem = DIWikiPage::newFromText( __METHOD__ );
+
+ $dataItemHandler = $this->getMockBuilder( '\SMW\SQLStore\EntityStore\DataItemHandler' )
+ ->disableOriginalConstructor()
+ ->getMockForAbstractClass();
+
+ $dataItemHandler->expects( $this->atLeastOnce() )
+ ->method( 'getWhereConds' )
+ ->will( $this->returnValue( [ 'o_id' => 42 ] ) );
+
+ $propertyTableDef = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableDefinition' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $propertyTableDef->expects( $this->atLeastOnce() )
+ ->method( 'isFixedPropertyTable' )
+ ->will( $this->returnValue( false ) );
+
+ $connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $connection->expects( $this->atLeastOnce() )
+ ->method( 'select' )
+ ->will( $this->returnValue( [] ) );
+
+ $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
+ ->disableOriginalConstructor()
+ ->setMethods( [ 'getConnection', 'getDataItemHandlerForDIType', 'getSQLOptions', 'getSQLConditions' ] )
+ ->getMock();
+
+ $store->expects( $this->atLeastOnce() )
+ ->method( 'getSQLOptions' )
+ ->will( $this->returnValue( [] ) );
+
+ $store->expects( $this->atLeastOnce() )
+ ->method( 'getSQLConditions' )
+ ->will( $this->returnValue( '' ) );
+
+ $store->expects( $this->atLeastOnce() )
+ ->method( 'getConnection' )
+ ->will( $this->returnValue( $connection ) );
+
+ $store->expects( $this->atLeastOnce() )
+ ->method( 'getDataItemHandlerForDIType' )
+ ->will( $this->returnValue( $dataItemHandler ) );
+
+ $instance = new TraversalPropertyLookup(
+ $store
+ );
+
+ $instance->fetchFromTable( $propertyTableDef, $dataItem );
+ }
+
+ public function testlookupForFixedPropertyTable() {
+
+ $dataItem = DIWikiPage::newFromText( __METHOD__ );
+
+ $resultWrapper = $this->getMockBuilder( '\FakeResultWrapper' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dataItemHandler = $this->getMockBuilder( '\SMW\SQLStore\EntityStore\DataItemHandler' )
+ ->disableOriginalConstructor()
+ ->getMockForAbstractClass();
+
+ $dataItemHandler->expects( $this->atLeastOnce() )
+ ->method( 'getWhereConds' )
+ ->will( $this->returnValue( [ 'o_id' => 42 ] ) );
+
+ $propertyTableDef = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableDefinition' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $propertyTableDef->expects( $this->atLeastOnce() )
+ ->method( 'isFixedPropertyTable' )
+ ->will( $this->returnValue( true ) );
+
+ $connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $connection->expects( $this->atLeastOnce() )
+ ->method( 'select' )
+ ->will( $this->returnValue( $resultWrapper ) );
+
+ $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
+ ->disableOriginalConstructor()
+ ->setMethods( [ 'getConnection', 'getDataItemHandlerForDIType' ] )
+ ->getMock();
+
+ $store->expects( $this->atLeastOnce() )
+ ->method( 'getConnection' )
+ ->will( $this->returnValue( $connection ) );
+
+ $store->expects( $this->atLeastOnce() )
+ ->method( 'getDataItemHandlerForDIType' )
+ ->will( $this->returnValue( $dataItemHandler ) );
+
+ $instance = new TraversalPropertyLookup(
+ $store
+ );
+
+ $instance->fetchFromTable( $propertyTableDef, $dataItem );
+ }
+
+}