eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testCreateContentObjectStates PHP Method

testCreateContentObjectStates() public method

Test for the createContent() method.
    public function testCreateContentObjectStates()
    {
        $spiFields = array(new SPIField(array('fieldDefinitionId' => 'fieldDefinitionId', 'type' => 'fieldTypeIdentifier', 'value' => 'defaultValue', 'languageCode' => 'eng-US')));
        $fieldDefinitions = array(new FieldDefinition(array('id' => 'fieldDefinitionId', 'fieldTypeIdentifier' => 'fieldTypeIdentifier', 'isTranslatable' => false, 'identifier' => 'identifier', 'isRequired' => false, 'defaultValue' => 'defaultValue')));
        $objectStateGroups = array(new SPIObjectStateGroup(array('id' => 10)), new SPIObjectStateGroup(array('id' => 20)));
        // Set up a simple case that will pass
        $contentCreateStruct = $this->assertForTestCreateContentNonRedundantFieldSet('eng-US', array(), $spiFields, $fieldDefinitions, array(), true, false);
        $timestamp = time();
        $contentCreateStruct->modificationDate = new \DateTime("@{$timestamp}");
        $repositoryMock = $this->getRepositoryMock();
        $mockedService = $this->getPartlyMockedContentService();
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
        $handlerMock = $this->getPersistenceMock()->contentHandler();
        $domainMapperMock = $this->getDomainMapperMock();
        $this->mockGetDefaultObjectStates();
        $this->mockSetDefaultObjectStates();
        $spiContentCreateStruct = new SPIContentCreateStruct(array('name' => array(), 'typeId' => 123, 'sectionId' => 1, 'ownerId' => 169, 'remoteId' => 'hash', 'fields' => $spiFields, 'modified' => $timestamp, 'initialLanguageId' => 4242, 'locations' => array()));
        $spiContentCreateStruct2 = clone $spiContentCreateStruct;
        ++$spiContentCreateStruct2->modified;
        $spiContent = new SPIContent(array('versionInfo' => new SPIContent\VersionInfo(array('contentInfo' => new SPIContent\ContentInfo(array('id' => 42)), 'versionNo' => 7))));
        $handlerMock->expects($this->once())->method('create')->with($this->equalTo($spiContentCreateStruct))->will($this->returnValue($spiContent));
        $domainMapperMock->expects($this->once())->method('buildContentDomainObject')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'), $this->equalTo(null));
        $repositoryMock->expects($this->once())->method('commit');
        // Execute
        $mockedService->createContent($contentCreateStruct, array());
    }
ContentTest