protected function assertForTestCreateContentRequiredField($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();
$fieldTypeMock = $this->getMock('eZ\\Publish\\SPI\\FieldType\\FieldType');
$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';
}));
$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('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));
return $contentCreateStruct;
}