public function testCopyAllVersions()
{
$handler = $this->getPartlyMockedHandler(array('loadContentInfo', 'load', 'internalCreate', 'listVersions'));
$gatewayMock = $this->getGatewayMock();
$mapperMock = $this->getMapperMock();
$fieldHandlerMock = $this->getFieldHandlerMock();
$contentTypeHandlerMock = $this->getContentTypeHandlerMock();
$contentTypeMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Type');
$time = time();
$createStructStub = new CreateStruct(array('modified' => $time, 'typeId' => 4242));
$contentTypeHandlerMock->expects($this->once())->method('load')->with($createStructStub->typeId)->will($this->returnValue($contentTypeMock));
$handler->expects($this->once())->method('loadContentInfo')->with($this->equalTo(23))->will($this->returnValue(new ContentInfo(array('currentVersionNo' => 2))));
$handler->expects($this->at(1))->method('load')->with($this->equalTo(23), $this->equalTo(2))->will($this->returnValue(new Content()));
$mapperMock->expects($this->once())->method('createCreateStructFromContent')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'))->will($this->returnValue($createStructStub));
$handler->expects($this->once())->method('internalCreate')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct'), $this->equalTo(2))->will($this->returnValue(new Content(array('versionInfo' => new VersionInfo(array('contentInfo' => new ContentInfo(array('id' => 24))))))));
$handler->expects($this->once())->method('listVersions')->with($this->equalTo(23))->will($this->returnValue(array(new VersionInfo(array('versionNo' => 1)), new VersionInfo(array('versionNo' => 2)))));
$versionInfo = new VersionInfo(array('names' => array('eng-US' => 'Test'), 'contentInfo' => new ContentInfo(array('id' => 24, 'alwaysAvailable' => true))));
$handler->expects($this->at(4))->method('load')->with($this->equalTo(23), $this->equalTo(1))->will($this->returnValue(new Content(array('versionInfo' => $versionInfo, 'fields' => array()))));
$versionInfo->creationDate = $time;
$versionInfo->modificationDate = $time;
$gatewayMock->expects($this->once())->method('insertVersion')->with($this->equalTo($versionInfo), $this->isType('array'))->will($this->returnValue(42));
$versionInfo = clone $versionInfo;
$versionInfo->id = 42;
$fieldHandlerMock->expects($this->once())->method('createNewFields')->with($this->equalTo(new Content(array('versionInfo' => $versionInfo, 'fields' => array()))), $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Type'));
$gatewayMock->expects($this->once())->method('setName')->with($this->equalTo(24), $this->equalTo(1), $this->equalTo('Test'), $this->equalTo('eng-US'));
$gatewayMock->expects($this->once())->method('copyRelations')->with($this->equalTo(23), $this->equalTo(24), $this->equalTo(null))->will($this->returnValue(null));
$result = $handler->copy(23);
$this->assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content', $result);
}