public function testPublish()
{
$handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus'));
$gatewayMock = $this->getGatewayMock();
$mapperMock = $this->getMapperMock();
$locationMock = $this->getLocationGatewayMock();
$fieldHandlerMock = $this->getFieldHandlerMock();
$metadataUpdateStruct = new MetadataUpdateStruct();
$handler->expects($this->at(0))->method('loadVersionInfo')->with(23, 2)->will($this->returnValue(new VersionInfo(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))));
$handler->expects($this->at(1))->method('setStatus')->with(23, VersionInfo::STATUS_ARCHIVED, 1);
$gatewayMock->expects($this->once())->method('load')->with($this->equalTo(23), $this->equalTo(2), $this->equalTo(null))->will($this->returnValue(array(42)));
$gatewayMock->expects($this->once())->method('loadVersionedNameData')->with($this->equalTo(array(array('id' => 23, 'version' => 2))))->will($this->returnValue(array(22)));
$mapperMock->expects($this->once())->method('extractContentFromRows')->with($this->equalTo(array(42)), $this->equalTo(array(22)))->will($this->returnValue(array($this->getContentFixtureForDraft())));
$fieldHandlerMock->expects($this->once())->method('loadExternalFieldData')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'));
$gatewayMock->expects($this->once())->method('updateContent')->with(23, $metadataUpdateStruct, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo'));
$locationMock->expects($this->once())->method('createLocationsFromNodeAssignments')->with(23, 2);
$locationMock->expects($this->once())->method('updateLocationsContentVersionNo')->with(23, 2);
$handler->expects($this->at(2))->method('setStatus')->with(23, VersionInfo::STATUS_PUBLISHED, 2);
$handler->publish(23, 2, $metadataUpdateStruct);
}