eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::assertForTestUpdateContentNonRedundantFieldSet PHP Метод

assertForTestUpdateContentNonRedundantFieldSet() защищенный Метод

Asserts that calling updateContent() with given API field set causes calling Handler::updateContent() with given SPI field set.
protected assertForTestUpdateContentNonRedundantFieldSet ( string $initialLanguageCode, array $structFields, array $spiFields, array $existingFields, array $fieldDefinitions, boolean $execute = true ) : mixed
$initialLanguageCode string
$structFields array
$spiFields array
$existingFields array
$fieldDefinitions array
$execute boolean
Результат mixed
    protected function assertForTestUpdateContentNonRedundantFieldSet($initialLanguageCode, array $structFields, array $spiFields, array $existingFields, array $fieldDefinitions, $execute = true)
    {
        $repositoryMock = $this->getRepositoryMock();
        $mockedService = $this->getPartlyMockedContentService(array('loadContent', 'loadRelations'));
        /** @var \PHPUnit_Framework_MockObject_MockObject $contentHandlerMock */
        $contentHandlerMock = $this->getPersistenceMock()->contentHandler();
        /** @var \PHPUnit_Framework_MockObject_MockObject $languageHandlerMock */
        $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();
        $contentTypeServiceMock = $this->getContentTypeServiceMock();
        $fieldTypeServiceMock = $this->getFieldTypeServiceMock();
        $domainMapperMock = $this->getDomainMapperMock();
        $relationProcessorMock = $this->getRelationProcessorMock();
        $nameSchemaServiceMock = $this->getNameSchemaServiceMock();
        $fieldTypeMock = $this->getMock('eZ\\Publish\\SPI\\FieldType\\FieldType');
        $existingLanguageCodes = array_map(function (Field $field) {
            return $field->languageCode;
        }, $existingFields);
        $languageCodes = $this->determineLanguageCodesForUpdate($initialLanguageCode, $structFields, $existingLanguageCodes);
        $versionInfo = new VersionInfo(array('contentInfo' => new ContentInfo(array('id' => 42, 'contentTypeId' => 24, 'mainLanguageCode' => 'eng-GB')), 'versionNo' => 7, 'languageCodes' => $existingLanguageCodes, 'status' => VersionInfo::STATUS_DRAFT));
        $content = new Content(array('versionInfo' => $versionInfo, 'internalFields' => $existingFields));
        $contentType = new ContentType(array('fieldDefinitions' => $fieldDefinitions));
        $languageHandlerMock->expects($this->any())->method('loadByLanguageCode')->with($this->isType('string'))->will($this->returnCallback(function () {
            return new Language(array('id' => 4242));
        }));
        $mockedService->expects($this->once())->method('loadContent')->with($this->equalTo(42), $this->equalTo(null), $this->equalTo(7))->will($this->returnValue($content));
        $repositoryMock->expects($this->once())->method('beginTransaction');
        $repositoryMock->expects($this->once())->method('canUser')->with($this->equalTo('content'), $this->equalTo('edit'), $this->equalTo($content))->will($this->returnValue(true));
        $contentTypeServiceMock->expects($this->once())->method('loadContentType')->with($this->equalTo(24))->will($this->returnValue($contentType));
        $repositoryMock->expects($this->once())->method('getContentTypeService')->will($this->returnValue($contentTypeServiceMock));
        $repositoryMock->expects($this->once())->method('getCurrentUserReference')->will($this->returnValue(new UserReference(169)));
        $fieldTypeMock->expects($this->any())->method('acceptValue')->will($this->returnCallback(function ($valueString) {
            return new ValueStub($valueString);
        }));
        $emptyValue = self::EMPTY_FIELD_VALUE;
        $fieldTypeMock->expects($this->any())->method('toPersistenceValue')->will($this->returnCallback(function (ValueStub $value) {
            return (string) $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->determineValuesForUpdate($initialLanguageCode, $structFields, $content, $fieldDefinitions, $languageCodes);
        $nameSchemaServiceMock->expects($this->once())->method('resolveNameSchema')->with($this->equalTo($content), $this->equalTo($values), $this->equalTo($languageCodes))->will($this->returnValue(array()));
        $existingRelations = array('RELATIONS!!!');
        $mockedService->expects($this->once())->method('loadRelations')->with($content->versionInfo)->will($this->returnValue($existingRelations));
        $relationProcessorMock->expects($this->any())->method('processFieldRelations')->with($this->isType('array'), $this->equalTo(42), $this->isType('int'), $this->equalTo($contentType), $this->equalTo($existingRelations));
        $contentUpdateStruct = new ContentUpdateStruct(array('fields' => $structFields, 'initialLanguageCode' => $initialLanguageCode));
        if ($execute) {
            $spiContentUpdateStruct = new SPIContentUpdateStruct(array('creatorId' => 169, 'fields' => $spiFields, 'modificationDate' => time(), 'initialLanguageId' => 4242));
            // During code coverage runs, timestamp might differ 1-3 seconds
            $spiContentUpdateStructTs1 = clone $spiContentUpdateStruct;
            ++$spiContentUpdateStructTs1->modificationDate;
            $spiContentUpdateStructTs2 = clone $spiContentUpdateStructTs1;
            ++$spiContentUpdateStructTs2->modificationDate;
            $spiContentUpdateStructTs3 = clone $spiContentUpdateStructTs2;
            ++$spiContentUpdateStructTs3->modificationDate;
            $spiContent = new SPIContent(array('versionInfo' => new SPIContent\VersionInfo(array('contentInfo' => new SPIContent\ContentInfo(array('id' => 42)), 'versionNo' => 7))));
            $contentHandlerMock->expects($this->once())->method('updateContent')->with(42, 7, $this->logicalOr($spiContentUpdateStruct, $spiContentUpdateStructTs1, $spiContentUpdateStructTs2, $spiContentUpdateStructTs3))->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->isInstanceOf('eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'));
            $mockedService->updateContent($content->versionInfo, $contentUpdateStruct);
        }
        return array($content->versionInfo, $contentUpdateStruct);
    }
ContentTest