diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/SQLStore/Writer/DataUpdateTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/SQLStore/Writer/DataUpdateTest.php | 409 |
1 files changed, 409 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/SQLStore/Writer/DataUpdateTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/SQLStore/Writer/DataUpdateTest.php new file mode 100644 index 00000000..995215ee --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/SQLStore/Writer/DataUpdateTest.php @@ -0,0 +1,409 @@ +<?php + +namespace SMW\Tests\SQLStore\Writer; + +use SMW\DIWikiPage; +use SMWSQLStore3Writers; +use Title; + +/** + * @covers \SMWSQLStore3Writers + * + * @group SMW + * @group SMWExtension + * + * @group semantic-mediawiki-sqlstore + * @group mediawiki-databaseless + * + * @license GNU GPL v2+ + * @since 1.9.2 + * + * @author mwjames + */ +class DataUpdateTest extends \PHPUnit_Framework_TestCase { + + private $store; + private $factory; + + protected function setUp() { + + $entityManager = $this->getMockBuilder( '\SMWSql3SmwIds' ) + ->disableOriginalConstructor() + ->getMock(); + + $entityManager->expects( $this->any() ) + ->method( 'findAllEntitiesThatMatch' ) + ->will( $this->returnValue( [] ) ); + + $this->store = $this->getMockBuilder( '\SMWSQLStore3' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->store->expects( $this->any() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $entityManager ) ); + + $this->store->expects( $this->any() ) + ->method( 'getPropertyTables' ) + ->will( $this->returnValue( [] ) ); + + $propertyTableRowDiffer = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableRowDiffer' ) + ->disableOriginalConstructor() + ->getMock(); + + $propertyTableRowDiffer->expects( $this->any() ) + ->method( 'computeTableRowDiff' ) + ->will( $this->returnValue( [ [], [], [] ] ) ); + + $propertyTableUpdater = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableUpdater' ) + ->disableOriginalConstructor() + ->getMock(); + + $propertyStatisticsStore = $this->getMockBuilder( '\SMW\SQLStore\PropertyStatisticsStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $hierarchyLookup = $this->getMockBuilder( '\SMW\HierarchyLookup' ) + ->disableOriginalConstructor() + ->getMock(); + + $subobjectListFinder = $this->getMockBuilder( '\SMW\SQLStore\EntityStore\SubobjectListFinder' ) + ->disableOriginalConstructor() + ->getMock(); + + $subobjectListFinder->expects( $this->any() ) + ->method( 'find' ) + ->will( $this->returnValue( [] ) ); + + $changePropListener = $this->getMockBuilder( '\SMW\ChangePropListener' ) + ->disableOriginalConstructor() + ->getMock(); + + $semanticDataLookup = $this->getMockBuilder( '\SMW\SQLStore\EntityStore\CachingSemanticDataLookup' ) + ->disableOriginalConstructor() + ->getMock(); + + $changeDiff = $this->getMockBuilder( '\SMW\SQLStore\ChangeOp\ChangeDiff' ) + ->disableOriginalConstructor() + ->getMock(); + + $changeDiff->expects( $this->any() ) + ->method( 'getTextItems' ) + ->will( $this->returnValue( [] ) ); + + $changeDiff->expects( $this->any() ) + ->method( 'getTableChangeOps' ) + ->will( $this->returnValue( [] ) ); + + $changeOp = $this->getMockBuilder( '\SMW\SQLStore\ChangeOp\ChangeOp' ) + ->disableOriginalConstructor() + ->getMock(); + + $changeOp->expects( $this->any() ) + ->method( 'newChangeDiff' ) + ->will( $this->returnValue( $changeDiff ) ); + + $changeOp->expects( $this->any() ) + ->method( 'getChangedEntityIdSummaryList' ) + ->will( $this->returnValue( [] ) ); + + $changeOp->expects( $this->any() ) + ->method( 'getDataOps' ) + ->will( $this->returnValue( [] ) ); + + $changeOp->expects( $this->any() ) + ->method( 'getTableChangeOps' ) + ->will( $this->returnValue( [] ) ); + + $changeOp->expects( $this->any() ) + ->method( 'getOrderedDiffByTable' ) + ->will( $this->returnValue( [] ) ); + + $this->factory = $this->getMockBuilder( '\SMW\SQLStore\SQLStoreFactory' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->factory->expects( $this->any() ) + ->method( 'newPropertyStatisticsStore' ) + ->will( $this->returnValue( $propertyStatisticsStore ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newHierarchyLookup' ) + ->will( $this->returnValue( $hierarchyLookup ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newSubobjectListFinder' ) + ->will( $this->returnValue( $subobjectListFinder ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newChangePropListener' ) + ->will( $this->returnValue( $changePropListener ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newPropertyTableRowDiffer' ) + ->will( $this->returnValue( $propertyTableRowDiffer ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newPropertyTableUpdater' ) + ->will( $this->returnValue( $propertyTableUpdater ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newSemanticDataLookup' ) + ->will( $this->returnValue( $semanticDataLookup ) ); + + $this->factory->expects( $this->any() ) + ->method( 'newChangeOp' ) + ->will( $this->returnValue( $changeOp ) ); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + '\SMWSQLStore3Writers', + new SMWSQLStore3Writers( $this->store, $this->factory ) + ); + } + + public function testDoDataUpdateForMainNamespaceWithoutSubobject() { + + $title = Title::newFromText( __METHOD__, NS_MAIN ); + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->setConstructorArgs( [ DIWikiPage::newFromTitle( $title ) ] ) + ->setMethods( null ) + ->getMock(); + + $objectIdGenerator = $this->getMockBuilder( '\SMWSql3SmwIds' ) + ->disableOriginalConstructor() + ->getMock(); + + $objectIdGenerator->expects( $this->any() ) + ->method( 'findAllEntitiesThatMatch' ) + ->will( $this->returnValue( [] ) ); + + $objectIdGenerator->expects( $this->once() ) + ->method( 'getSMWPageIDandSort' ) + ->will( $this->returnValue( 0 ) ); + + $objectIdGenerator->expects( $this->once() ) + ->method( 'makeSMWPageID' ) + ->will( $this->returnValue( 0 ) ); + + $database = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore->expects( $this->any() ) + ->method( 'getPropertyTableInfoFetcher' ) + ->will( $this->returnValue( $propertyTableInfoFetcher ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $objectIdGenerator ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $database ) ); + + $parentStore->expects( $this->any() ) + ->method( 'getPropertyTables' ) + ->will( $this->returnValue( [] ) ); + + $parentStore->expects( $this->any() ) + ->method( 'getOptions' ) + ->will( $this->returnValue( new \SMW\Options() ) ); + + $instance = new SMWSQLStore3Writers( $parentStore, $this->factory ); + $instance->doDataUpdate( $semanticData ); + } + + public function testDoDataUpdateForConceptNamespaceWithoutSubobject() { + + $title = Title::newFromText( __METHOD__, SMW_NS_CONCEPT ); + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->setConstructorArgs( [ DIWikiPage::newFromTitle( $title ) ] ) + ->setMethods( null ) + ->getMock(); + + $objectIdGenerator = $this->getMockBuilder( '\SMWSql3SmwIds' ) + ->disableOriginalConstructor() + ->getMock(); + + $objectIdGenerator->expects( $this->any() ) + ->method( 'findAllEntitiesThatMatch' ) + ->will( $this->returnValue( [] ) ); + + $objectIdGenerator->expects( $this->once() ) + ->method( 'getSMWPageIDandSort' ) + ->will( $this->returnValue( 0 ) ); + + $objectIdGenerator->expects( $this->once() ) + ->method( 'makeSMWPageID' ) + ->will( $this->returnValue( 0 ) ); + + $database = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore->expects( $this->any() ) + ->method( 'getPropertyTableInfoFetcher' ) + ->will( $this->returnValue( $propertyTableInfoFetcher ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $objectIdGenerator ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $database ) ); + + $parentStore->expects( $this->any() ) + ->method( 'getPropertyTables' ) + ->will( $this->returnValue( [] ) ); + + $parentStore->expects( $this->any() ) + ->method( 'getOptions' ) + ->will( $this->returnValue( new \SMW\Options() ) ); + + $instance = new SMWSQLStore3Writers( $parentStore, $this->factory ); + $instance->doDataUpdate( $semanticData ); + } + + public function testDoDataUpdateForMainNamespaceWithRedirect() { + + $title = Title::newFromText( __METHOD__, NS_MAIN ); + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->setConstructorArgs( [ DIWikiPage::newFromTitle( $title ) ] ) + ->setMethods( [ 'getPropertyValues' ] ) + ->getMock(); + + $semanticData->expects( $this->once() ) + ->method( 'getPropertyValues' ) + ->will( $this->returnValue( [ DIWikiPage::newFromTitle( $title ) ] ) ); + + $objectIdGenerator = $this->getMockBuilder( '\SMWSql3SmwIds' ) + ->disableOriginalConstructor() + ->getMock(); + + $objectIdGenerator->expects( $this->once() ) + ->method( 'getSMWPageIDandSort' ) + ->will( $this->returnValue( 0 ) ); + + $objectIdGenerator->expects( $this->once() ) + ->method( 'makeSMWPageID' ) + ->will( $this->returnValue( 0 ) ); + + $database = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore->expects( $this->any() ) + ->method( 'getPropertyTableInfoFetcher' ) + ->will( $this->returnValue( $propertyTableInfoFetcher ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $objectIdGenerator ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $database ) ); + + $parentStore->expects( $this->any() ) + ->method( 'getOptions' ) + ->will( $this->returnValue( new \SMW\Options() ) ); + + $instance = new SMWSQLStore3Writers( $parentStore, $this->factory ); + $instance->doDataUpdate( $semanticData ); + } + + public function testAtomicTransactionOnDataUpdate() { + + $title = Title::newFromText( __METHOD__, NS_MAIN ); + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->setConstructorArgs( [ DIWikiPage::newFromTitle( $title ) ] ) + ->setMethods( [ 'getPropertyValues' ] ) + ->getMock(); + + $semanticData->expects( $this->once() ) + ->method( 'getPropertyValues' ) + ->will( $this->returnValue( [ DIWikiPage::newFromTitle( $title ) ] ) ); + + $objectIdGenerator = $this->getMockBuilder( '\SMWSql3SmwIds' ) + ->disableOriginalConstructor() + ->getMock(); + + $objectIdGenerator->expects( $this->atLeastOnce() ) + ->method( 'getSMWPageIDandSort' ) + ->will( $this->returnValue( 0 ) ); + + $objectIdGenerator->expects( $this->atLeastOnce() ) + ->method( 'makeSMWPageID' ) + ->will( $this->returnValue( 0 ) ); + + $database = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $database->expects( $this->atLeastOnce() ) + ->method( 'beginAtomicTransaction' ); + + $database->expects( $this->atLeastOnce() ) + ->method( 'endAtomicTransaction' ); + + $propertyTableInfoFetcher = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableInfoFetcher' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $parentStore->expects( $this->any() ) + ->method( 'getPropertyTableInfoFetcher' ) + ->will( $this->returnValue( $propertyTableInfoFetcher ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $objectIdGenerator ) ); + + $parentStore->expects( $this->atLeastOnce() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $database ) ); + + $parentStore->expects( $this->any() ) + ->method( 'getOptions' ) + ->will( $this->returnValue( new \SMW\Options() ) ); + + $instance = new SMWSQLStore3Writers( $parentStore, $this->factory ); + $instance->doDataUpdate( $semanticData ); + } + +} |