eZ\Publish\Core\Persistence\Legacy\Tests\Content\ContentHandlerTest::testCreateDraftFromVersion PHP Method

testCreateDraftFromVersion() public method

    public function testCreateDraftFromVersion()
    {
        $handler = $this->getPartlyMockedHandler(array('load'));
        $mapperMock = $this->getMapperMock();
        $gatewayMock = $this->getGatewayMock();
        $fieldHandlerMock = $this->getFieldHandlerMock();
        $handler->expects($this->once())->method('load')->with(23, 2)->will($this->returnValue($this->getContentFixtureForDraft()));
        $mapperMock->expects($this->once())->method('createVersionInfoForContent')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'), $this->equalTo(3), $this->equalTo(14))->will($this->returnValue(new VersionInfo(array('names' => array(), 'versionNo' => 3))));
        $gatewayMock->expects($this->once())->method('insertVersion')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo'), $this->getContentFixtureForDraft()->fields)->will($this->returnValue(42));
        $gatewayMock->expects($this->once())->method('getLastVersionNumber')->with($this->equalTo(23))->will($this->returnValue(2));
        $fieldHandlerMock->expects($this->once())->method('createExistingFieldsInNewVersion')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'));
        $relationData = array(array('ezcontentobject_link_contentclassattribute_id' => 0, 'ezcontentobject_link_to_contentobject_id' => 42, 'ezcontentobject_link_relation_type' => 1));
        $gatewayMock->expects($this->once())->method('loadRelations')->with($this->equalTo(23), $this->equalTo(2))->will($this->returnValue($relationData));
        $relationStruct = new RelationCreateStruct(array('sourceContentId' => 23, 'sourceContentVersionNo' => 3, 'sourceFieldDefinitionId' => 0, 'destinationContentId' => 42, 'type' => 1));
        $gatewayMock->expects($this->once())->method('insertRelation')->with($this->equalTo($relationStruct));
        $result = $handler->createDraftFromVersion(23, 2, 14);
        $this->assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content', $result);
        $this->assertEquals(42, $result->versionInfo->id);
    }