propertyTableRowMapper = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableRowMapper' ) ->disableOriginalConstructor() ->getMock(); $this->propertyTableRowMapper->expects( $this->any() ) ->method( 'mapToRows' ) ->willReturn( [ [], [], [], [] ] ); } public function testCanConstruct() { $store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->assertInstanceOf( '\SMW\SQLStore\PropertyTableRowDiffer', new PropertyTableRowDiffer( $store, $this->propertyTableRowMapper ) ); } public function testComputeTableRowDiffForEmptyPropertyTables() { $subject = new DIWikiPage( 'Foo', NS_MAIN ); $semanticData = new SemanticData( $subject ); $propertyTables = []; $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) ->setMethods( [ 'getPropertyTables' ] ) ->getMock(); $store->expects( $this->any() ) ->method( 'getPropertyTables' ) ->willReturn( $propertyTables ); $instance = new PropertyTableRowDiffer( $store, $this->propertyTableRowMapper ); $result = $instance->computeTableRowDiff( 42, $semanticData ); $this->assertIsArray( $result ); } public function testChangeOp() { $subject = new DIWikiPage( 'Foo', NS_MAIN ); $semanticData = new SemanticData( $subject ); $propertyTables = []; $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) ->setMethods( [ 'getPropertyTables' ] ) ->getMock(); $store->expects( $this->any() ) ->method( 'getPropertyTables' ) ->willReturn( $propertyTables ); $instance = new PropertyTableRowDiffer( $store, $this->propertyTableRowMapper ); $instance->setChangeOp( new ChangeOp( $subject ) ); $result = $instance->computeTableRowDiff( 42, $semanticData ); $this->assertInstanceOf( '\SMW\SQLStore\ChangeOp\ChangeOp', $instance->getChangeOp() ); } public function testChangeOpWithUnknownFixedProperty() { $propertyTable = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableDefinition' ) ->disableOriginalConstructor() ->getMock(); $propertyTable->expects( $this->once() ) ->method( 'usesIdSubject' ) ->willReturn( true ); $propertyTable->expects( $this->atLeastOnce() ) ->method( 'isFixedPropertyTable' ) ->willReturn( true ); $propertyTable->expects( $this->atLeastOnce() ) ->method( 'getFixedProperty' ) ->willReturn( '_UNKNOWN_FIXED_PROPERTY' ); $subject = new DIWikiPage( 'Foo', NS_MAIN ); $semanticData = new SemanticData( $subject ); $propertyTables = [ $propertyTable ]; $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) ->setMethods( [ 'getPropertyTables' ] ) ->getMock(); $store->expects( $this->any() ) ->method( 'getPropertyTables' ) ->willReturn( $propertyTables ); $store->expects( $this->any() ) ->method( 'getPropertyTables' ) ->willReturn( $propertyTables ); $instance = new PropertyTableRowDiffer( $store, $this->propertyTableRowMapper ); $instance->setChangeOp( new ChangeOp( $subject ) ); $result = $instance->computeTableRowDiff( 42, $semanticData ); $this->assertInstanceOf( '\SMW\SQLStore\ChangeOp\ChangeOp', $instance->getChangeOp() ); $this->assertEmpty( $instance->getChangeOp()->getFixedPropertyRecords() ); } public function testChangeOpWithUnknownFixedProperty_Ghost() { $row = [ 'smw_proptable_hash' => null ]; $connection = $this->getMockBuilder( '\SMW\MediaWiki\Connection\Database' ) ->disableOriginalConstructor() ->getMock(); $connection->expects( $this->any() ) ->method( 'select' ) ->willReturn( [] ); $connection->expects( $this->any() ) ->method( 'selectRow' ) ->willReturn( (object)$row ); $propertyTable = $this->getMockBuilder( '\SMW\SQLStore\PropertyTableDefinition' ) ->disableOriginalConstructor() ->getMock(); $propertyTable->expects( $this->atLeastOnce() ) ->method( 'usesIdSubject' ) ->willReturn( true ); $propertyTable->expects( $this->atLeastOnce() ) ->method( 'isFixedPropertyTable' ) ->willReturn( true ); $propertyTable->expects( $this->atLeastOnce() ) ->method( 'getFixedProperty' ) ->willReturn( '_UNKNOWN_FIXED_PROPERTY' ); $subject = new DIWikiPage( 'Foo', NS_MAIN ); $semanticData = new SemanticData( $subject ); $propertyTables = [ $propertyTable ]; $idTable = $this->getMockBuilder( '\SMW\SQLStore\EntityStore\EntityIdManager' ) ->disableOriginalConstructor() ->getMock(); $idTable->expects( $this->any() ) ->method( 'getPropertyTableHashes' ) ->willReturn( [ 'foo' => 'abcdef10001' ] ); $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) ->disableOriginalConstructor() ->setMethods( [ 'getPropertyTables', 'getConnection', 'getObjectIds' ] ) ->getMock(); $store->expects( $this->any() ) ->method( 'getPropertyTables' ) ->willReturn( $propertyTables ); $store->expects( $this->any() ) ->method( 'getPropertyTables' ) ->willReturn( $propertyTables ); $store->expects( $this->any() ) ->method( 'getConnection' ) ->willReturn( $connection ); $store->expects( $this->any() ) ->method( 'getObjectIds' ) ->willReturn( $idTable ); $instance = new PropertyTableRowDiffer( $store, $this->propertyTableRowMapper ); $instance->setChangeOp( new ChangeOp( $subject ) ); $instance->checkRemnantEntities( true ); $result = $instance->computeTableRowDiff( 42, $semanticData ); $this->assertInstanceOf( '\SMW\SQLStore\ChangeOp\ChangeOp', $instance->getChangeOp() ); $this->assertEmpty( $instance->getChangeOp()->getFixedPropertyRecords() ); } }