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

assertForTestCreateContentThrowsContentFieldValidationException() protected method

Asserts behaviour necessary for testing ContentFieldValidationException because of field not being valid.
protected assertForTestCreateContentThrowsContentFieldValidationException ( string $mainLanguageCode, array $structFields, array $fieldDefinitions ) : mixed
$mainLanguageCode string
$structFields array
$fieldDefinitions array
return mixed
    protected function assertForTestCreateContentThrowsContentFieldValidationException($mainLanguageCode, array $structFields, array $fieldDefinitions)
    {
        $repositoryMock = $this->getRepositoryMock();
        /** @var \PHPUnit_Framework_MockObject_MockObject $languageHandlerMock */
        $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();
        $contentTypeServiceMock = $this->getContentTypeServiceMock();
        $fieldTypeServiceMock = $this->getFieldTypeServiceMock();
        $domainMapperMock = $this->getDomainMapperMock();
        $relationProcessorMock = $this->getRelationProcessorMock();
        $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));
        }));
        $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(array()))->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';
        }));
        $this->getFieldTypeRegistryMock()->expects($this->any())->method('getFieldType')->will($this->returnValue($fieldTypeMock));
        $relationProcessorMock->expects($this->any())->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());
        $fieldValues = $this->determineValuesForCreate($mainLanguageCode, $structFields, $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;
            }
        }
        return array($contentCreateStruct, $allFieldErrors);
    }
ContentTest