Skip to content

Commit

Permalink
IBX-4031: Applied review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Aug 7, 2023
1 parent fa81f27 commit 7635e14
Showing 1 changed file with 62 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\Tests\Integration\Core\Repository\ContentService;

use Datetime;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct;
use eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct;
use Ibexa\Tests\Integration\Core\RepositoryTestCase;

Expand All @@ -20,7 +21,11 @@ final class CopyNonTranslatableFieldsFromPublishedVersionTest extends Repository
private const GER_DE = 'ger-DE';
private const ENG_US = 'eng-US';
private const CONTENT_TYPE_IDENTIFIER = 'nontranslatable';
private const TEXT_LINE_FIELD_TYPE_IDENTIFIER = 'ezstring';

/**
* @throws \eZ\Publish\API\Repository\Exceptions\Exception
*/
public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void
{
$this->createNonTranslatableContentType();
Expand Down Expand Up @@ -99,58 +104,70 @@ private function createNonTranslatableContentType(): void
$typeCreate->creatorId = $permissionResolver->getCurrentUserReference()->getUserId();
$typeCreate->creationDate = new DateTime();

$titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('title', 'ezstring');
$titleFieldCreate->names = [
'eng-GB' => 'Title',
];
$titleFieldCreate->descriptions = [
'eng-GB' => 'Title',
];
$titleFieldCreate->fieldGroup = 'content';
$titleFieldCreate->position = 1;
$titleFieldCreate->isTranslatable = true;
$titleFieldCreate->isRequired = true;
$titleFieldCreate->isInfoCollector = false;
$titleFieldCreate->validatorConfiguration = [
'StringLengthValidator' => [
'minStringLength' => 0,
'maxStringLength' => 0,
],
];
$titleFieldCreate->fieldSettings = [];
$titleFieldCreate->isSearchable = true;
$titleFieldCreate->defaultValue = 'default title';
$fieldDefinitionPosition = 1;
$typeCreate->addFieldDefinition(
$this->buildFieldDefinitionCreateStructForNonTranslatableContentType(
$fieldDefinitionPosition,
'title',
['eng-GB' => 'Title'],
true,
true,
'default title'
)
);

$typeCreate->addFieldDefinition($titleFieldCreate);
$typeCreate->addFieldDefinition(
$this->buildFieldDefinitionCreateStructForNonTranslatableContentType(
++$fieldDefinitionPosition,
'body',
['eng-GB' => 'Body'],
false,
false
)
);

$bodyFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('body', 'ezstring');
$bodyFieldCreate->names = [
'eng-GB' => 'Body',
];
$bodyFieldCreate->descriptions = [
'eng-GB' => 'Body',
];
$bodyFieldCreate->fieldGroup = 'content';
$bodyFieldCreate->position = 2;
$bodyFieldCreate->isTranslatable = false;
$bodyFieldCreate->isRequired = false;
$bodyFieldCreate->isInfoCollector = false;
$bodyFieldCreate->validatorConfiguration = [
$contentTypeDraft = $contentTypeService->createContentType(
$typeCreate,
[$contentTypeService->loadContentTypeGroupByIdentifier('Media')],
);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);
}

/**
* @param array<string, string> $names
*/
private function buildFieldDefinitionCreateStructForNonTranslatableContentType(
int $position,
string $fieldIdentifier,
array $names,
bool $isTranslatable,
bool $isRequired,
?string $defaultValue = null
): FieldDefinitionCreateStruct {
$contentTypeService = self::getContentTypeService();

$fieldDefinitionCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct(
$fieldIdentifier,
self::TEXT_LINE_FIELD_TYPE_IDENTIFIER
);

$fieldDefinitionCreateStruct->names = $names;
$fieldDefinitionCreateStruct->descriptions = $names;
$fieldDefinitionCreateStruct->fieldGroup = 'content';
$fieldDefinitionCreateStruct->position = $position;
$fieldDefinitionCreateStruct->isTranslatable = $isTranslatable;
$fieldDefinitionCreateStruct->isRequired = $isRequired;
$fieldDefinitionCreateStruct->isInfoCollector = false;
$fieldDefinitionCreateStruct->validatorConfiguration = [
'StringLengthValidator' => [
'minStringLength' => 0,
'maxStringLength' => 0,
],
];
$bodyFieldCreate->fieldSettings = [];
$bodyFieldCreate->isSearchable = true;
$bodyFieldCreate->defaultValue = null;

$typeCreate->addFieldDefinition($bodyFieldCreate);
$fieldDefinitionCreateStruct->fieldSettings = [];
$fieldDefinitionCreateStruct->isSearchable = true;
$fieldDefinitionCreateStruct->defaultValue = $defaultValue;

$contentTypeDraft = $contentTypeService->createContentType(
$typeCreate,
[$contentTypeService->loadContentTypeGroupByIdentifier('Media')],
);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);
return $fieldDefinitionCreateStruct;
}
}

0 comments on commit 7635e14

Please sign in to comment.