コード例 #1
0
 public function testMapToFormData()
 {
     $fieldDef1 = new FieldDefinition(['identifier' => 'identifier1', 'fieldTypeIdentifier' => 'ezstring', 'names' => ['fre-FR' => 'foo'], 'descriptions' => ['fre-FR' => 'some description'], 'fieldGroup' => 'foo', 'position' => 0, 'isTranslatable' => true, 'isRequired' => true, 'isInfoCollector' => false, 'validatorConfiguration' => ['validator' => 'config'], 'fieldSettings' => ['field' => 'settings'], 'defaultValue' => $this->getMockForAbstractClass('\\eZ\\Publish\\Core\\FieldType\\Value'), 'isSearchable' => true]);
     $fieldDef2 = new FieldDefinition(['identifier' => 'identifier2', 'fieldTypeIdentifier' => 'eztext', 'names' => ['fre-FR' => 'foo2'], 'descriptions' => ['fre-FR' => 'some description 2'], 'fieldGroup' => 'foo2', 'position' => 15, 'isTranslatable' => false, 'isRequired' => false, 'isInfoCollector' => true, 'validatorConfiguration' => ['validator2' => 'config'], 'fieldSettings' => ['field2' => 'settings'], 'defaultValue' => null, 'isSearchable' => false]);
     $fieldDef3 = new FieldDefinition(['identifier' => 'identifiea3', 'fieldTypeIdentifier' => 'eztext', 'names' => ['fre-FR' => 'foo3'], 'descriptions' => ['fre-FR' => 'some description 3'], 'fieldGroup' => 'foo3', 'position' => 15, 'isTranslatable' => false, 'isRequired' => false, 'isInfoCollector' => true, 'validatorConfiguration' => ['validator3' => 'config'], 'fieldSettings' => ['field3' => 'settings'], 'defaultValue' => null, 'isSearchable' => false]);
     $fieldDefs = [$fieldDef1, $fieldDef2, $fieldDef3];
     $identifier = 'identifier';
     $remoteId = 'remoteId';
     $urlAliasSchema = 'urlAliasSchema';
     $nameSchema = 'nameSchema';
     $isContainer = true;
     $mainLanguageCode = 'fre-FR';
     $defaultSortField = Location::SORT_FIELD_NAME;
     $defaultSortOrder = Location::SORT_ORDER_ASC;
     $defaultAlwaysAvailable = true;
     $names = ['fre-FR' => 'Français', 'eng-GB' => 'English'];
     $descriptions = ['fre-FR' => 'Vive le sucre !!!', 'eng-GB' => 'Sugar rules!!!'];
     $contentTypeDraft = new ContentTypeDraft(['innerContentType' => new ContentType(['fieldDefinitions' => $fieldDefs, 'identifier' => $identifier, 'remoteId' => $remoteId, 'urlAliasSchema' => $urlAliasSchema, 'nameSchema' => $nameSchema, 'isContainer' => $isContainer, 'mainLanguageCode' => $mainLanguageCode, 'defaultSortField' => $defaultSortField, 'defaultSortOrder' => $defaultSortOrder, 'defaultAlwaysAvailable' => $defaultAlwaysAvailable, 'names' => $names, 'descriptions' => $descriptions])]);
     $expectedContentTypeData = new ContentTypeData(['contentTypeDraft' => $contentTypeDraft, 'identifier' => $contentTypeDraft->identifier, 'remoteId' => $contentTypeDraft->remoteId, 'urlAliasSchema' => $contentTypeDraft->urlAliasSchema, 'nameSchema' => $contentTypeDraft->nameSchema, 'isContainer' => $contentTypeDraft->isContainer, 'mainLanguageCode' => $contentTypeDraft->mainLanguageCode, 'defaultSortField' => $contentTypeDraft->defaultSortField, 'defaultSortOrder' => $contentTypeDraft->defaultSortOrder, 'defaultAlwaysAvailable' => $contentTypeDraft->defaultAlwaysAvailable, 'names' => $contentTypeDraft->getNames(), 'descriptions' => $contentTypeDraft->getDescriptions()]);
     $expectedFieldDefData1 = new FieldDefinitionData(['fieldDefinition' => $fieldDef1, 'contentTypeData' => $expectedContentTypeData, 'identifier' => $fieldDef1->identifier, 'names' => $fieldDef1->names, 'descriptions' => $fieldDef1->descriptions, 'fieldGroup' => $fieldDef1->fieldGroup, 'position' => $fieldDef1->position, 'isTranslatable' => $fieldDef1->isTranslatable, 'isRequired' => $fieldDef1->isRequired, 'isInfoCollector' => $fieldDef1->isInfoCollector, 'validatorConfiguration' => $fieldDef1->validatorConfiguration, 'fieldSettings' => $fieldDef1->fieldSettings, 'defaultValue' => $fieldDef1->defaultValue, 'isSearchable' => $fieldDef1->isSearchable]);
     $expectedContentTypeData->addFieldDefinitionData($expectedFieldDefData1);
     $expectedFieldDefData3 = new FieldDefinitionData(['fieldDefinition' => $fieldDef3, 'contentTypeData' => $expectedContentTypeData, 'identifier' => $fieldDef3->identifier, 'names' => $fieldDef3->names, 'descriptions' => $fieldDef3->descriptions, 'fieldGroup' => $fieldDef3->fieldGroup, 'position' => $fieldDef3->position, 'isTranslatable' => $fieldDef3->isTranslatable, 'isRequired' => $fieldDef3->isRequired, 'isInfoCollector' => $fieldDef3->isInfoCollector, 'validatorConfiguration' => $fieldDef3->validatorConfiguration, 'fieldSettings' => $fieldDef3->fieldSettings, 'defaultValue' => $fieldDef3->defaultValue, 'isSearchable' => $fieldDef3->isSearchable]);
     $expectedContentTypeData->addFieldDefinitionData($expectedFieldDefData3);
     $expectedFieldDefData2 = new FieldDefinitionData(['fieldDefinition' => $fieldDef2, 'contentTypeData' => $expectedContentTypeData, 'identifier' => $fieldDef2->identifier, 'names' => $fieldDef2->names, 'descriptions' => $fieldDef2->descriptions, 'fieldGroup' => $fieldDef2->fieldGroup, 'position' => $fieldDef2->position, 'isTranslatable' => $fieldDef2->isTranslatable, 'isRequired' => $fieldDef2->isRequired, 'isInfoCollector' => $fieldDef2->isInfoCollector, 'validatorConfiguration' => $fieldDef2->validatorConfiguration, 'fieldSettings' => $fieldDef2->fieldSettings, 'defaultValue' => $fieldDef2->defaultValue, 'isSearchable' => $fieldDef2->isSearchable]);
     $expectedContentTypeData->addFieldDefinitionData($expectedFieldDefData2);
     self::assertEquals($expectedContentTypeData, (new ContentTypeDraftMapper())->mapToFormData($contentTypeDraft));
 }
