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

assertForTestCreateContentNonRedundantFieldSet() protected method

Asserts that calling createContent() with given API field set causes calling Handler::createContent() with given SPI field set.
protected assertForTestCreateContentNonRedundantFieldSet ( string $mainLanguageCode, array $structFields, array $spiFields, array $fieldDefinitions, array $locationCreateStructs = [], $withObjectStates = false, boolean $execute = true ) : mixed
$mainLanguageCode string
$structFields array
$spiFields array
$fieldDefinitions array
$locationCreateStructs array
$execute boolean
return mixed
    protected function assertForTestCreateContentNonRedundantFieldSet($mainLanguageCode, array $structFields, array $spiFields, array $fieldDefinitions, array $locationCreateStructs = array(), $withObjectStates = false, $execute = true)
    {
        $repositoryMock = $this->getRepositoryMock();
        $mockedService = $this->getPartlyMockedContentService();
        /** @var \PHPUnit_Framework_MockObject_MockObject $contentHandlerMock */
        $contentHandlerMock = $this->getPersistenceMock()->contentHandler();
        /** @var \PHPUnit_Framework_MockObject_MockObject $languageHandlerMock */
        $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();
        /** @var \PHPUnit_Framework_MockObject_MockObject $objectStateHandlerMock */
        $objectStateHandlerMock = $this->getPersistenceMock()->objectStateHandler();
        $contentTypeServiceMock = $this->getContentTypeServiceMock();
        $fieldTypeServiceMock = $this->getFieldTypeServiceMock();
        $domainMapperMock = $this->getDomainMapperMock();
        $relationProcessorMock = $this->getRelationProcessorMock();
        $nameSchemaServiceMock = $this->getNameSchemaServiceMock();
        $fieldTypeMock = $this->getMock('eZ\\Publish\\SPI\\FieldType\\FieldType');
        $languageCodes = $this->determineLanguageCodesForCreate($mainLanguageCode, $structFields);
        $contentType = new ContentType(array('id' => 123, 'fieldDefinitions' => $fieldDefinitions, 'nameSchema' => '<nameSchema>'));
        $contentCreateStruct = new ContentCreateStruct(array('fields' => $structFields, 'mainLanguageCode' => $mainLanguageCode, 'contentType' => $contentType, 'alwaysAvailable' => false, 'ownerId' => 169, 'sectionId' => 1));
        $languageHandlerMock->expects($this->any())->method('loadByLanguageCode')->with($this->isType('string'))->will($this->returnCallback(function () {
            return new Language(array('id' => 4242));
        }));
        $repositoryMock->expects($this->once())->method('beginTransaction');
        $contentTypeServiceMock->expects($this->once())->method('loadContentType')->with($this->equalTo($contentType->id))->will($this->returnValue($contentType));
        $repositoryMock->expects($this->once())->method('getContentTypeService')->will($this->returnValue($contentTypeServiceMock));
        $that = $this;
        $repositoryMock->expects($this->once())->method('canUser')->with($this->equalTo('content'), $this->equalTo('create'), $this->isInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct'), $this->equalTo($locationCreateStructs))->will($this->returnCallback(function () use($that, $contentCreateStruct) {
            $that->assertEquals($contentCreateStruct, func_get_arg(2));
            return true;
        }));
        $domainMapperMock->expects($this->once())->method('getUniqueHash')->with($this->isInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct'))->will($this->returnCallback(function ($object) use($that, $contentCreateStruct) {
            $that->assertEquals($contentCreateStruct, $object);
            return 'hash';
        }));
        $fieldTypeMock->expects($this->any())->method('acceptValue')->will($this->returnCallback(function ($valueString) {
            return new ValueStub($valueString);
        }));
        $fieldTypeMock->expects($this->any())->method('toPersistenceValue')->will($this->returnCallback(function (ValueStub $value) {
            return (string) $value;
        }));
        $emptyValue = self::EMPTY_FIELD_VALUE;
        $fieldTypeMock->expects($this->any())->method('isEmptyValue')->will($this->returnCallback(function (ValueStub $value) use($emptyValue) {
            return $emptyValue === (string) $value;
        }));
        $fieldTypeMock->expects($this->any())->method('validate')->will($this->returnValue(array()));
        $this->getFieldTypeRegistryMock()->expects($this->any())->method('getFieldType')->will($this->returnValue($fieldTypeMock));
        $relationProcessorMock->expects($this->exactly(count($fieldDefinitions) * count($languageCodes)))->method('appendFieldRelations')->with($this->isType('array'), $this->isType('array'), $this->isInstanceOf('eZ\\Publish\\SPI\\FieldType\\FieldType'), $this->isInstanceOf('eZ\\Publish\\Core\\FieldType\\Value'), $this->anything());
        $values = $this->determineValuesForCreate($mainLanguageCode, $structFields, $fieldDefinitions, $languageCodes);
        $nameSchemaServiceMock->expects($this->once())->method('resolve')->with($this->equalTo($contentType->nameSchema), $this->equalTo($contentType), $this->equalTo($values), $this->equalTo($languageCodes))->will($this->returnValue(array()));
        $relationProcessorMock->expects($this->any())->method('processFieldRelations')->with($this->isType('array'), $this->equalTo(42), $this->isType('int'), $this->equalTo($contentType), $this->equalTo(array()));
        if (!$withObjectStates) {
            $objectStateHandlerMock->expects($this->once())->method('loadAllGroups')->will($this->returnValue(array()));
        }
        if ($execute) {
            $spiContentCreateStruct = new SPIContentCreateStruct(array('name' => array(), 'typeId' => 123, 'sectionId' => 1, 'ownerId' => 169, 'remoteId' => 'hash', 'fields' => $spiFields, 'modified' => time(), 'initialLanguageId' => 4242));
            $spiContentCreateStruct2 = clone $spiContentCreateStruct;
            ++$spiContentCreateStruct2->modified;
            $spiContent = new SPIContent(array('versionInfo' => new SPIContent\VersionInfo(array('contentInfo' => new SPIContent\ContentInfo(array('id' => 42)), 'versionNo' => 7))));
            $contentHandlerMock->expects($this->once())->method('create')->with($this->logicalOr($spiContentCreateStruct, $spiContentCreateStruct2))->will($this->returnValue($spiContent));
            $repositoryMock->expects($this->once())->method('commit');
            $domainMapperMock->expects($this->once())->method('buildContentDomainObject')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'), $this->equalTo(null));
            $mockedService->createContent($contentCreateStruct, array());
        }
        return $contentCreateStruct;
    }
ContentTest