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

testCreate() public method

public testCreate ( )
    public function testCreate()
    {
        $handler = $this->getContentHandler();
        $mapperMock = $this->getMapperMock();
        $gatewayMock = $this->getGatewayMock();
        $fieldHandlerMock = $this->getFieldHandlerMock();
        $locationMock = $this->getLocationGatewayMock();
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
        $contentTypeMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Type');
        $createStruct = $this->getCreateStructFixture();
        $contentTypeHandlerMock->expects($this->once())->method('load')->with($createStruct->typeId)->will($this->returnValue($contentTypeMock));
        $mapperMock->expects($this->once())->method('createVersionInfoFromCreateStruct')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct'))->will($this->returnValue(new VersionInfo(array('names' => array(), 'contentInfo' => new ContentInfo()))));
        $gatewayMock->expects($this->once())->method('insertContentObject')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct'))->will($this->returnValue(23));
        $gatewayMock->expects($this->once())->method('insertVersion')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo'), $this->isType('array'))->will($this->returnValue(1));
        $fieldHandlerMock->expects($this->once())->method('createNewFields')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'), $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Type'));
        $locationMock->expects($this->once())->method('createNodeAssignment')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\CreateStruct'), $this->equalTo(42), $this->equalTo(3));
        $res = $handler->create($createStruct);
        // @todo Make subsequent tests
        $this->assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content', $res, 'Content not created');
        $this->assertEquals(23, $res->versionInfo->contentInfo->id, 'Content ID not set correctly');
        $this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo', $res->versionInfo, 'Version infos not created');
        $this->assertEquals(1, $res->versionInfo->id, 'Version ID not set correctly');
        $this->assertEquals(2, count($res->fields), 'Fields not set correctly in version');
    }