コード例 #2
0
 public function testFieldDefinitionData()
 {
     $fieldDef1 = new FieldDefinitionData();
     $fieldDef2 = new FieldDefinitionData();
     $fieldDef3 = new FieldDefinitionData();
     $fieldDef4 = new FieldDefinitionData();
     $initialFieldDefs = [$fieldDef1, $fieldDef2];
     $data = new ContentTypeData(['fieldDefinitionsData' => $initialFieldDefs]);
     self::assertSame($initialFieldDefs, $data->fieldDefinitionsData);
     $data->addFieldDefinitionData($fieldDef3);
     $data->addFieldDefinitionData($fieldDef4);
     self::assertSame([$fieldDef1, $fieldDef2, $fieldDef3, $fieldDef4], $data->fieldDefinitionsData);
 }
コード例 #3
0
 public function testProcessDefaultAction()
 {
     $contentTypeDraft = new ContentTypeDraft();
     $fieldDef1 = new FieldDefinition();
     $fieldDefData1 = new FieldDefinitionData(['fieldDefinition' => $fieldDef1]);
     $fieldDef2 = new FieldDefinition();
     $fieldDefData2 = new FieldDefinitionData(['fieldDefinition' => $fieldDef2]);
     $contentTypeData = new ContentTypeData(['contentTypeDraft' => $contentTypeDraft]);
     $contentTypeData->addFieldDefinitionData($fieldDefData1);
     $contentTypeData->addFieldDefinitionData($fieldDefData2);
     $this->contentTypeService->expects($this->at(0))->method('updateFieldDefinition')->with($contentTypeDraft, $fieldDef1, $fieldDefData1);
     $this->contentTypeService->expects($this->at(1))->method('updateFieldDefinition')->with($contentTypeDraft, $fieldDef2, $fieldDefData2);
     $this->contentTypeService->expects($this->at(2))->method('updateContentTypeDraft')->with($contentTypeDraft, $contentTypeData);
     $event = new FormActionEvent($this->getMock('\\Symfony\\Component\\Form\\FormInterface'), $contentTypeData, 'fooAction');
     $this->formProcessor->processDefaultAction($event);
 }
 public function testInvalid()
 {
     $identifier = 'foo';
     $constraint = new UniqueFieldDefinitionIdentifier();
     $constraintViolationBuilder = $this->getMock('\\Symfony\\Component\\Validator\\Violation\\ConstraintViolationBuilderInterface');
     $this->executionContext->expects($this->once())->method('buildViolation')->with($constraint->message)->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->expects($this->once())->method('atPath')->with('identifier')->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->expects($this->once())->method('setParameter')->with('%identifier%', $identifier)->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->expects($this->once())->method('addViolation');
     $contentTypeData = new ContentTypeData();
     $fieldDefData1 = new FieldDefinitionData(['identifier' => $identifier, 'contentTypeData' => $contentTypeData]);
     $contentTypeData->addFieldDefinitionData($fieldDefData1);
     $fieldDefData2 = new FieldDefinitionData(['identifier' => 'bar', 'contentTypeData' => $contentTypeData]);
     $contentTypeData->addFieldDefinitionData($fieldDefData2);
     $fieldDefData3 = new FieldDefinitionData(['identifier' => $identifier, 'contentTypeData' => $contentTypeData]);
     $contentTypeData->addFieldDefinitionData($fieldDefData3);
     $this->validator->validate($fieldDefData1, $constraint);
 }
