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

assertForTestUpdateContentThrowsContentFieldValidationException() public method

public assertForTestUpdateContentThrowsContentFieldValidationException ( $initialLanguageCode, $structFields, $existingFields, $fieldDefinitions )
    public function assertForTestUpdateContentThrowsContentFieldValidationException($initialLanguageCode, $structFields, $existingFields, $fieldDefinitions)
    {
        $repositoryMock = $this->getRepositoryMock();
        $mockedService = $this->getPartlyMockedContentService(array('loadContent'));
        /** @var \PHPUnit_Framework_MockObject_MockObject $languageHandlerMock */
        $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();
        $contentTypeServiceMock = $this->getContentTypeServiceMock();
        $fieldTypeServiceMock = $this->getFieldTypeServiceMock();
        $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('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));
        $fieldValues = $this->determineValuesForUpdate($initialLanguageCode, $structFields, $content, $fieldDefinitions, $languageCodes);
        $allFieldErrors = array();
        $validateCount = 0;
        $emptyValue = self::EMPTY_FIELD_VALUE;
        foreach ($contentType->getFieldDefinitions() as $fieldDefinition) {
            foreach ($fieldValues[$fieldDefinition->identifier] as $languageCode => $value) {
                $fieldTypeMock->expects($this->at($validateCount++))->method('acceptValue')->will($this->returnCallback(function ($valueString) {
                    return new ValueStub($valueString);
                }));
                $fieldTypeMock->expects($this->at($validateCount++))->method('isEmptyValue')->will($this->returnCallback(function (ValueStub $value) use($emptyValue) {
                    return $emptyValue === (string) $value;
                }));
                if (self::EMPTY_FIELD_VALUE === (string) $value) {
                    continue;
                }
                $fieldTypeMock->expects($this->at($validateCount++))->method('validate')->with($this->equalTo($fieldDefinition), $this->equalTo($value))->will($this->returnArgument(1));
                $allFieldErrors[$fieldDefinition->id][$languageCode] = $value;
            }
        }
        $this->getFieldTypeRegistryMock()->expects($this->any())->method('getFieldType')->will($this->returnValue($fieldTypeMock));
        $contentUpdateStruct = new ContentUpdateStruct(array('fields' => $structFields, 'initialLanguageCode' => $initialLanguageCode));
        return array($content->versionInfo, $contentUpdateStruct, $allFieldErrors);
    }
ContentTest