コード例 #5
0
 /**
  * Maps a ValueObject from eZ content repository to a data usable as underlying form data (e.g. create/update struct).
  *
  * @param ValueObject|\eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
  * @param array $params
  *
  * @return ContentTypeData
  */
 public function mapToFormData(ValueObject $contentTypeDraft, array $params = [])
 {
     $contentTypeData = new ContentTypeData(['contentTypeDraft' => $contentTypeDraft]);
     if (!$contentTypeData->isNew()) {
         $contentTypeData->identifier = $contentTypeDraft->identifier;
     }
     $contentTypeData->remoteId = $contentTypeDraft->remoteId;
     $contentTypeData->urlAliasSchema = $contentTypeDraft->urlAliasSchema;
     $contentTypeData->nameSchema = $contentTypeDraft->nameSchema;
     $contentTypeData->isContainer = $contentTypeDraft->isContainer;
     $contentTypeData->mainLanguageCode = $contentTypeDraft->mainLanguageCode;
     $contentTypeData->defaultSortField = $contentTypeDraft->defaultSortField;
     $contentTypeData->defaultSortOrder = $contentTypeDraft->defaultSortOrder;
     $contentTypeData->defaultAlwaysAvailable = $contentTypeDraft->defaultAlwaysAvailable;
     $contentTypeData->names = $contentTypeDraft->getNames();
     $contentTypeData->descriptions = $contentTypeDraft->getDescriptions();
     foreach ($contentTypeDraft->fieldDefinitions as $fieldDef) {
         $contentTypeData->addFieldDefinitionData(new FieldDefinitionData(['fieldDefinition' => $fieldDef, 'contentTypeData' => $contentTypeData, 'identifier' => $fieldDef->identifier, 'names' => $fieldDef->getNames(), 'descriptions' => $fieldDef->getDescriptions(), 'fieldGroup' => $fieldDef->fieldGroup, 'position' => $fieldDef->position, 'isTranslatable' => $fieldDef->isTranslatable, 'isRequired' => $fieldDef->isRequired, 'isInfoCollector' => $fieldDef->isInfoCollector, 'validatorConfiguration' => $fieldDef->getValidatorConfiguration(), 'fieldSettings' => $fieldDef->getFieldSettings(), 'defaultValue' => $fieldDef->defaultValue, 'isSearchable' => $fieldDef->isSearchable]));
     }
     return $contentTypeData;
 }